summaryrefslogtreecommitdiff
path: root/ffmpeg_opt.c
diff options
context:
space:
mode:
authorClément Bœsch <clement@stupeflix.com>2016-09-21 15:39:16 +0200
committerJames Almer <jamrial@gmail.com>2016-09-24 14:25:53 -0300
commit5ef19590802f000299e418143fc2301e3f43affe (patch)
tree327fdd757e3aadc3ddf1a04ceb55364d47d31dac /ffmpeg_opt.c
parent159aa1275e5d9c94edc313a51d65220e887d790b (diff)
ffmpeg: switch to the new BSF API
This commit is initially largely based on commit 4426540 from Anton Khirnov <anton@khirnov.net> and two following fixes (80fb19b and fe7b21c) which were previously skipped respectively in 98e3153, c9ee36e, and 7fe7cdc. mpeg4-bsf-unpack-bframes FATE reference is updated because the bsf filter now actually fixes the extradata (mpeg4_unpack_bframes_init() changing one byte is now honored on the output extradata). The FATE references for remove_extra change because the packet flags were wrong and the keyframes weren't marked, causing the bsf relying on these proprieties to not actually work as intended. The following was fixed by James Almer: The filter option arguments are now also parsed correctly. A hack to propagate extradata changed by bitstream filters after the first av_bsf_receive_packet() call is added to maintain the current behavior. This was previously done by av_bitstream_filter_filter() and is needed for the aac_adtstoasc bsf. The exit_on_error was not being checked anymore, and led to an exit error in the last frame of h264_mp4toannexb test. Restoring this behaviour prevents erroring out. The test is still changed as a result due to the badly filtered frame now not being written after the failure. Signed-off-by: Clément Bœsch <u@pkh.me> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'ffmpeg_opt.c')
-rw-r--r--ffmpeg_opt.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 8169f20012..0dfdbd6118 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1229,8 +1229,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
OutputStream *ost;
AVStream *st = avformat_new_stream(oc, NULL);
int idx = oc->nb_streams - 1, ret = 0;
- char *bsf = NULL, *next, *codec_tag = NULL;
- AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
+ const char *bsfs = NULL;
+ char *next, *codec_tag = NULL;
double qscale = -1;
int i;
@@ -1319,29 +1319,62 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->copy_prior_start = -1;
MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
- 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);
+ MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
+ while (bsfs && *bsfs) {
+ const AVBitStreamFilter *filter;
+ char *bsf, *bsf_options_str, *bsf_name;
+
+ bsf = av_get_token(&bsfs, ",");
+ if (!bsf)
+ exit_program(1);
+ bsf_name = av_strtok(bsf, "=", &bsf_options_str);
+ if (!bsf_name)
+ exit_program(1);
+
+ filter = av_bsf_get_by_name(bsf_name);
+ if (!filter) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
exit_program(1);
}
- if (bsfc_prev)
- bsfc_prev->next = bsfc;
- else
- ost->bitstream_filters = bsfc;
- if (arg)
- if (!(bsfc->args = av_strdup(arg))) {
- av_log(NULL, AV_LOG_FATAL, "Bitstream filter memory allocation failed\n");
+
+ ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
+ ost->nb_bitstream_filters + 1,
+ sizeof(*ost->bsf_ctx));
+ if (!ost->bsf_ctx)
+ exit_program(1);
+
+ ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n");
+ exit_program(1);
+ }
+
+ if (bsf_options_str && filter->priv_class) {
+ const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, NULL);
+ const char * shorthand[2] = {NULL};
+
+ if (opt)
+ shorthand[0] = opt->name;
+
+ ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, bsf_options_str, shorthand, "=", ":");
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
exit_program(1);
}
+ }
+ av_freep(&bsf);
- bsfc_prev = bsfc;
- bsf = next;
+ ost->nb_bitstream_filters++;
+
+ if (*bsfs)
+ bsfs++;
+ }
+ if (ost->nb_bitstream_filters) {
+ ost->bsf_extradata_updated = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_extradata_updated));
+ if (!ost->bsf_extradata_updated) {
+ av_log(NULL, AV_LOG_FATAL, "Bitstream filter memory allocation failed\n");
+ exit_program(1);
+ }
}
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);