Log in

View Full Version : Framerate Problem with MKV-H.264


kalorx
22nd October 2006, 20:24
Hi all. It seems that when I mux H.264 video into an MKV container, every tool I have with the ability to read framerates displays a slightly different framerate than I know the video to be.

For example, I mux a 23.976 H.264 video into an MKV. Mkvinfo.exe and MediaInfo both return a framerate of something like "23.906" or "23.97" or "23.966" or "23.957", etc.

This problem doesn't seem to arise with other codecs.

I can't just extract the raw H.264 video from the MKV and check its framerate, because I have no idea how to check raw video for a framerate. Plus, I can't just mux extracted video from the MKV into another MP4, because I have to manually set the fps and that destroys the whole purpose of the test.

I'm rather perplexed. Any help would be greatly appreciated.

PS: I'd just use MP4 as a format instead of MKV, but I have some problems I'm just about to cover in an MP4 container thread...

nm
22nd October 2006, 20:42
How exactly did you mux the video to the Matroska container?

kalorx
22nd October 2006, 21:08
With MKVmerge; MKVtoolnix. Latest version as of the date of this thread.

foxyshadis
22nd October 2006, 21:21
MediaInfo always gives me correct framerates (not including vfr, which throws a spanner in the works). There's a couple headers in the mkv file, known as Timecode Scale (per file) and DefaultDuration (per track), which are the framerate ratio. You can access them with mkvverify if you want to calculate manually.

Other tools, know knows, maybe they use something like dividing the number of frames by total length, or something even goofier.

kalorx
22nd October 2006, 21:43
MKVverify and MKVinfo more or less give me the same information.

The TimeScale of the video is 1,000,000, while the video DefaultDuration is 41,725,983 and the audio DefaultDuration is 42,666,666. MediaInfo and MKVinfo report a framerate of 23.966, while I know the framerate is really 23.976; it was so before I muxed it into an MKV.

The audio and video are perfectly synced (as far as I can tell) during playback with MPC. I don't know how to do the calculations of which you speak.

foxyshadis
22nd October 2006, 22:12
TimeScale/DefaultDuration * 1000 = framerate. Which really does come out to 23.965... in your case, so if you didn't mux with any timecodes, the original must've been off a bit. It's possible the avisynth did something to it. It's possible to force a framerate by remuxing it with a timecode file:


# timecode format v1
Assume 23.976


The DefaultDuration should normally be approximately 41,708,333.

bond
22nd October 2006, 22:37
was the source mp4 vfr?

kalorx
23rd October 2006, 00:37
TimeScale/DefaultDuration * 1000 = framerate. Which really does come out to 23.965... in your case, so if you didn't mux with any timecodes, the original must've been off a bit. It's possible the avisynth did something to it. It's possible to force a framerate by remuxing it with a timecode file:

That's really odd. The output MP4 created by MeGUI reads a 23.976 fps in MediaInfo. The fps seems to only get screwed up when I mux it into an MKV.

And what is a timecode file? How do I create one? How do I use one? What program uses it? I've been doing searches, and it seems everyone talks about them, but no one says how to make one. I can't find any information anywhere.

was the source mp4 vfr?

I don't know what you're asking me. VFR? Do you mean variable framerate? I should think not. I certainly didn't flip any switches anywhere to ask it to do that. I deinterlaced using TDeint and then decimated the 29.97 source fps into 23.976 using DeComb.

GodofaGap
23rd October 2006, 10:10
And what is a timecode file? How do I create one? How do I use one? What program uses it? I've been doing searches, and it seems everyone talks about them, but no one says how to make one. I can't find any information anywhere.

foxyshadis just gave you an example. Read his post. You can use it with mkvmerge/mmg.

I deinterlaced using TDeint and then decimated the 29.97 source fps into 23.976 using DeComb.
This does not make any sense really. Either you deinterlace, or you do a IVTC and use a deinterlacer afterwards for pattern mismatches (so first use decomb and *then* tdeint)

kalorx
23rd October 2006, 11:18
foxyshadis just gave you an example. Read his post. You can use it with mkvmerge/mmg.

But... what on Earth do I do with that code? Do I put it in a text file? Where do I put the text file? Is it automatically read? I see no options in MKVmergeGUI to load a timecode file, etc, etc, etc. The path may seem like it should be obvious to me, but it's not.

This does not make any sense really. Either you deinterlace, or you do a IVTC and use a deinterlacer afterwards for pattern mismatches (so first use decomb and *then* tdeint)

I've actually done a lot of experiments and found my method to work quite well. I've found that for both interlaced and telecined sources, TDeint (mode=2, all other settings default) produces smoother playback than DeComb. I've found this to be the case just about all the time. (You tend to discover these things when you watch, fully, more than one two-hour film at only 2 fps.)

However, it's not perfect. Every once in a while a frame or two won't deinterlace correctly and will leave a ghost or two. The problem, I've found, is always 100% solved by using DeComb on those frames instead of TDeint. After those few frames pass, I go back to using TDeint.

It works the other way around, too. I could use DeComb all the time, and sometimes a few frames won't detelecine correctly, and I just use TDeint on them and it always solves the problem. However, as I previously stated, I default to TDeint because it never fails to produce smoother playback.

Either way, I use DeComb to decimate the video to 23.976 fps, because otherwise every fifth frame is "frozen". It's hard to notice in full-speed playback, but it is noticeable nonetheless.

GodofaGap
23rd October 2006, 12:26
Yes you put it in a txt file.

Look for the red circled area in the following pic to find where to load it.
http://images6.theimagehosting.com/mmgtimecode.th.png (http://server6.theimagehosting.com/image.php?img=mmgtimecode.png)

kalorx
23rd October 2006, 14:17
Oh cool. How did I miss that? It worked. MediaInfo reports 23.976 on the MKV. That'll come in handy...

Still, though. I wonder why the timecode has to be used in the first place.

kalorx
23rd October 2006, 15:03
Oh, for... :scared:

Just to see what would happen, I decided to extract the video from my newly-corrected MKV files and mux them into MP4 files, being careful to manually enter the fps so the framerate wouldn't come out at 25.

Now the framerates for the MP4s are all screwed up! No matter what I manually enter, MediaInfo reads the framerates as always .002 off, plus or minus. I checked to see if there was some kind of pattern, but there wasn't. Remuxing the MP4s doesn't work, either.

I wish I'd left some MKVs unmodified by timecodes to see if that's the culprit here.

EDIT: Turns out only some of the MP4s have suffered this fate. Can't think of any reason why or why not they would, though.

bond
23rd October 2006, 19:06
i can only imagine that mkvmerge has a problem handling 64bit mp4 timestamps

run mp4dump over your source mp4 file and post it here to see if your file has such timestamps

kalorx
23rd October 2006, 23:09
Here's the dump text:

http://www.progressivedementia.net/mp4dump.txt

This isn't from the "source" MP4 file per se, because there is no source MP4 file; only a source MKV file. I ran the dump on the MP4 with the screwy framerate not knowing what else to do.

bond
23rd October 2006, 23:17
so you encoded directly to mkv?

kalorx
23rd October 2006, 23:36
Oh. Now I see what you're saying. No, I encoded it directly to MP4. But I deleted that file a long time ago, at about the same time I decided I wanted the video to be MKV instead. Now I want them to be MP4s, and I really, really don't want to have to do all that video editing again and recompress the file just because the thing isn't converting to MP4 correctly.

EDIT: I have compressed another video, and this time the source MP4 seems to have the wrong framerate. The source MP4 was created by MeGUI, and the source video is 23.976. I manually enter 23.976 and remux all I want, but it alway comes out 23.977. I can mux it to an MKV with timecode to 23.976, but turning it back into an MP4 returns it to 23.977, manual input of fps or not.

The video might just be too short for MediaInfo to make a good estimate. It's only 2 seconds long... but length shouldn't matter, should it? (Ah, the question of the ages...)

bond
24th October 2006, 22:18
might be a rounding error

actually if you encoded to mp4 with x264cli with an older version of avisynth (read: not one of the latest alpha versions) it might be that the mp4 file used 64bit timestamps and mkvmerge might have a problem with that. i am pretty sure that the mp4 files created by x264 are correct

mp4 files created with mencoder are borked. mp4 files created with ffmpeg should be ok

you maybe want to contact mosu the dev of mkvmerge

kalorx
24th October 2006, 23:04
I think you misunderstood me -- or I was not clear (or I'm misunderstanding you): the MP4 created by MeGUI has the wrong framerate (23.977), even though I double-checked and made sure the input was 23.976. Even if I remux to a new MP4 it using Yamb, manually entering 23.976, the new MP4 still comes out as 23.977 in MediaInfo.

Versions I'm using:

MeGUI 0.2.3.2177
Yamb 1.6
MP4Box 0.4.3
x264 CLI-r58
MediaInfo 0.7.3.1

bond
28th October 2006, 12:54
might be a rounding error

run mp4dump over the mp4 file and post the result or run mp4info over it and check the fps reported

MeteorRain
28th October 2006, 13:03
try extract the timecode from the mkv and convert it into v1 format and you got the exact fps

bond
28th October 2006, 13:04
moved