Browse code

ffmpeg: take bsf arguments from the command line

The format is now:
-bsf:X filter1[=opt1=str1/opt2=str2],filter2
ie the parameters are appended after the filter name using '='. As ','
has been reserved already for the list of filters, '/' is just an
example of token separation for now, but that could become part of the
API to avoid each bsf using its own tokenization.

The proper solution would be using AVOption, but this is overkill for now.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Christophe Gisquet authored on 2014/11/30 03:15:02
Showing 4 changed files
... ...
@@ -13,6 +13,14 @@ bitstream filter using the option @code{--disable-bsf=BSF}.
13 13
 The option @code{-bsfs} of the ff* tools will display the list of
14 14
 all the supported bitstream filters included in your build.
15 15
 
16
+The ff* tools have a -bsf option applied per stream, taking a
17
+comma-separated list of filters, whose parameters follow the filter
18
+name after a '='.
19
+
20
+@example
21
+ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1/opt2=str2][,filter2] OUTPUT
22
+@end example
23
+
16 24
 Below is a description of the currently available bitstream filters.
17 25
 
18 26
 @section aac_adtstoasc
... ...
@@ -623,7 +623,11 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
623 623
 
624 624
     while (bsfc) {
625 625
         AVPacket new_pkt = *pkt;
626
-        int a = av_bitstream_filter_filter(bsfc, avctx, NULL,
626
+        AVDictionaryEntry *bsf_arg = av_dict_get(ost->bsf_args,
627
+                                                 bsfc->filter->name,
628
+                                                 NULL, 0);
629
+        int a = av_bitstream_filter_filter(bsfc, avctx,
630
+                                           bsf_arg ? bsf_arg->value : NULL,
627 631
                                            &new_pkt.data, &new_pkt.size,
628 632
                                            pkt->data, pkt->size,
629 633
                                            pkt->flags & AV_PKT_FLAG_KEY);
... ...
@@ -3834,6 +3838,7 @@ static int transcode(void)
3834 3834
                 av_dict_free(&ost->encoder_opts);
3835 3835
                 av_dict_free(&ost->swr_opts);
3836 3836
                 av_dict_free(&ost->resample_opts);
3837
+                av_dict_free(&ost->bsf_args);
3837 3838
             }
3838 3839
         }
3839 3840
     }
... ...
@@ -422,6 +422,7 @@ typedef struct OutputStream {
422 422
     AVDictionary *encoder_opts;
423 423
     AVDictionary *swr_opts;
424 424
     AVDictionary *resample_opts;
425
+    AVDictionary *bsf_args;
425 426
     char *apad;
426 427
     OSTFinished finished;        /* no more packets should be written for this stream */
427 428
     int unavailable;                     /* true if the steram is unavailable (possibly temporarily) */
... ...
@@ -1138,8 +1138,11 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
1138 1138
 
1139 1139
     MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
1140 1140
     while (bsf) {
1141
+        char *arg = NULL;
1141 1142
         if (next = strchr(bsf, ','))
1142 1143
             *next++ = 0;
1144
+        if (arg = strchr(bsf, '='))
1145
+            *arg++ = 0;
1143 1146
         if (!(bsfc = av_bitstream_filter_init(bsf))) {
1144 1147
             av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
1145 1148
             exit_program(1);
... ...
@@ -1148,6 +1151,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
1148 1148
             bsfc_prev->next = bsfc;
1149 1149
         else
1150 1150
             ost->bitstream_filters = bsfc;
1151
+        av_dict_set(&ost->bsf_args, bsfc->filter->name, arg, 0);
1151 1152
 
1152 1153
         bsfc_prev = bsfc;
1153 1154
         bsf       = next;