Hi All, This patch is a bug fix for a problem I faced recently. There are cases when duration info is not available. e.g. reading an mpegts file via a fifo file. But for concatenation this info is mandatory to adjust next file timestamps. So we need to measure it to have this value.
please include my patch in official ffmpeg tree. thanks in advance, best regards, Bela Bodecs
>From 3512d551fbf9d93398373edb37e4e92158bf4227 Tue, 16 Feb 2016 00:10:55 +0100 From: Bela Bodecs <bode...@vivanet.hu> Date: Tue, 16 Feb 2016 00:08:13 +0100 Subject: [PATCH] concatdec: measure duration when it is not available There are cases when duration info is not available. e.g. reading an mpegts file via a fifo file. But for concatenation this info is mandatory to adjust next file timestamps. So we need to measure it to have this value. Signed-off-by: Bela Bodecs <bode...@vivanet.hu> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index d226e15..68c4701 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -47,10 +47,11 @@ ConcatStream *streams; int64_t inpoint; int64_t outpoint; AVDictionary *metadata; int nb_streams; + int64_t measured_duration; } ConcatFile; typedef struct { AVClass *class; ConcatFile *files; @@ -478,11 +479,11 @@ { ConcatContext *cat = avf->priv_data; unsigned fileno = cat->cur_file - cat->files; if (cat->cur_file->duration == AV_NOPTS_VALUE) - cat->cur_file->duration = cat->avf->duration - (cat->cur_file->file_inpoint - cat->cur_file->file_start_time); + cat->cur_file->duration = ((cat->avf->duration == AV_NOPTS_VALUE) ? cat->cur_file->measured_duration : cat->avf->duration) - (cat->cur_file->file_inpoint - cat->cur_file->file_start_time); if (++fileno >= cat->nb_files) { cat->eof = 1; return AVERROR_EOF; } @@ -544,10 +545,11 @@ ConcatContext *cat = avf->priv_data; int ret; int64_t delta; ConcatStream *cs; AVStream *st; + int64_t new_dur; if (cat->eof) return AVERROR_EOF; if (!cat->avf) @@ -587,10 +589,14 @@ av_log(avf, AV_LOG_DEBUG, "file:%d stream:%d pts:%s pts_time:%s dts:%s dts_time:%s", (unsigned)(cat->cur_file - cat->files), pkt->stream_index, av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base)); + new_dur = av_rescale_q(pkt->pts + pkt->duration, cat->avf->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q) - cat->cur_file->file_inpoint; + if (cat->cur_file->measured_duration < new_dur) + cat->cur_file->measured_duration = new_dur; + delta = av_rescale_q(cat->cur_file->start_time - cat->cur_file->file_inpoint, AV_TIME_BASE_Q, cat->avf->streams[pkt->stream_index]->time_base); if (pkt->pts != AV_NOPTS_VALUE) pkt->pts += delta;
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel