[FFmpeg-devel] [PATCH 3/3] ffmpeg: Load the video/audio preset named default if none is specified

Alexander Strange astrange
Mon Nov 8 05:44:07 CET 2010


---
 ffmpeg.c |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 91ab431..3a34dc4 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -236,6 +236,9 @@ static float dts_delta_threshold = 10;
 
 static unsigned int sws_flags = SWS_BICUBIC;
 
+static int video_preset_loaded = 0;
+static int audio_preset_loaded = 0;
+
 static int64_t timer_start;
 
 static uint8_t *audio_buf;
@@ -3280,11 +3283,25 @@ static int opt_preset(const char *opt, const char *arg)
 {
     FILE *f=NULL;
     char filename[1000], tmp[1000], tmp2[1000], line[1000];
-    char *codec_name = *opt == 'v' ? video_codec_name :
-                       *opt == 'a' ? audio_codec_name :
-                                     subtitle_codec_name;
+    char *codec_name;
+    int is_default = arg == NULL;
+
+    if (*opt == 'v') {
+        codec_name = video_codec_name;
+        video_preset_loaded = 1;
+    } else if (*opt == 'a') {
+        codec_name = audio_codec_name;
+        audio_preset_loaded = 1;
+    } else {
+        codec_name = subtitle_codec_name;
+    }
+
+    if (is_default)
+        arg = "default";
 
     if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
+        if (is_default)
+            return 0;
         fprintf(stderr, "File for preset '%s' not found\n", arg);
         ffmpeg_exit(1);
     }
@@ -3344,6 +3361,10 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
         }
     }
 
+    if (!video_preset_loaded)
+        opt_preset("vpre", NULL);
+    video_preset_loaded = 0;
+
     avcodec_get_context_defaults3(st->codec, codec);
     ost->bitstream_filters = video_bitstream_filters;
     video_bitstream_filters= NULL;
@@ -3491,6 +3512,10 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
         }
     }
 
+    if (!audio_preset_loaded)
+        opt_preset("apre", NULL);
+    audio_preset_loaded = 0;
+
     avcodec_get_context_defaults3(st->codec, codec);
 
     ost->bitstream_filters = audio_bitstream_filters;
@@ -4188,8 +4213,8 @@ 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}, "set the audio options to the indicated preset", "preset" },
-    { "vpre", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" },
+    { "apre", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)&opt_preset}, "set the audio options to the indicated preset", "preset" },
+    { "vpre", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)&opt_preset}, "set the video options to the indicated preset", "preset" },
     { "spre", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
     { "fpre", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" },
 
-- 
1.7.3.1




More information about the ffmpeg-devel mailing list