summaryrefslogtreecommitdiffstats
path: root/libavformat/concatdec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat/concatdec.c')
-rw-r--r--libavformat/concatdec.c70
1 files changed, 57 insertions, 13 deletions
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 20a37e0..50d6689 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) {
OpenPOWER on IntegriCloud