Trim video and concatenate using ffmpeg - getting "Non-monotonous DTS in output stream" errors

Use

ffmpeg -i 0.mp4 -c:v h264_nvenc -preset fast -rc vbr -qmin 1 -qmax 1 -filter_complex "[0:v]trim=start=01.00:duration=03.00,setpts=PTS-STARTPTS[vmiddle]" -video_track_timescale 18000 -map [vmiddle] middle_0.mp4

Those numbers in the ffprobe readout are presentation timestamps and inform the player when to display each frame. They are denominated in terms of a timebase. So, a PTS of 600 with a timebase of 1/1200 (or timescale of 1200), means a display time of 600 * 1/1200 = 0.5 seconds, as does a PTS of 700 with a timescale of 1400. Now, when two videos with different timebases are joined, the result won't be correct since ffmpeg will adopt the timebase of the first video as the definitive value. I added a parameter to make those uniform.

Tags:

Ffmpeg

Video

Mp4