[FFmpeg-user] Fixing bad DTS/PTS without reencode

Massimo Battistel battistel at gmail.com
Sun Jan 13 11:52:29 CET 2013

> Could you elaborate what you mean with "wrong DTS"?

Suppose a correct files (25fps, times in milliseconds) reading with
av_read_packet only video track.

dts        duration
0            40
40           40
80           40
120          40

For various reasons (i.e. a bad merge of 2 videos) you could find:

dts        duration
0             40
40            40
160           40   <---- (apparent) discontinuty
200           40

Usually these files have also bad header duration: It may be duration of
the first video or "lastDTS - firstDTS + frame_duration".

What I want to do is to recalculate dts/pts without reencode (and fix
header duration too).

The first things I tried were:
ffmpeg -i "d:\temp\sample.mkv" -vcodec copy d:\temp\output.mkv
ffmpeg -i "d:\temp\sample.mkv" -vcodec copy -vsync 0 d:\temp\output1.mkv
ffmpeg -i "d:\temp\sample.mkv" -vcodec copy -vsync 1 d:\temp\output2.mkv
ffmpeg -i "d:\temp\sample.mkv" -vcodec copy -vsync 2 d:\temp\output3.mkv

but the video track in all cases preserved the same errors in the same
All output files have same size but different MD5 (so the -vsync parameter
is not totally ignored).

Then I tried:
A. ffmpeg -i "d:\temp\sample.mkv" -vcodec copy -vfilter:v "setpts=2.0*PTS"
B. ffmpeg -i "d:\temp\sample.mkv" -vfilter:v "setpts=2.0*PTS"

With (A) errors are always there and -filter seems to be ignored, (B)
transcoded and doubled video duration, but added even more errors.

I hope you understand better my needs now.

More information about the ffmpeg-user mailing list