X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmux.c;h=e9973edd0865127409cfa41d136e8e0d96f4b529;hb=3282e31baaa77d161a4451c27ad0d45f78e1da0a;hp=a44764519870de6f56ee3850da50736f1af80ec4;hpb=e6d0acd4383d9400d3c6f174e3d8abb98ec38818;p=ffmpeg diff --git a/libavformat/mux.c b/libavformat/mux.c index a4476451987..e9973edd086 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -557,7 +557,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * av_log(s, AV_LOG_TRACE, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n", av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index); - if (pkt->duration < 0 && st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { av_log(s, AV_LOG_WARNING, "Packet with invalid duration %"PRId64" in stream %d\n", pkt->duration, pkt->stream_index); pkt->duration = 0; @@ -623,7 +623,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * st->priv_pts->val = pkt->dts; /* update pts */ - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: frame_size = (pkt->flags & AV_PKT_FLAG_UNCODED_FRAME) ? ((AVFrame *)pkt->data)->nb_samples : @@ -817,6 +817,57 @@ static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt) return 0; } +static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) { + AVStream *st = s->streams[pkt->stream_index]; + int i, ret; + + if (s->oformat->check_bitstream) { + if (!st->internal->bitstream_checked) { + if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) + return ret; + else if (ret == 1) + st->internal->bitstream_checked = 1; + } + } + + for (i = 0; i < st->internal->nb_bsfcs; i++) { + AVBSFContext *ctx = st->internal->bsfcs[i]; + if (i > 0) { + AVBSFContext* prev_ctx = st->internal->bsfcs[i - 1]; + if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) { + if ((ret = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0) + return ret; + } + } + // TODO: when any bitstream filter requires flushing at EOF, we'll need to + // flush each stream's BSF chain on write_trailer. + if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) { + av_log(ctx, AV_LOG_ERROR, + "Failed to send packet to filter %s for stream %d", + ctx->filter->name, pkt->stream_index); + return ret; + } + // TODO: when any automatically-added bitstream filter is generating multiple + // output packets for a single input one, we'll need to call this in a loop + // and write each output packet. + if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) { + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + return 0; + av_log(ctx, AV_LOG_ERROR, + "Failed to send packet to filter %s for stream %d", + ctx->filter->name, pkt->stream_index); + return ret; + } + if (i == st->internal->nb_bsfcs - 1) { + if (ctx->par_out->extradata_size != st->codecpar->extradata_size) { + if ((ret = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0) + return ret; + } + } + } + return 1; +} + int av_write_frame(AVFormatContext *s, AVPacket *pkt) { int ret; @@ -842,6 +893,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) return 1; } + ret = do_packet_auto_bsf(s, pkt); + if (ret <= 0) + return ret; + #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt); @@ -1082,7 +1137,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) { - int ret, flush = 0, i; + int ret, flush = 0; ret = prepare_input_packet(s, pkt); if (ret < 0) @@ -1091,50 +1146,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) if (pkt) { AVStream *st = s->streams[pkt->stream_index]; - if (s->oformat->check_bitstream) { - if (!st->internal->bitstream_checked) { - if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) - goto fail; - else if (ret == 1) - st->internal->bitstream_checked = 1; - } - } - - for (i = 0; i < st->internal->nb_bsfcs; i++) { - AVBSFContext *ctx = st->internal->bsfcs[i]; - if (i > 0) { - AVBSFContext* prev_ctx = st->internal->bsfcs[i - 1]; - if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) { - if ((ret = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0) - goto fail; - } - } - // TODO: when any bitstream filter requires flushing at EOF, we'll need to - // flush each stream's BSF chain on write_trailer. - if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) { - av_log(ctx, AV_LOG_ERROR, - "Failed to send packet to filter %s for stream %d", - ctx->filter->name, pkt->stream_index); - goto fail; - } - // TODO: when any automatically-added bitstream filter is generating multiple - // output packets for a single input one, we'll need to call this in a loop - // and write each output packet. - if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) { - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) - return 0; - av_log(ctx, AV_LOG_ERROR, - "Failed to send packet to filter %s for stream %d", - ctx->filter->name, pkt->stream_index); - goto fail; - } - if (i == st->internal->nb_bsfcs - 1) { - if (ctx->par_out->extradata_size != st->codecpar->extradata_size) { - if ((ret = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0) - goto fail; - } - } - } + ret = do_packet_auto_bsf(s, pkt); + if (ret == 0) + return 0; + else if (ret < 0) + goto fail; if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",