From d9f1b68cf57220c0ec0cefaee3558e6b37ab0d72 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 7 Jun 2008 09:12:42 +0000 Subject: [PATCH] Presets support. How per codec defaults and ranges will be supported is still being discussed. Originally committed as revision 13685 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index 2885ee4563..98973acaa7 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3636,6 +3636,41 @@ static int opt_bsf(const char *opt, const char *arg) return 0; } +static int opt_preset(const char *opt, const char *arg) +{ + FILE *f; + char tmp[100], tmp2[100]; + char *home= getenv("HOME"); + + snprintf(tmp, sizeof(tmp), "%s/.ffmpeg/%s.ffpreset", home, arg); + f= fopen(tmp, "r"); + if(!f){ + char *codec_name= *opt == 'v' ? video_codec_name : + *opt == 'a' ? audio_codec_name : + subtitle_codec_name; + snprintf(tmp, sizeof(tmp), "%s/.ffmpeg/%s-%s.ffpreset", home, codec_name, arg); + f= fopen(tmp, "r"); + } + + if(!f){ + fprintf(stderr, "Preset file not found\n"); + av_exit(1); + } + + while(!feof(f)){ + int e= fscanf(f, "%99[^=]=%99[^\n]\n", tmp, tmp2); + if(e!=2){ + fprintf(stderr, "Preset file invalid\n"); + av_exit(1); + } + opt_default(tmp, tmp2); + } + + fclose(f); + + return 0; +} + static const OptionDef options[] = { /* main options */ { "L", OPT_EXIT, {(void*)show_license}, "show license" }, @@ -3758,6 +3793,10 @@ static const OptionDef options[] = { { "vbsf", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, { "sbsf", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, + { "apre", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "", "preset" }, + { "vpre", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "", "preset" }, + { "spre", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "", "preset" }, + { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, { NULL, }, };