Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/ffmpeg.c b/ffmpeg.c
- index b962d5e..bd7e488 100644
- --- a/ffmpeg.c
- +++ b/ffmpeg.c
- @@ -506,10 +506,8 @@ static void ffmpeg_cleanup(int ret)
- if (!ost)
- continue;
- - for (j = 0; j < ost->nb_bitstream_filters; j++)
- - av_bsf_free(&ost->bsf_ctx[j]);
- + av_bsf_free(&ost->bsf_ctx);
- av_freep(&ost->bsf_ctx);
- - av_freep(&ost->bitstream_filters);
- av_frame_free(&ost->filtered_frame);
- av_frame_free(&ost->last_frame);
- @@ -675,6 +673,20 @@ static void write_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- }
- }
- + if (ost->nb_bitstream_filters)
- + if (!ost->bsf_extradata_updated) {
- + if(ost->bsf_ctx->par_out->extradata_size) {
- + av_freep(&ost->st->codecpar->extradata);
- + ost->st->codecpar->extradata_size = 0;
- + ost->st->codecpar->extradata = av_mallocz(ost->bsf_ctx->par_out->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
- + if (!ost->st->codecpar->extradata)
- + exit_program(1);
- + memcpy(ost->st->codecpar->extradata, ost->bsf_ctx->par_out->extradata, ost->bsf_ctx->par_out->extradata_size);
- + ost->st->codecpar->extradata_size = ost->bsf_ctx->par_out->extradata_size;
- + }
- + ost->bsf_extradata_updated = 1;
- + }
- +
- if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
- if (pkt->dts != AV_NOPTS_VALUE &&
- pkt->pts != AV_NOPTS_VALUE &&
- @@ -755,29 +767,20 @@ static void output_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- if (ost->nb_bitstream_filters) {
- int idx;
- - ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);
- + ret = av_bsf_send_packet(ost->bsf_ctx, pkt);
- if (ret < 0)
- goto finish;
- idx = 1;
- - while (idx) {
- + while (1) {
- /* get a packet from the previous filter up the chain */
- - ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
- + ret = av_bsf_receive_packet(ost->bsf_ctx, pkt);
- if (ret == AVERROR(EAGAIN)) {
- ret = 0;
- - idx--;
- - continue;
- + break;
- } else if (ret < 0)
- - goto finish;
- -
- - /* send it to the next filter down the chain or to the muxer */
- - if (idx < ost->nb_bitstream_filters) {
- - ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);
- - if (ret < 0)
- - goto finish;
- - idx++;
- - } else
- - write_packet(s, pkt, ost);
- + break;
- + write_packet(s, pkt, ost);
- }
- } else
- write_packet(s, pkt, ost);
- @@ -2617,34 +2620,20 @@ static int init_output_bsfs(OutputStream *ost)
- if (!ost->nb_bitstream_filters)
- return 0;
- - ost->bsf_ctx = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_ctx));
- - if (!ost->bsf_ctx)
- - return AVERROR(ENOMEM);
- -
- - for (i = 0; i < ost->nb_bitstream_filters; i++) {
- - ret = av_bsf_alloc(ost->bitstream_filters[i], &ctx);
- - if (ret < 0) {
- - av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n");
- - return ret;
- - }
- - ost->bsf_ctx[i] = ctx;
- -
- - ret = avcodec_parameters_copy(ctx->par_in,
- - i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
- + ret = avcodec_parameters_copy(ost->bsf_ctx->par_in,
- + ost->st->codecpar);
- if (ret < 0)
- return ret;
- - ctx->time_base_in = i ? ost->bsf_ctx[i - 1]->time_base_out : ost->st->time_base;
- + ost->bsf_ctx->time_base_in = ost->st->time_base;
- - ret = av_bsf_init(ctx);
- + ret = av_bsf_init(ost->bsf_ctx);
- if (ret < 0) {
- - av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filter: %s\n",
- - ost->bitstream_filters[i]->name);
- + av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filters");
- return ret;
- }
- - }
- - ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
- + ctx = ost->bsf_ctx;
- ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
- if (ret < 0)
- return ret;
- diff --git a/ffmpeg.h b/ffmpeg.h
- index 87cec30..c4f4325 100644
- --- a/ffmpeg.h
- +++ b/ffmpeg.h
- @@ -417,9 +417,9 @@ typedef struct OutputStream {
- /* dts of the last packet sent to the muxer */
- int64_t last_mux_dts;
- + int bsf_extradata_updated;
- int nb_bitstream_filters;
- - const AVBitStreamFilter **bitstream_filters;
- - AVBSFContext **bsf_ctx;
- + AVBSFContext *bsf_ctx;
- AVCodecContext *enc_ctx;
- AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */
- diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
- index c9cc6bc..ee9249b 100644
- --- a/ffmpeg_opt.c
- +++ b/ffmpeg_opt.c
- @@ -1320,31 +1320,13 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
- MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
- MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
- - while (bsfs && *bsfs) {
- - const AVBitStreamFilter *filter;
- - char *bsf;
- -
- - bsf = av_get_token(&bsfs, ",");
- - if (!bsf)
- - exit_program(1);
- -
- - filter = av_bsf_get_by_name(bsf);
- - if (!filter) {
- - av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
- + if (bsfs && *bsfs) {
- + ost->bsf_ctx = av_mallocz(sizeof(*ost->bsf_ctx));
- + if (av_bsf_list_parse_str(bsfs, &ost->bsf_ctx) < 0) {
- + av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsfs);
- exit_program(1);
- }
- - av_freep(&bsf);
- -
- - ost->bitstream_filters = av_realloc_array(ost->bitstream_filters,
- - ost->nb_bitstream_filters + 1,
- - sizeof(*ost->bitstream_filters));
- - if (!ost->bitstream_filters)
- - exit_program(1);
- -
- - ost->bitstream_filters[ost->nb_bitstream_filters++] = filter;
- -
- - if (*bsfs)
- - bsfs++;
- + ost->nb_bitstream_filters = 1;
- }
- MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
Add Comment
Please, Sign In to add comment