Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > Capturing and Editing Video > New and alternative a/v containers

Thread Tools Search this Thread Display Modes
Old 25th May 2011, 20:05   #1  |  Link
Registered User
b66pak's Avatar
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
mp4fpsmod - one pass CFR to VFR tool and more...

for who is interested...


change log


What is this?
Tiny mp4 time code editor.
You can use this for changing fps, delaying audio tracks,
executing DTS compression, extracting time codes of mp4.


Read foo.mp4, change fps to 25, and save to bar.mp4::

mp4fpsmod -r 0:25 -o bar.mp4 foo.mp4

Read foo.mp4, change fps of first 300 frames to 30000/1001, next 600 frames to 24000/1001,
and rest of the movie to 30000/1001 (producing VFR movie)::

mp4fpsmod -r 300:30000/1001 -r 600:24000/1001 -r 0:30000/1001 -o bar.mp4 foo.mp4

Edit timecodes of foo.mp4 with timecode_v2 described in timecode.txt, and save to bar.mp4::

mp4fpsmod -t timecode.txt foo.mp4 -o bar.mp4

Same as above example, with DTS compression enabled and timecodes optimization::

mp4fpsmod -t timecode.txt -x -c foo.mp4 -o bar.mp4

Read timecodes of foo.mp4 and save to timecode.txt::

mp4fpsmod -p timecode.txt foo.mp4

Execute DTS compression, and save to bar.mp4::

mp4fpsmod -c foo.mp4 -o bar.mp4

Delay audio by 100ms using edts/elst::

mp4fpsmod -d 100 foo.mp4 -o bar.mp4

Delay audio by -200ms using DTS/CTS shifting::

mp4fpsmod -d -200 -c foo.mp4 -o bar.mp4



-o file Specify MP4 output filename.
-p file Output current timecodes into timecode-v2 format.
-t file Edit timecodes with timecode-v2 file.
-x When given with -t, optimize timecode entries in the file.
-r nframes:fps
Directly specify fps with option, and edit timecodes.
You can specify -r option more than two times to produce
VFR movie.
"nframes" is number of frames which \"fps\" is aplied to,
0 as nframes means "rest of the movie"
"fps" is a rational or integer. That is, something like
25 or 30000/1001.
-c Enable DTS compression.
-d n Delay audio by n millisecond.

In any cases, the original mp4 is kept as it is (not touched).
-o is required except when you specify -p.
On the other hand, when you specify -p, other options are ignored.

-t and -r are exclusive, and cannot be set both at the same time.
-c and/or -d can be set standalone, or with -t or -r.

When you specify one of -t, -r, -c, -d, timecode is edited/rewritten.
Otherwise without -p, input is just copied with moov->mdat order, without
timecode editing.

You should always set -c when you set -t, -r, -d, if you want your output
widely playable with video/audio in sync, especially with hardware players.
Read about DTS compression for details.

Beware that mp4fpsmod ignores edts/elst of input,
and when timecode is edited, edts/elst of video/audio tracks are deleted,
and re-inserted as needed.
Therefore, if the input has already some audio delays, you have to always
specify it with -d.

About timecode optimization

Consider timecode file like this::

# timecode format v2

This is the example of timecodes for 30000/1001 fps movie.
In this case, each timeDelta of entries are 33, 34, 33, 33, 34, 33...

When -x option is given, and when timecodes are integer values, mp4fpsmod tries
to divide timecodes into groups, whose entries have time delta very close to each other.
Then, average each group's time delta into one floating point value.

mp4fpsmod also tries to do further optimization when -x option specified.
If every timeDelta of frames looks like close enough to one of the well known NTSC or PAL rate,
mp4fpsmod takes the latter, and do the exact math, instead of floating point calcuration.

You can control these behaviors by -x option. Without -x, literal values in the timecodes_v2 file will be used.

About DTS Compression

By default, mp4fpsmod produces rather straightforward DTS.
For example, when you specify -r 300:30000/1001 -r400 24000/1001,

- TimeScale is set to 120000, which is LCM of 30000 and 24000
- DTS is like 0, 4004, 8008,... for first 300 frames.
For next 400 frames, DTS delta is 5005.
- CTS is like DTS, except that it is arranged in the composition
order, instead of decoding/frame order.

In the mp4 container, stts box(which holds DTS delta) will look like this::

<TimeToSampleEntry SampleDelta="4004" SampleCount="300"/>
<TimeToSampleEntry SampleDelta="5005" SampleCount="400"/>

Timecodes of this movie will be with something like this, if B-frame is used:

------------ --------
------------ --------
0 0(I)
4004 12012(P)
8008 4004(B)
12012 8008(B)
16016 24024(P)
20020 16016(B)
------------ --------

However, this doesn't satisfy DTS <= CTS, for some frames.
Therefore, we have to shift(delay) CTS. Finally, we get:

------------ -----
------------ -----
0 4004
4004 16016
8008 8008
12012 12012
16016 28028
20020 20020
------------ -----

As you can see, CTS of first frame is non-zero value, therefore has delay of
4004, in timescale unit.
This delay value is, by default, saved into edts/elst box.
If your player handles edts/elst properly, this is fine.
However, there's many players in the wild, which lacks edts support.
If you are using them, you might find video/audio out of sync.

DTS compression comes for this reason.
If you enable DTS compression with "-c" option, mp4fpsmod produces smaller
DTS at beginning, and minimizes the CTS delay without the help of
edts/elst box.
With DTS compression, DTS and CTS will be something like this:

----------- -----
----------- -----
0 0
2002 12012
4004 4004
8008 8008
12012 24024
16016 16016
----------- -----

About audio delay

You can specify audio delay with -d option.
Delay is in milliseconds, and both positive and negative values are valid.

When you don't enable DTS compression with -c, delay is just achieved with
edts/elst setting. If positive, video track's edts is set. Otherwise,
each audio track's edts is set.

When you enable DTS compression, DTS/CTS are directly shifted to reflect
the delay.
When delay is positive, smaller DTS/CTS are assigned for the beginning of
movie, so that video plays faster and audio is delayed,
until it reaches the specified delay time.
Negative delay is achieved mostly like the positive case, except that
bigger DTS/CTS are used, and video plays slower.

N.B. I am not the developer of this tool!
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note...
Visit The Land Of Dracula (Romania - EU)!
b66pak is offline   Reply With Quote
Old 26th May 2011, 12:19   #2  |  Link
Registered User
Selur's Avatar
Join Date: Oct 2001
Location: Germany
Posts: 5,903
Thanks for posting, a tool that can extract time codes without extracting the video stream as well is a thing I was waiting for.
preferring a static build, I compiled it with VS C++ Express 2010 statically: mp4fpsmod_0.12_static.7z -> http://www.multiupload.com/P2EUXFMQ5T
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..

Last edited by Selur; 28th May 2011 at 11:57.
Selur is offline   Reply With Quote
Old 14th September 2011, 18:58   #3  |  Link
Registered User
b66pak's Avatar
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
new version...
[mp4fpsmod] v0.15
posted Sep 12, 2011 9:39 PM by nu 774

Added better progress message.
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note...
Visit The Land Of Dracula (Romania - EU)!
b66pak is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 07:43.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.