bond
31st March 2004, 11:18
as most of you might propably already know its possible to create variable framerate video streams with mpeg-4 video
the fact why it is often not used is probably caused by the crappy avi container, which (apart from many other issues) is not able to store real variable framerate streams
now with the upcoming of far more advanced containers (like matroska and mp4) able to handle vfr, i think we should explore the possibilites of vfr far more (and i hope i can encourage some people to help me with my currently ongoing testings):
as avi and vfw (used by xvid and divx5 in vdm) doesnt seem to be able to handle vfr at all there are two possibilities to create vfr mpeg-4 video streams
1) use a directshow encoder, like the one from 3ivx (suxendrol is already working on a xvid dshow enc filter) and dont even think about touching crappy outdated avi and vfw
2) use vfw encoders, with avi workarounds, and do some smart avi->mp4 conversions:
the xvid encoder already offers the so called "frame drop ratio":
with a setting of 0 only frames get dropped which are 100% the same as the frame before, with 100 all frames are dropped
this option's name and description might be a little misleading as the frames arent really totally dropped (leading to vfr or less frames in the output), also a value of 50 doesnt mean that every second frame is affected -> frames get simply not coded, which means so called n-vops are placed in the stream
this value specifies a threshold under which, if the difference of the following frame to the previous frame is below or equal to this threshold, a frame gets not coded (see it could even be that you set a value of 50, but still no frame gets not coded)
on the decoder side, everytime when the decoder comes to such a n-vop, it displays the frame before the n-vop again, therefore its some sort of "fake vfr stream"
now with the 3ivx or MP4Box MP4 muxers these n-vops can be really dropped and real vfr mpeg-4 streams get created inside the mp4 container
small howto
1) open your to-encode source in virtualdubmod (http://sourceforge.net/projects/virtualdubmod/)
2) go to the xvid (http://xvid.gamrdev.com/) codec settings and choose the settings as you wish and set the frame drop ratio you want to use (on my testssample it seemed that i didnt get a dropped frame with a value of 15, with 90 there were (of course) far too much dropped frames) also it seems that the frame drop ratio seems to work better when packed bitstream (b-frames) is disabled
now you can decide whether you want to use the commandline MP4Box or the 3ivx directshow muxer to create a VFR MP4 file:
MP4Box:
3) download mp4box from rarewares (http://www.rarewares.org/mp4.html)
4) run the following commandline:
MP4Box -import myavi.avi mymp4.mp4 3ivx:
3) install 3ivx (http://www.3ivx.com/download/index.html)
4) open the resulting avi in graphedit (http://www.doom9.org/Soft21/Filters/graphedit.rar)
5) remove all filters, except the source and the avi splitter, load the 3ivx mp4 muxer and the file writer (*.mp4) and connect the 3ivx muxer between avi splitter and file writer
6) enable the "compress n-vops" option in the 3ivx muxer and push play
you should now be able to enjoy and play the created variable frame rate mp4 file with every mpeg-4 decoder (xvid, divx5, ffdshow, 3ivx etc...) in any dshow based player without loosing sync with the audio aso...
edit:
note that during my testings i found that the frame drop ratio was broken in the current release candidates (koepis rc3). syskin now fixed some bugs but it seems that there are still "unfixable" problems when using it with b-frames
therefore the frame drop option in xvid will only work without b-frames from now on :(
edit2: added gpac's mp4box, as it offers exactly the same features as 3ivx now too
the fact why it is often not used is probably caused by the crappy avi container, which (apart from many other issues) is not able to store real variable framerate streams
now with the upcoming of far more advanced containers (like matroska and mp4) able to handle vfr, i think we should explore the possibilites of vfr far more (and i hope i can encourage some people to help me with my currently ongoing testings):
as avi and vfw (used by xvid and divx5 in vdm) doesnt seem to be able to handle vfr at all there are two possibilities to create vfr mpeg-4 video streams
1) use a directshow encoder, like the one from 3ivx (suxendrol is already working on a xvid dshow enc filter) and dont even think about touching crappy outdated avi and vfw
2) use vfw encoders, with avi workarounds, and do some smart avi->mp4 conversions:
the xvid encoder already offers the so called "frame drop ratio":
with a setting of 0 only frames get dropped which are 100% the same as the frame before, with 100 all frames are dropped
this option's name and description might be a little misleading as the frames arent really totally dropped (leading to vfr or less frames in the output), also a value of 50 doesnt mean that every second frame is affected -> frames get simply not coded, which means so called n-vops are placed in the stream
this value specifies a threshold under which, if the difference of the following frame to the previous frame is below or equal to this threshold, a frame gets not coded (see it could even be that you set a value of 50, but still no frame gets not coded)
on the decoder side, everytime when the decoder comes to such a n-vop, it displays the frame before the n-vop again, therefore its some sort of "fake vfr stream"
now with the 3ivx or MP4Box MP4 muxers these n-vops can be really dropped and real vfr mpeg-4 streams get created inside the mp4 container
small howto
1) open your to-encode source in virtualdubmod (http://sourceforge.net/projects/virtualdubmod/)
2) go to the xvid (http://xvid.gamrdev.com/) codec settings and choose the settings as you wish and set the frame drop ratio you want to use (on my testssample it seemed that i didnt get a dropped frame with a value of 15, with 90 there were (of course) far too much dropped frames) also it seems that the frame drop ratio seems to work better when packed bitstream (b-frames) is disabled
now you can decide whether you want to use the commandline MP4Box or the 3ivx directshow muxer to create a VFR MP4 file:
MP4Box:
3) download mp4box from rarewares (http://www.rarewares.org/mp4.html)
4) run the following commandline:
MP4Box -import myavi.avi mymp4.mp4 3ivx:
3) install 3ivx (http://www.3ivx.com/download/index.html)
4) open the resulting avi in graphedit (http://www.doom9.org/Soft21/Filters/graphedit.rar)
5) remove all filters, except the source and the avi splitter, load the 3ivx mp4 muxer and the file writer (*.mp4) and connect the 3ivx muxer between avi splitter and file writer
6) enable the "compress n-vops" option in the 3ivx muxer and push play
you should now be able to enjoy and play the created variable frame rate mp4 file with every mpeg-4 decoder (xvid, divx5, ffdshow, 3ivx etc...) in any dshow based player without loosing sync with the audio aso...
edit:
note that during my testings i found that the frame drop ratio was broken in the current release candidates (koepis rc3). syskin now fixed some bugs but it seems that there are still "unfixable" problems when using it with b-frames
therefore the frame drop option in xvid will only work without b-frames from now on :(
edit2: added gpac's mp4box, as it offers exactly the same features as 3ivx now too