PTS/DTS timestamps get broken when concatenating MPEG-TS files using -f concat
|Reported by:||Jarda Snajdr||Owned by:||Marton Balint|
|Blocking:||Reproduced by developer:||no|
|Analyzed by developer:||no|
Description (last modified by )
Steps to reproduce:
- Download two *.ts files and a list.txt from this Dropbox URL:
- Concat them with this command:
ffmpeg -f concat -i list.txt -c copy output.ts
- Look at the PTS/DTS timestamps of the output.ts file:
ffprobe -show_entries packet=codec_type,stream_index,pts,dts output.ts
The timestamps are in a continuous range and the transitions from one chunk to the next are seamless.
The timestamps from the first chunk are OK, but at the start of the second, they start to be shifted by a big time interval backwards, which causes a timestamp wrap by 233. This causes a huge discontinuity and a resulting file duration of 26 hours instead of 6 seconds.
Fixing the delta-computing algorithm in libavformat/concatdec.c:concat_read_packet fixed the issue for me (see the patch below). But I suspect it doesn't work in the general case. My case is special in that the timestamps are not-overlapping, following one sequence across files. Concatenating files where timestamps always start from zero probably won't work. I don't know how to fix it, the timestamp shifting/scaling logic is very complex and confusing.
ffmpeg bleeding-edge from Github master. The issue is new in 2.8 - it didn't happen in 2.7.
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 832b7f4..1151b10 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -580,7 +580,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base)); - delta = av_rescale_q(cat->cur_file->start_time - cat->cur_file->file_inpoint, + delta = av_rescale_q(cat->cur_file->file_start_time - cat->cur_file->file_inpoint, AV_TIME_BASE_Q, cat->avf->streams[pkt->stream_index]->time_base);
Change History (8)
comment:1 by , 6 years ago
|Component:||ffmpeg → avfilter|
|Keywords:||concat regression added|
|Priority:||normal → important|
|Version:||unspecified → git-master|