Variable Frame Rate MP4

From SDA Knowledge Base

Revision as of 20:34, 26 December 2007 by Ballofsnow (Talk | contribs)

Jump to: navigation, search

Introduction

This guide assumes you're comfortable with AviSynth, MeGUI and batch files or working through the command line.

What is variable frame rate? You can probably guess that a constant frame rate is where the frame rate of a video stays the same throughout its whole length. In VFR you'll have sections that have a different framerate. VFR is useful when the game you've recorded has multiple in-game framerates. For example, God of War for the PS2 outputs gameplay at full framerate while its cinematics are half framerate.


Understanding the VFR process

1. Normally, videos that have different framerates cannot be joined together.

Vfr1.png


2. Using Avisynth, we can change the framerates of each video so that they match, and can thus be joined. Of course this will make parts of the video play faster or slower than it should. As you can see, changing the framerate from 60 to 30 has doubled the length of Video2.

Vfr2.png


3. Once joined, a temporary video is encoded with H.264 / AAC in the MP4 container.

Vfr3.png


4. Now to get the video to play like normal again, we tell tc2mp4 which parts should be set to the orignal framerate. The result is a variable framerate video.

Vfr4.png


Files you'll need

Download tc2mp4 and extract the contents to your working directory. Place mp4box.exe in the same directory. Mp4box can be found in "..\MeGUI\tools\mp4box\".


Avisynth script

As you saw in the pictures above, changing the framerate can change the video duration. Doing so also changes the duration of the audio which affects the pitch; not a good thing. So, the first goal is to create an audio file that sounds normal. Here's a simple AviSynth script:

vid1=avisource("my30fpsvid.avi")
vid2=avisource("my60fpsvid.avi")

vid2=vid2.changefps(vid1)

AlignedSplice(a,b)
ConvertToYV12()

Modify it to your liking and encode the audio only. Once that's done it's time to prepare the real avisynth script. Simply change changefps to assumefps and encode the video.

vid1=avisource("my30fpsvid.avi")
vid2=avisource("my60fpsvid.avi")

vid2=vid2.assumefps(vid1)

AlignedSplice(a,b)
ConvertToYV12()


Finding the frame ranges

To calculate the frame ranges from the AviSynth script above, first find out how many there are in each set.

From the script above, if the 30 fps video had 1000 frames, and the 60 fps video had 2500 frames, then your timecode.txt file would be:

# timecode format v1
Assume 30
0,999,30
1000,3499,60


Setting the VFR

Your encoding should be done now. Open a command line and use the following:

tc2mp4 -i myCFRvid.mp4 -t timecode.txt -o myVFRvid.mp4

tc2mp4 gets rid of any audio in your files so mux the one you made at the beginning of the guide.

And that's it! Now just make sure it plays correctly in Quicktime and you're good to go.

Personal tools