Variable frame rate for mencoder
Hi all I had a need to generate variable frame rate avi files and timecode stamps for muxing into other containers (specifically .mkv) and hacked in a -makevfr option into mencoder. There are only a handful of really awful unmaintained windows apps that manage these currently. What this does is it generates an avi output file without any null frames, which is pretty much unusable by itself, but it also generates a timecodes version2 file (timecodes.txt). The resulting avi file and timecodes file can then be muxed into a true variable frame rate container such as mkv using mkvtoolnix. So what this is useful for, is the various pseudo variable frame rate videos out there such as wmv (which imitates 1000fps) and the so called 120fps ntsc video captures. These are usually a blend of various combinations of 24000/1001, 30000/1001 and 60000/1001 videos. No fixed frame rate ever creates smooth video from them. To use this, you must use nosound as the resultant file is meaningless without it. Any frame rate input should be able to be used, and the resultant output *should* always have audio video sync. Eg: mencoder -nosound -ovc lavc -mc 0 -makevfr -o temporary_vfr.avi source.wmv the resultant temporary_vfr.avi file then needs to be muxed with mkvtoolnix specifying the timecodes for that video stream and the audio needs to be added separately. mplayer -vo null -ao pcm:fast:file=audio.wav source.wmv faac audio.wav mkvmerge -o vfr.mkv --timecodes 0:timecodes.txt temporary_vfr.avi audio.aac This should generate a real variable frame rate in a container that supports it without losing audio sync from any input. The use of -ofps can be used to set the maximum frame rate, but is usually not required. I'd actually suggest using it for wmv because at a precision of 1000fps it actually isn't any meaningful multiple of the real frame rates. The best is actually that 120 number used by avi, so -ofps 120000/1001 Generally speaking, those who already know about making variable frame rate anime will already know what to do. I realise mencoder has lots of issues and is considered broken at the moment, but there are many of us who depend on it as it fills a niche nothing else does. I also realise that I have not studied the code style of mplayer/mencoder extensively and have probably committed numerous sins in the way I've hacked this up. Thus I don't expect the code to be committed. However, I offer it as a demonstration piece and of interest since it has been incredibly useful to me, dealing with variable frame rate mkv, mp4, 120fps avi, wmv. Cheers, and thanks for mplayer. Patch attached. -- -ck
On Mon, 2008-02-18 at 11:06 +1100, Con Kolivas wrote:
Hi all
I had a need to generate variable frame rate avi files and timecode stamps for muxing into other containers (specifically .mkv) and hacked in a -makevfr option into mencoder. There are only a handful of really awful unmaintained windows apps that manage these currently.
What this does is it generates an avi output file without any null frames, which is pretty much unusable by itself, but it also generates a timecodes version2 file (timecodes.txt). The resulting avi file and timecodes file can then be muxed into a true variable frame rate container such as mkv using mkvtoolnix.
So what this is useful for, is the various pseudo variable frame rate videos out there such as wmv (which imitates 1000fps) and the so called 120fps ntsc video captures. These are usually a blend of various combinations of 24000/1001, 30000/1001 and 60000/1001 videos. No fixed frame rate ever creates smooth video from them.
From my testing, mkvmerge can handle a 120fps avi file as input just fine, outputting an mkv with the correct timecodes, so you shouldn't really need this hack. For my encoding currently, I use mencoder to encode directly to h264 120fps avi (with b-frames even, with the really hacky support), then use mkvmerge to turn that into an mkv. Admittedly, I wrote a video filter that implements the same thing you are doing before I realized this. I had the video filter write the time code of each frame to a text file as it passed through, which is a bit cleaner than adding another separate command line option. If you're curious, I've attached my patch here as well. It's against an older version of mplayer, but it should only have trivial merge problems, from changes to the list of video filters. Usage is "-vf timecode=filename.txt" I generally used it in combination with the raw video output (which drops all null frames), piped into the 'h264' command line encoder.
Generally speaking, those who already know about making variable frame rate anime will already know what to do.
I know what you mean, some of the DVDs I have switch switch between 24fps progressive, 30fps telecined, 30fps progressive, 30fps interlaced several times within just the first few minutes of the opening...
I realise mencoder has lots of issues and is considered broken at the moment, but there are many of us who depend on it as it fills a niche nothing else does.
I also realise that I have not studied the code style of mplayer/mencoder extensively and have probably committed numerous sins in the way I've hacked this up. Thus I don't expect the code to be committed. However, I offer it as a demonstration piece and of interest since it has been incredibly useful to me, dealing with variable frame rate mkv, mp4, 120fps avi, wmv.
Cheers, and thanks for mplayer.
Patch attached.
-- Calvin Walton <calvin.walton@gmail.com>
On Mon, 18 Feb 2008 12:47:04 Calvin Walton wrote:
On Mon, 2008-02-18 at 11:06 +1100, Con Kolivas wrote:
Hi all
I had a need to generate variable frame rate avi files and timecode stamps for muxing into other containers (specifically .mkv) and hacked in a -makevfr option into mencoder. There are only a handful of really awful unmaintained windows apps that manage these currently.
What this does is it generates an avi output file without any null frames, which is pretty much unusable by itself, but it also generates a timecodes version2 file (timecodes.txt). The resulting avi file and timecodes file can then be muxed into a true variable frame rate container such as mkv using mkvtoolnix.
So what this is useful for, is the various pseudo variable frame rate videos out there such as wmv (which imitates 1000fps) and the so called 120fps ntsc video captures. These are usually a blend of various combinations of 24000/1001, 30000/1001 and 60000/1001 videos. No fixed frame rate ever creates smooth video from them.
From my testing, mkvmerge can handle a 120fps avi file as input just fine, outputting an mkv with the correct timecodes, so you shouldn't really need this hack.
For my encoding currently, I use mencoder to encode directly to h264 120fps avi (with b-frames even, with the really hacky support), then use mkvmerge to turn that into an mkv.
Admittedly, I wrote a video filter that implements the same thing you are doing before I realized this. I had the video filter write the time code of each frame to a text file as it passed through, which is a bit cleaner than adding another separate command line option.
If you're curious, I've attached my patch here as well. It's against an older version of mplayer, but it should only have trivial merge problems, from changes to the list of video filters.
Usage is "-vf timecode=filename.txt"
I generally used it in combination with the raw video output (which drops all null frames), piped into the 'h264' command line encoder.
Generally speaking, those who already know about making variable frame rate anime will already know what to do.
I know what you mean, some of the DVDs I have switch switch between 24fps progressive, 30fps telecined, 30fps progressive, 30fps interlaced several times within just the first few minutes of the opening...
I realise mencoder has lots of issues and is considered broken at the moment, but there are many of us who depend on it as it fills a niche nothing else does.
I also realise that I have not studied the code style of mplayer/mencoder extensively and have probably committed numerous sins in the way I've hacked this up. Thus I don't expect the code to be committed. However, I offer it as a demonstration piece and of interest since it has been incredibly useful to me, dealing with variable frame rate mkv, mp4, 120fps avi, wmv.
Cheers, and thanks for mplayer.
Patch attached.
Sounds great, but I still need the null-frame-less avi stream to work with in the intermediate stage to do hard subs and so on. Also it allows me to deconstruct mkv, mp4 and wmv into this format for that intermediate use while generating the timecodes I need for the final phase. Yes I do use softsubs for the final phase as well, but hardsubs are required for certain things, and wmv and other sources are impossible to manipulate in this way. It just happens to combine and streamline the steps for me that you describe above (with raw output etc). I kind of got sick of piping things all over the place for different encoders etc :P Anyway as I said, I found it useful (as have a few friends) so I was just making the code available. I doubt the maintainers want this merged, so I've made the patch available for download here for those who want it: http://ck.kolivas.org/apps/mplayer/vfr.patch -- -ck
participants (2)
-
Calvin Walton -
Con Kolivas