josh-stackexchange
josh-stackexchange

Reputation: 175

ffmpeg -to with -ss before input file

Using ffmpeg in the order ffmpeg -ss 00:04:21 -i "filename.mp4" -to 00:04:47 -c copy "output.mp4" is far faster than switching the order of the -ss and -i flags but -ss causes the timestamps to be incorrect for the -to flag, making them not match and the -to not correspond to the correct time in the source file. Adding -copyts fixes this issue and trims it to the correct the time, but causes the timestamps to show the original's in the output file, i.e. the time in the output file starts at 4:47 on any viewer despite the video only being 26 seconds long.

Using the order ffmpeg -i "filename.mp4" -ss 00:04:21 -to 00:04:47 -c copy "output.mp4" fixes the issue at the cost of a much longer execution time.

Is there any way to get the best of both such that it seeks to the correct time before opening the file while still being fast?

Upvotes: 2

Views: 2993

Answers (1)

Gyan
Gyan

Reputation: 93068

FFmpeg, by default, normalizes input timestamps to start from 0. So, the -to as an output option effectively becomes a duration limiter. -copyts avoids that by not resetting the timestamps. However, some players may not gracefully handle non-zero start times.

Using -to as input option (available since v4.0) achieves your goal.

Upvotes: 5

Related Questions