2014-11-30 10:59 GMT+01:00 Christophe Gisquet <christophe.gisq...@gmail.com>:
> So I'm going to add a "AVDictionary *bsf_args" to OutputStream.
>
> That dictionary lookup seems negligible to the amount of work done overall.

Done in the attached patch. I've edited the documentation also to
reflect this change that only affects ffmpeg.

-- 
Christophe
From cccecb1eef2e387115d83ec5bad58e006f4007ea Mon Sep 17 00:00:00 2001
From: Christophe Gisquet <christophe.gisq...@gmail.com>
Date: Sat, 29 Nov 2014 19:15:02 +0100
Subject: [PATCH 1/4] 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.
---
 doc/bitstream_filters.texi | 8 ++++++++
 ffmpeg.c                   | 7 ++++++-
 ffmpeg.h                   | 1 +
 ffmpeg_opt.c               | 4 ++++
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 58ebddd..8124238 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -13,6 +13,14 @@ bitstream filter using the option @code{--disable-bsf=BSF}.
 The option @code{-bsfs} of the ff* tools will display the list of
 all the supported bitstream filters included in your build.
 
+The ff* tools have a -bsf option applied per stream, taking a
+comma-separated list of filters, whose parameters follow the filter
+name after a '='.
+
+@example
+ffmpeg -i INPUT -c:v copy -bsf:v filter1[=opt1=str1/opt2=str2][,filter2] OUTPUT
+@end example
+
 Below is a description of the currently available bitstream filters.
 
 @section aac_adtstoasc
diff --git a/ffmpeg.c b/ffmpeg.c
index 57abd30..b44401f 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -623,7 +623,11 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
 
     while (bsfc) {
         AVPacket new_pkt = *pkt;
-        int a = av_bitstream_filter_filter(bsfc, avctx, NULL,
+        AVDictionaryEntry *bsf_arg = av_dict_get(ost->bsf_args,
+                                                 bsfc->filter->name,
+                                                 NULL, 0);
+        int a = av_bitstream_filter_filter(bsfc, avctx,
+                                           bsf_arg ? bsf_arg->value : NULL,
                                            &new_pkt.data, &new_pkt.size,
                                            pkt->data, pkt->size,
                                            pkt->flags & AV_PKT_FLAG_KEY);
@@ -3834,6 +3838,7 @@ static int transcode(void)
                 av_dict_free(&ost->encoder_opts);
                 av_dict_free(&ost->swr_opts);
                 av_dict_free(&ost->resample_opts);
+                av_dict_free(&ost->bsf_args);
             }
         }
     }
diff --git a/ffmpeg.h b/ffmpeg.h
index 8107fe7..117a35c 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -422,6 +422,7 @@ typedef struct OutputStream {
     AVDictionary *encoder_opts;
     AVDictionary *swr_opts;
     AVDictionary *resample_opts;
+    AVDictionary *bsf_args;
     char *apad;
     OSTFinished finished;        /* no more packets should be written for this stream */
     int unavailable;                     /* true if the steram is unavailable (possibly temporarily) */
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 03e049b..1f281f6 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1138,8 +1138,11 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
 
     MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
     while (bsf) {
+        char *arg = NULL;
         if (next = strchr(bsf, ','))
             *next++ = 0;
+        if (arg = strchr(bsf, '='))
+            *arg++ = 0;
         if (!(bsfc = av_bitstream_filter_init(bsf))) {
             av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
             exit_program(1);
@@ -1148,6 +1151,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
             bsfc_prev->next = bsfc;
         else
             ost->bitstream_filters = bsfc;
+        av_dict_set(&ost->bsf_args, bsfc->filter->name, arg, 0);
 
         bsfc_prev = bsfc;
         bsf       = next;
-- 
1.9.2.msysgit.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to