diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-10 20:58:15 +0100 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-10 20:59:55 +0100 |
commit | 6f69f7a8bf6a0d013985578df2ef42ee6b1c7994 (patch) | |
tree | 0c2ec8349ff1763d5f48454b8b9f26374dbd80b0 /libavformat/concatdec.c | |
parent | 60b75186b2c878b6257b43c8fcc0b1356ada218e (diff) | |
parent | 9200514ad8717c63f82101dc394f4378854325bf (diff) | |
download | ffmpeg-6f69f7a8bf6a0d013985578df2ef42ee6b1c7994.tar.gz |
Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
lavf: replace AVStream.codec with AVStream.codecpar
This has been a HUGE effort from:
- Derek Buitenhuis <derek.buitenhuis@gmail.com>
- Hendrik Leppkes <h.leppkes@gmail.com>
- wm4 <nfxjfg@googlemail.com>
- Clément Bœsch <clement@stupeflix.com>
- James Almer <jamrial@gmail.com>
- Michael Niedermayer <michael@niedermayer.cc>
- Rostislav Pehlivanov <atomnuker@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavformat/concatdec.c')
-rw-r--r-- | libavformat/concatdec.c | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 20a37e022a..50d6689413 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -35,6 +35,7 @@ typedef enum ConcatMatchMode { typedef struct ConcatStream { AVBitStreamFilterContext *bsf; + AVCodecContext *avctx; int out_stream_index; } ConcatStream; @@ -164,19 +165,28 @@ static int copy_stream_props(AVStream *st, AVStream *source_st) { int ret; - if (st->codec->codec_id || !source_st->codec->codec_id) { - if (st->codec->extradata_size < source_st->codec->extradata_size) { - ret = ff_alloc_extradata(st->codec, - source_st->codec->extradata_size); + if (st->codecpar->codec_id || !source_st->codecpar->codec_id) { + if (st->codecpar->extradata_size < source_st->codecpar->extradata_size) { + if (st->codecpar->extradata) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + } + ret = ff_alloc_extradata(st->codecpar, + source_st->codecpar->extradata_size); if (ret < 0) return ret; } - memcpy(st->codec->extradata, source_st->codec->extradata, - source_st->codec->extradata_size); + memcpy(st->codecpar->extradata, source_st->codecpar->extradata, + source_st->codecpar->extradata_size); return 0; } - if ((ret = avcodec_copy_context(st->codec, source_st->codec)) < 0) + if ((ret = avcodec_parameters_copy(st->codecpar, source_st->codecpar)) < 0) return ret; + /* We don't want to carry around MP4-style extradata, since we are usoign a bsf anyway. */ + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + } st->r_frame_rate = source_st->r_frame_rate; st->avg_frame_rate = source_st->avg_frame_rate; st->time_base = source_st->time_base; @@ -192,9 +202,10 @@ static int detect_stream_specific(AVFormatContext *avf, int idx) AVStream *st = cat->avf->streams[idx]; ConcatStream *cs = &cat->cur_file->streams[idx]; AVBitStreamFilterContext *bsf; + int ret; - if (cat->auto_convert && st->codec->codec_id == AV_CODEC_ID_H264 && - (st->codec->extradata_size < 4 || AV_RB32(st->codec->extradata) != 1)) { + if (cat->auto_convert && st->codecpar->codec_id == AV_CODEC_ID_H264 && + (st->codecpar->extradata_size < 4 || AV_RB32(st->codecpar->extradata) != 1)) { av_log(cat->avf, AV_LOG_INFO, "Auto-inserting h264_mp4toannexb bitstream filter\n"); if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb"))) { @@ -203,6 +214,17 @@ static int detect_stream_specific(AVFormatContext *avf, int idx) return AVERROR_BSF_NOT_FOUND; } cs->bsf = bsf; + + cs->avctx = avcodec_alloc_context3(NULL); + if (!cs->avctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(cs->avctx, st->codecpar); + if (ret < 0) { + avcodec_free_context(&cs->avctx); + return ret; + } + } return 0; } @@ -338,15 +360,21 @@ static int open_file(AVFormatContext *avf, unsigned fileno) static int concat_read_close(AVFormatContext *avf) { ConcatContext *cat = avf->priv_data; - unsigned i; + unsigned i, j; - if (cat->avf) - avformat_close_input(&cat->avf); for (i = 0; i < cat->nb_files; i++) { av_freep(&cat->files[i].url); + for (j = 0; j < cat->avf->nb_streams; j++) { + if (cat->files[i].streams[j].avctx) + avcodec_free_context(&cat->files[i].streams[j].avctx); + if (cat->files[i].streams[j].bsf) + av_bitstream_filter_close(cat->files[i].streams[j].bsf); + } av_freep(&cat->files[i].streams); av_dict_free(&cat->files[i].metadata); } + if (cat->avf) + avformat_close_input(&cat->avf); av_freep(&cat->files); return 0; } @@ -499,7 +527,8 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) av_assert0(cs->out_stream_index >= 0); for (bsf = cs->bsf; bsf; bsf = bsf->next) { pkt2 = *pkt; - ret = av_bitstream_filter_filter(bsf, st->codec, NULL, + + ret = av_bitstream_filter_filter(bsf, cs->avctx, NULL, &pkt2.data, &pkt2.size, pkt->data, pkt->size, !!(pkt->flags & AV_PKT_FLAG_KEY)); @@ -507,6 +536,21 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) av_packet_unref(pkt); return ret; } + + if (cs->avctx->extradata_size > st->codecpar->extradata_size) { + int eret; + if (st->codecpar->extradata) + av_freep(&st->codecpar->extradata); + + eret = ff_alloc_extradata(st->codecpar, cs->avctx->extradata_size); + if (eret < 0) { + av_packet_unref(pkt); + return AVERROR(ENOMEM); + } + st->codecpar->extradata_size = cs->avctx->extradata_size; + memcpy(st->codecpar->extradata, cs->avctx->extradata, cs->avctx->extradata_size); + } + av_assert0(pkt2.buf); if (ret == 0 && pkt2.data != pkt->data) { if ((ret = av_copy_packet(&pkt2, pkt)) < 0) { |