FFmpeg: recreate timestamps without reencoding
It turns out that the -r
option only works for raw stream data. (This can be an H.264 stream... it does not have to be just pixel data.)
In this example, I'm using MP4 containers. First, extract the stream:
ffmpeg -i source.mp4 -map 0:v -vcodec copy -bsf:v h264_mp4toannexb source-video.h264
Next, take that stream and re-mux it, but with a specific frame rate and generated timestamps.
ffmpeg -fflags +genpts -r 60 -i source-video.h264 -vcodec copy output.mp4
The -vsync
option is used to control output timestamps, not the -r
option.
The drop
parameter resets input timestamps and generates new ones.
ffmpeg -vsync drop -i source.mp4 -map 0:v -vcodec copy output.mp4
The -r
option before the input tells FFmpeg to read the specified number of frames in constant mode. FFmpeg sometimes has a hard time figuring out the input frames count.
By specifying the exact number, you eliminate misunderstandings.
The -r
option works with all type of data, raw or encoded.
By the way H.264 is the exact opposite of raw.