Explicit timebase with ffmpeg and variable framerates in mp4s

5,708

Solution 1

Use the private MP4 muxer option

ffmpeg.exe -i .\ballon.mp4 -c copy -video_track_timescale 120 .\ballon-120.mp4

With your command, you were re-encoding the video and supplying a time base to the encoder, which ffmpeg uses for frame duplication/drop decisons.

Solution 2

The key was using the vsync option like this:

ffmpeg.exe -i .\ballon.mp4 -enc_time_base 1:120 -vsync vfr .\ballon-120.mp4

Share:
5,708

Related videos on Youtube

John
Author by

John

If you want to contact me, send a mail to [email protected].

Updated on September 18, 2022

Comments

  • John
    John almost 2 years

    I need to concatenate a number of video files with different framerates to play them with OMXPlayer on a Raspberry PI (the concatenation is also done on the PI).

    Both the originals and the concatenation are mp4/h264 and the originals are also created by some software of mine.

    Using ffmpegs copy muxer doesn't work when the files have different time bases.

    So I was thinking that I produce the original videos with an explicit timebase of 120 (120 is divisible by both 25 and 30, the only frame rates I care about).

    The test

    ffmpeg.exe -i .\ballon.mp4 -enc_time_base 1:120 .\ballon-120.mp4
    

    seems promising: ffmpeg says it produces a 30fps video (the original was 30fps) with a timebase of 120 in the output.

    However, it also says that it "duplicates frames" a lot and the following command tells me I have 4 times as many frames as I actually should have:

    ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 .\ballon.mp4
    

    ffprobe also thinks the frame rate is now 120 and indeed OMXPlayer complains about the framerate being too high and plays the video somewhat slow.

    What I want is to change the timebase, not the frame rate or the number of frames. How do I do that?

  • John
    John about 6 years
    Awesome! I found another way also (see my own answer), but yours is better as it doesn't have to be done at encoding time. Annoying that it isn't documented.
  • slhck
    slhck about 6 years
    @John Run ffmpeg -h full and look for the option.
  • Gyan
    Gyan about 6 years
    I don't recommend this. Encoder time base is used by some encoders, like x264, to modulate rate-control. Even with the same set of frames, the encode will produce a different bitrate. Significant issue for longer videos.
  • John
    John about 6 years
    @Gyan Interesting. Do you habe resources to recommend on why it does that? Just curious.
  • Gyan
    Gyan about 6 years
    Codecs like x264.. take human perception into account. A longer a frame is shown, the greater bits it is rationed. The encoder timebase is used to infer frame durations.