Browse code

avconv: move audio_sample_fmt to options context.

Also document it and replace undocumented and inconsistent
'-sample_fmt list' syntax with -sample_fmts.

Anton Khirnov authored on 2011/08/31 15:51:15
Showing 6 changed files
... ...
@@ -105,7 +105,6 @@ static int frame_width  = 0;
105 105
 static int frame_height = 0;
106 106
 static float frame_aspect_ratio = 0;
107 107
 static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
108
-static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE;
109 108
 static AVRational frame_rate;
110 109
 static float video_qscale = 0;
111 110
 static uint16_t *intra_matrix = NULL;
... ...
@@ -320,6 +319,8 @@ typedef struct OptionsContext {
320 320
     int        nb_bitstream_filters;
321 321
     SpecifierOpt *codec_tags;
322 322
     int        nb_codec_tags;
323
+    SpecifierOpt *sample_fmts;
324
+    int        nb_sample_fmts;
323 325
 } OptionsContext;
324 326
 
325 327
 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
... ...
@@ -2572,24 +2573,6 @@ static int opt_top_field_first(const char *opt, const char *arg)
2572 2572
     return 0;
2573 2573
 }
2574 2574
 
2575
-static int opt_audio_sample_fmt(const char *opt, const char *arg)
2576
-{
2577
-    if (strcmp(arg, "list")) {
2578
-        audio_sample_fmt = av_get_sample_fmt(arg);
2579
-        if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) {
2580
-            av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg);
2581
-            return AVERROR(EINVAL);
2582
-        }
2583
-    } else {
2584
-        int i;
2585
-        char fmt_str[128];
2586
-        for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
2587
-            printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
2588
-        exit_program(0);
2589
-    }
2590
-    return 0;
2591
-}
2592
-
2593 2575
 static int opt_audio_rate(const char *opt, const char *arg)
2594 2576
 {
2595 2577
     audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
... ...
@@ -2994,7 +2977,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
2994 2994
     frame_height = 0;
2995 2995
     frame_width  = 0;
2996 2996
     audio_sample_rate = 0;
2997
-    audio_sample_fmt  = AV_SAMPLE_FMT_NONE;
2998 2997
 
2999 2998
     for (i = 0; i < orig_nb_streams; i++)
3000 2999
         av_dict_free(&opts[i]);
... ...
@@ -3204,14 +3186,21 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
3204 3204
         audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
3205 3205
     }
3206 3206
     if (!st->stream_copy) {
3207
+        char *sample_fmt = NULL;
3208
+
3207 3209
         if (audio_qscale > QSCALE_NONE) {
3208 3210
             audio_enc->flags |= CODEC_FLAG_QSCALE;
3209 3211
             audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale;
3210 3212
         }
3211 3213
         MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
3212 3214
 
3213
-        if (audio_sample_fmt != AV_SAMPLE_FMT_NONE)
3214
-            audio_enc->sample_fmt = audio_sample_fmt;
3215
+        MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
3216
+        if (sample_fmt &&
3217
+            (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
3218
+            av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", sample_fmt);
3219
+            exit_program(1);
3220
+        }
3221
+
3215 3222
         if (audio_sample_rate)
3216 3223
             audio_enc->sample_rate = audio_sample_rate;
3217 3224
     }
... ...
@@ -3642,7 +3631,6 @@ static void opt_output_file(void *optctx, const char *filename)
3642 3642
     frame_width   = 0;
3643 3643
     frame_height  = 0;
3644 3644
     audio_sample_rate = 0;
3645
-    audio_sample_fmt  = AV_SAMPLE_FMT_NONE;
3646 3645
 
3647 3646
     av_freep(&streamid_map);
3648 3647
     nb_streamid_map = 0;
... ...
@@ -4079,7 +4067,7 @@ static const OptionDef options[] = {
4079 4079
     { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
4080 4080
     { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" },
4081 4081
     { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
4082
-    { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_sample_fmt}, "set sample format, 'list' as argument shows all the sample formats supported", "format" },
4082
+    { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" },
4083 4083
 
4084 4084
     /* subtitle options */
4085 4085
     { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" },
... ...
@@ -717,6 +717,15 @@ void show_pix_fmts(void)
717 717
     }
718 718
 }
719 719
 
720
+int show_sample_fmts(const char *opt, const char *arg)
721
+{
722
+    int i;
723
+    char fmt_str[128];
724
+    for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
725
+        printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
726
+    return 0;
727
+}
728
+
720 729
 int read_yesno(void)
721 730
 {
722 731
     int c = getchar();
... ...
@@ -278,6 +278,12 @@ void show_protocols(void);
278 278
 void show_pix_fmts(void);
279 279
 
280 280
 /**
281
+ * Print a listing containing all the sample formats supported by the
282
+ * program.
283
+ */
284
+int show_sample_fmts(const char *opt, const char *arg);
285
+
286
+/**
281 287
  * Return a positive value if a line read from standard input
282 288
  * starts with [yY], otherwise return 0.
283 289
  */
... ...
@@ -10,4 +10,5 @@
10 10
     { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" },
11 11
     { "filters",   OPT_EXIT, {(void*)show_filters  }, "show available filters" },
12 12
     { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" },
13
+    { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show available audio sample formats" },
13 14
     { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" },
... ...
@@ -590,6 +590,9 @@ and is mapped to the corresponding demuxer options.
590 590
 Disable audio recording.
591 591
 @item -acodec @var{codec}
592 592
 Set the audio codec. This is an alias for @code{-codec:a}.
593
+@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt}
594
+Set the audio sample format. Use @code{-help sample_fmts} to get a list
595
+of supported sample formats.
593 596
 @end table
594 597
 
595 598
 @section Advanced Audio options:
... ...
@@ -68,6 +68,9 @@ Show available libavfilter filters.
68 68
 @item -pix_fmts
69 69
 Show available pixel formats.
70 70
 
71
+@item -sample_fmts
72
+Show available sample formats.
73
+
71 74
 @item -loglevel @var{loglevel}
72 75
 Set the logging level used by the library.
73 76
 @var{loglevel} is a number or a string containing one of the following values: