23

I have an MP4 file containing H264 video (25 FPS). Some timestamps are not correct (for reasons...). Can I process the file and have only the timestamps regenerated without reencoding? I've tried this

ffmpeg -r 25 -i infile -c copy outfile

but the timestamps in outfile are still like in the original even though the documentation for"-r" says:

As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps.

I've also tried the suggestion mentioned here at the bottom:

ffmpeg -fflags +genpts -i infile -c copy outfile

This also doesn't change the timestamps in the outfile. Any other way to perform this task? Timestamps are kind of metadata, so I think it should be possible somehow.

2 Answers2

18

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
Brad
  • 6,629
9

The -fps_mode option is used to control output timestamps, not the -r option.  The drop parameter resets input timestamps and generates new ones.

ffmpeg -i source.mp4 -fps_mode drop -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.

Pistacio
  • 159