I extract the part from 2:00 to 3:30 of a video with ffmpeg
:
ffmpeg -i input.mp4 -ss 120 -t 90 -vcodec copy -acodec copy output.mp4
It works but the output video is jerky/choppy, i.e. not really smooth/fluid. The log I have is:
[mp4 @ 000000000041c700] track 1: codec frame size is not set
[mp4 @ 000000000041c700] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 000000000041c700] pts has no value
Last message repeated 7894 times
When watching the original video and navigating to 00:02:00.000
, the video is perfectly fluid/smooth. How to fix this?
The reason might be that (see here):
A video stream consists of chunks of video [...] At the start of each chunk is a keyframe, which contains the entire frame, and then the subsequent frame data consists of changes to the previous image.
When you use -c:v copy -ss 123.45, chances are the timestamp you're specifying doesn't coincide with a keyframe, and so your resultant video will assume a black keyframe and the subsequent frame changes will not make much sense, hence giving a choppy output.
What solution is there, without reencoding?
Maybe: a flag in ffmpeg in addition to -ss 123.45
to ask ffmpeg to keep all the data since the previous keyframe and a flag in the video to say "the video should begin at 123.45".
TL;DR: the output MP4 might contain data from 118.28, but with a flag to begin the playback only at 123.45.