Log in

View Full Version : How to convert a variable framerate MPEG to constant framerate?


TlatoSMD
14th April 2010, 23:43
Okay, I have this one HD-sized MPEG-2 (HD-sized because the tool I had handy captured my whole screen) that I recorded via screengrab of a webstream, and as is usual with webstreams, you don't get realtime playback. My recording tool compensated for that by making the resulting MPEG's framerate variable, ranging between 25fps down to 1 frame every 4 seconds or so. This file plays fine, at variable framerate, in WMP, MPC, VLC, etc, honoring the variable framerate and has the file play at its original speed and length.

However, I also recorded the webstream's audio separately, and if I simply drag this MPEG into any program or convert it to AVI to marry it to the audio, it's interpreted at constant 25fps, which turns 120 minutes into about 17 minutes in varying fast-forward mode.

What I need is a way to transcode or recode this MPEG and force constant 25fps (PAL destination) upon it in a way that the process automatically duplicates frames where there's gaps, with the number of duplicates adding up to the particular gap length. Again, any freeware and particularly MEncoder-based solution would be appreciated.

Guest
14th April 2010, 23:54
MPEG2 video does not support VFR (other than small changes using repeat flags). How can you have an MPEG2 stream specifying 0.25 fps? It's not a legal MPEG-2 frame rate.

Please post a link to an unprocessed sample of the source stream.

TlatoSMD
15th April 2010, 00:01
I'd love to, but I don't even know how to split this thing up without speeding it up as insanely as mentioned above.

The original consists of two files, part 1 and 2, one is roughly 130MB, the other roughly 160MB.

Guest
15th April 2010, 00:03
Use DGSplit to chop off the first 50MBytes and post a link to that.

TlatoSMD
15th April 2010, 00:33
Okay, split it and just tested it in VLC, amazingly the variable framerate was retained. See here: http://www.megaupload.com/?d=X2VWME25

BTW, I only made it a 10MB chunk. With this variable framerate, that's almost 5 minutes of HD-res MPEG-2.

Guest
15th April 2010, 00:59
Well, isn't that cute!

They have a fixed frame rate of 25 fps but then they change the PTS timestamps to vary the playing time of the frames. This relies on the player's ability to sync video to the PTS timestamps. The PTS timestamps are in the program stream overhead. If you demux the video and play that in VLC, it will no longer play correctly.

This is certainly a highly non-standard, if not illegal, stream. No MPEG-2 VBV model is going to work correctly with this.

So, you just want to get this into a standard stream without the PTS silliness. Unfortunately, I do not know of any standard tools to convert this. I would have to write a special AVS source filter to do that. Or one could dump the timestamps and use that to create a (probably too large) AVS script to duplicate the frames as needed.

Maybe such a thing exists and someone else will point it out.

You definitely need a more sensible capture chain. :)

TlatoSMD
15th April 2010, 01:05
Would there be any way to utilize the PTS timestamps during a transcode or recode that would use said PTS to introduce duplicate frames for a standard file output? EDIT: Ah, I see you've adressed that.

And thing is, as you may see towards the bottom of my sample, the stream was from 2008 and is now long gone, no way to recapture this. In fact, it was the only time I ever did anything like this, I just grabbed the next best tool from download.com that promised 25fps capture and never used it again.

Guest
15th April 2010, 01:06
Didn't I already answer that (to the best of my knowledge)?

TlatoSMD
15th April 2010, 01:28
Yes, I've made an edit when I saw you'd addressed that.

GrofLuigi
15th April 2010, 19:44
Try VideoReDo.

I once had a DVD that some 'genius' edited with god-knows-what, that normal DVD decrypting/indexing tools chocked on (the discarded material was still inside, just 'masked out' or something in the IFOs).

Probaby it's not the same as your situation, but I think it's worth a try.

GL

TlatoSMD
16th April 2010, 21:11
Try VideoReDo.

I once had a DVD that some 'genius' edited with god-knows-what, that normal DVD decrypting/indexing tools chocked on (the discarded material was still inside, just 'masked out' or something in the IFOs).

Probaby it's not the same as your situation, but I think it's worth a try.

GL

Well, I've tried VideoReDo now, both TV and Plus version, and even though interestingly enough, it recognizes the variable framerate when playing back the files, it just fails to fix the output, no matter whether I tick the box to fix according to PTS or all the other whatever boxes to whatever else. All it puts out is files that are way too fast.

Stephen R. Savage
16th April 2010, 21:38
Try this:

DirectShowSource("Eop_01.mpg", fps=25, convertfps=true, framecount=200000, seek=false)

Change framecount to some number that makes the clip about the right length. After you do this, dump this to a lossless file. Once that's done, you can apply whatever filters you like to the lossless clip, encode, and mux the audio back in.

As far as I can tell, MS MPEG-2 Splitter + ffdshow gets the timestamps right.

TlatoSMD
16th April 2010, 21:41
Try this:

DirectShowSource("Eop_01.mpg", fps=25, convertfps=true, framecount=200000, seek=false)

Change framecount to some number that makes the clip about the right length. After you do this, dump this to a lossless file, find the real end of the clip, and then transcode and mux your audio.

"About the right length"? Do you mean I should check how long the file plays when it plays at the right speed, then insert the number of how many frames that'd be at 25fps?

TlatoSMD
16th April 2010, 23:18
Oh wow. I just dabbled around a bit on videohelp.com and downloaded some tools promising "MPEG fixing", and the very first one I tried out of a whim, PVAStrumento, did the trick noiselessly.

I just clicked "scan", it gave me a detailled log with every frame visible for longer than it should, frame-accurately reporting its effective length each, then I clicked "make PS" (= "Program Stream")...

...and nothing happened. :confused: I checked my output folder in Windows Explorer, and now it suddenly contained 5 new files, the log as a txt, two AVIs, and two WAVs. :eek: Except for the log, their creation dates (back in 2008) are identical to the original MPEGs which I have on a way other HDD to begin with! I guess back then I didn't even own this HDD yet where I've output these files to.

I opened them in VDub, and there it was! Constant 25fps, AND DUPLICATE FRAMES WHENEVER NECESSARY! More than 1.5 GB, created in a matter of seconds.

VDub is telling me they're DivX 3 MPEG-4 files at thousand-something kbps (while MPC identifies them as MP4s in AVI containers, rather). The WAVs are unplayable, which is not surprising because the original MPEGs are silent to begin with.

TlatoSMD
12th September 2012, 01:40
UPDATE after 2 years:

I've found out that the current version of VDub works pretty well with non-standard PTS timestamps in MPEG. All you have to do now is set the framerate to "change so video and audio duration match". What that does in case of non-standard PTS timestamps is a.) VDub will slow down the framerate to what's necessary to make audio and video match, and b.) then read the PTS timestamps and insert frame duplicates (or, in rare cases, remove frames) wherever necessary. If need be, also use the box right below to convert to the standard framerate that you want it at for PAL or NTSC.

You'll get lotsa drop frames, but if you're working with ugly non-standard PTS timestamps they're already in the original file, and all this is about is to preserve perfect A/V synchronicity of the original file even beyond the original MPEG container in case you wanna process the video in some form or another.

Emulgator
13th September 2012, 18:21
TlatoSMD, what software did you use back then to make the VFR screengrabs ?

poisondeathray
13th September 2012, 21:45
TlatoSMD, what software did you use back then to make the VFR screengrabs ?

I don't know if this will help you , but ffmpegsource2 will list CFR and VFR times (overlaid) if you use ffinfo() . So you can seek to whatever VFR time you want then take a screenshot in something like vdub or avspmod