From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Cc: Marton Balint <cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/4] fftools/cmdutils: factorize loading a file from the datadir Date: Sat, 17 May 2025 01:08:59 +0200 Message-ID: <20250516231041.4640-2-cus@passwd.hu> (raw) In-Reply-To: <20250516231041.4640-1-cus@passwd.hu> This changes the order of preset file loading slighly to be in line with the documentation, because before the patch codec-prefixed presets were probed before trying the next directory. Signed-off-by: Marton Balint <cus@passwd.hu> --- fftools/cmdutils.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index e516ee6ebd..1de670c2e4 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -920,9 +920,7 @@ int read_yesno(void) return yesno; } -FILE *get_preset_file(AVBPrint *filename, - const char *preset_name, int is_path, - const char *codec_name) +static FILE *get_datadir_file_fmt(AVBPrint *filename, const char *fmt, ...) { FILE *f = NULL; int i; @@ -935,11 +933,6 @@ FILE *get_preset_file(AVBPrint *filename, env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */ FFMPEG_DATADIR, }; - if (is_path) { - av_bprintf(filename, "%s", preset_name); - if (av_bprint_is_complete(filename)) - f = fopen_utf8(filename->str, "r"); - } else { #if HAVE_GETMODULEHANDLE && defined(_WIN32) wchar_t *datadir_w = get_module_filename(NULL); base[2] = NULL; @@ -969,21 +962,21 @@ FILE *get_preset_file(AVBPrint *filename, } } #endif + + { + va_list ap; + for (i = 0; i < 3 && !f; i++) { if (!base[i]) continue; av_bprint_clear(filename); - av_bprintf(filename, "%s%s/%s.ffpreset", base[i], - i != 1 ? "" : "/.ffmpeg", preset_name); + av_bprintf(filename, "%s%s/", base[i], i != 1 ? "" : "/.ffmpeg"); + va_start(ap, fmt); + av_vbprintf(filename, fmt, ap); + va_end(ap); + if (!av_bprint_is_complete(filename)) + break; f = fopen_utf8(filename->str, "r"); - if (!f && codec_name) { - av_bprint_clear(filename); - av_bprintf(filename, - "%s%s/%s-%s.ffpreset", - base[i], i != 1 ? "" : "/.ffmpeg", codec_name, - preset_name); - f = fopen_utf8(filename->str, "r"); - } } } @@ -995,6 +988,23 @@ FILE *get_preset_file(AVBPrint *filename, return f; } +FILE *get_preset_file(AVBPrint *filename, + const char *preset_name, int is_path, + const char *codec_name) +{ + FILE *f = NULL; + if (is_path) { + av_bprintf(filename, "%s", preset_name); + if (av_bprint_is_complete(filename)) + f = fopen_utf8(filename->str, "r"); + } else { + f = get_datadir_file_fmt(filename, "%s.ffpreset", preset_name); + if (!f && codec_name) + f = get_datadir_file_fmt(filename, "%s%s/%s-%s.ffpreset", codec_name, preset_name); + } + return f; +} + int cmdutils_isalnum(char c) { return (c >= '0' && c <= '9') || -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-05-16 23:11 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-05-16 23:08 [FFmpeg-devel] [PATCH 1/4] fftools/cmdutils: allow arbitrary length paths for preset files Marton Balint 2025-05-16 23:08 ` Marton Balint [this message] 2025-05-16 23:09 ` [FFmpeg-devel] [PATCH 3/4] fftools/graph/graphprint: load CSS and HTML resources from ffmpeg data directories Marton Balint 2025-05-17 2:21 ` softworkz . 2025-05-17 9:13 ` Marton Balint 2025-05-17 17:22 ` softworkz . 2025-05-17 20:33 ` softworkz . 2025-05-16 23:09 ` [FFmpeg-devel] [PATCH 4/4] Revert "fftools/resources: Add resource manager files with build-time compression" Marton Balint 2025-06-14 14:43 ` Kacper Michajlow 2025-06-14 16:11 ` Marton Balint
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250516231041.4640-2-cus@passwd.hu \ --to=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git