Opened 6 years ago

Last modified 6 years ago

#7353 new defect

Option -ss on output with -c copy uses dts instead of pts

Reported by: Misaki Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: dts, pts
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Editing scenario: have a finished video, want to copy audio from another video starting at a certain point.

If you use the command

ffmpeg -ss 11 -i video1.webm -i video2.mp4 -c copy output.mkv

then ffmpeg will seek to the video keyframe before 11 in video1.webm, and copy audio from there, instead of from 11.

If you add -ss 0 to the output, it trims audio before 11. But due to this bug, if the first dts of video2.mp4 is negative, it also trims the first group of pictures.

How to replicate:

ffmpeg -filter_complex color=black -t 2 -g 25 black.mp4; ffmpeg -i black.mp4 -c copy -ss 0 black2.mp4; ffmpeg -i black.mp4 -ss 0 black3.mp4

The first file is 50 frames. The second, using -c copy, is only 25 frames. The third, not copying, is 50 frames. Verbose output for these commands attached to report.

The desired behaviour is that packets are trimmed based on their presentation timestamp (pts), not their decode timestamp (dts).

Attachments (3)

ffmpeg-20180812-155540.log (13.2 KB ) - added by Misaki 6 years ago.
First command's verbose output
ffmpeg-20180812-155542.log (11.7 KB ) - added by Misaki 6 years ago.
Second command's verbose output
ffmpeg-20180812-155543.log (25.9 KB ) - added by Misaki 6 years ago.
Third command's verbose output

Download all attachments as: .zip

Change History (5)

by Misaki, 6 years ago

Attachment: ffmpeg-20180812-155540.log added

First command's verbose output

by Misaki, 6 years ago

Attachment: ffmpeg-20180812-155542.log added

Second command's verbose output

by Misaki, 6 years ago

Attachment: ffmpeg-20180812-155543.log added

Third command's verbose output

comment:1 by Gyan, 6 years ago

For your root use case, you can run

ffmpeg -seek2any 1 -ss 11 -i video1.webm -i video2.mp4 -c copy -map 1:v -map 0:a output.mkv

For supporting demuxers (like Matroska), this won't seek to an earlier KF.

comment:2 by Misaki, 6 years ago


Note: See TracTickets for help on using tickets.