VideoHelp Forum
+ Reply to Thread
Results 1 to 20 of 20
Thread
  1. Hi guys,
    I am working on a Matroska file I want to convert to PAL DVD (details here) but I am having some troubles with framerate.
    MediaInfo seems to output a wrong value (23.220fps), GSpot outputs no value at all, DGAVCIndex says it's 25fps but the 25fps M2V transcoded video is not synchronized with the audio.
    The only thing I could think of was to take the number of frames and divide it by the original lenght (in seconds), I got 23.998 fps.
    Since this problem may come again in the future my question is:
    generally speaking, is there a way/piece of software to positively check the framerate of Matroska files?
    Quote Quote  
  2. only way to get an exact average frame rate, extract the time codes and calculate the frame rate from the time codes

    side note: mediainfo isn't always right about whether a stream is vfr or cfr since it only looks at the first few time codes to determine if the stream is vfr or cfr.

    If your stream has a frame rate of '23.22fps' there usually is either something wrong with it or the stream is vfr.
    Quote Quote  
  3. Thanks for replying.
    only way to get an exact average frame rate, extract the time codes and calculate the frame rate from the time codes
    And I do that how?
    Quote Quote  
  4. mkvextract can be used to extract the time codes.
    Timecode extraction:
    The sixth mode finds the timecodes of all blocks for a track and outputs a
    timecode v2 file with these timecodes.
    source: mkvextract help
    the rest is simple math,...
    don't know a tool that does the whole thing for you, but it's not hard to write assuming you know a programming language.
    Quote Quote  
  5. Thank you, I'll give it a look as soon as I have the time.
    As for your... assuming, you'd better don't.
    Quote Quote  
  6. Mod Neophyte Super Moderator redwudz's Avatar
    Join Date: Sep 2002
    Location: AZ, USA
    Search Comp PM
    Gspot doesn't work well with MKV, and I'm not surprised MediaInfo has problems with correctly reading VFR video. Most times it just says 'variable'. But since you tried 25 FPS, try 23.976 FPS. Most likely alternative.


    I use ConvertXtoDVD most times for MKV>DVD conversion. As an experiment, I just tried to convert a MKV video that shows as variable framerate to a PAL DVD format. It took about 12 minutes on my PC. 190 fps conversion rate for the 1.5 hr video. It looks good quality to me, close in quality to the MKV video version that is about 800 MB. The audio, which was CBR AC3, was perfectly in sync throughout the DVD movie.
    Quote Quote  
  7. Thanks to you too for the info.
    Quote Quote  
  8. batch expert Endoro's Avatar
    Join Date: Dec 2013
    Location: Bozen
    Search PM
    Counting the frames is a good idea. You can do this with mkvinfo.
    If your mkv is muxed with simple blocks (default):
    Code:
    mkvinfo -v "video.mkv" |find /c "SimpleBlock (track number 1, 1 frame"
    and without simple blocks (mkvmerge --engage no_simpleblocks):
    Code:
    mkvinfo -v "video.mkv" |find /c "Block (track number 1, 1 frame"
    Output is (in my tests) the number of frames in the video track #1.
    Now you can compare this with mediainfo and calculate the frame rate for cfr tracks.

    The time codes method is also nice:
    Code:
    mkvextract timecodes_v2 "video.mkv" 0:tcodes.txt
    awk "{n++}; END {print n,\"frames,\",$1/1000,\"sec,\",n/$1*1000,\"fps\"}" tcodes.txt
    Output is number of frames, duration of the video in sec., and fps.

    And if you need to know all different frame durations:
    Code:
    awk "{f2=f1;f1=$1;if (NR>2) a[f1-f2]++}; END {printf(\"%8s %10s\", \"duration\",\"frames\n\");for (i in a) printf(\"%5s ms %9s \n\",i,a[i])}" tcodes.txt
    Please note, mkvinfo starts counting the tracks with "1", mkvextract with "0".
    I used awk from the GnuWin32 project.
    Last edited by Endoro; 23rd Dec 2013 at 16:03. Reason: Update.
    Quote Quote  
  9. Thanks to you too.
    Problem is that I am not familiar with MKV files or MKVtoolnix.
    But thanks for the precious help that you guys are giving me.
    I'll see what I can get out of it asap.
    Quote Quote  
  10. Member leghorn's Avatar
    Join Date: Apr 2007
    Location: Germany
    Search Comp PM
    Maybe you could post the Mediainfo log? Anyhow, I guess 23.220 fps is VFR...
    Das Leben ist eine Nebelwand voller Rasierklingen. (C. Bukowski)
    Quote Quote  
  11. Here it is:
    General
    Format : Matroska
    Format version : Version 1
    File size : 3.08 GiB
    Duration : 2h 44mn
    Overall bit rate : 2 687 Kbps
    Writing application : mkvmerge v2.2.0 ('Turn It On Again') built on Mar 4 2008 13:20:25
    Writing library : libebml v0.7.7 + libmatroska v0.8.1

    Video
    ID : 1
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L3.1
    Format settings, CABAC : Yes
    Format settings, ReFrames : 4 frames
    Codec ID : V_MPEG4/ISO/AVC
    Duration : 2h 44mn
    Bit rate : 2 300 Kbps
    Width : 1 280 pixels
    Height : 544 pixels
    Display aspect ratio : 2.35:1
    Frame rate mode : Constant
    Frame rate : 23.220 fps
    Color space : YUV
    Chroma subsampling : 4:2:0
    Bit depth : 8 bits
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.142
    Stream size : 2.58 GiB (84%)
    Writing library : x264 core 112
    Encoding settings : cabac=1 / ref=4 / deblock=1:0:0 / analyse=0x3:0x113 / me=umh / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=240 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=2pass / mbtree=1 / bitrate=2300 / ratetol=1.0 / qcomp=0.60 / qpmin=3 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:1.00
    Default : Yes
    Forced : No
    Color primaries : BT.709
    Transfer characteristics : BT.709
    Matrix coefficients : BT.709

    Audio
    ID : 2
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Format settings, Endianness : Big
    Codec ID : A_AC3
    Duration : 2h 44mn
    Bit rate mode : Constant
    Bit rate : 384 Kbps
    Channel(s) : 6 channels
    Channel positions : Front: L C R, Side: L R, LFE
    Sampling rate : 48.0 KHz
    Bit depth : 16 bits
    Compression mode : Lossy
    Stream size : 451 MiB (14%)
    Default : Yes
    Forced : No
    It looks like Constant Frame Rate.
    Quote Quote  
  12. aBigMeanie aedipuss's Avatar
    Join Date: Oct 2005
    Location: 666th portal
    Search Comp PM
    wow all this wasted time over a crappy encode. just start over and rip it again from the source. you do have the source right? this isn't about some numbskull's warez rip.
    --
    "a lot of people are better dead" - prisoner KSC2-303
    Quote Quote  
  13. Not that this is much of a help, but thanks anyway for the suggestion.
    Quote Quote  
  14. MKVCleaver is probably the easiest way to extract MKV timecodes (it requires MKVToolnix be installed to work). Open the MKV, select both the video track and timecodes in the right pane. Use the Settings menu at the top to make sure it's set to "Timecodes/Timecodes Only", then click on extract. The video timecodes will be extracted to a text file.

    If the video is constant frame rate 25fps, the timecodes should consistently be 40ms apart, so it'll look like this:

    # timecode format v2
    0
    40
    80
    120
    160
    200
    240
    280
    320


    If the video is constant frame rate 23.976fps, I'm pretty sure the timecodes should alternate between 42 and 41ms in some sort of repeating pattern (although I can't remember the exact pattern). Like this:

    # timecode format v2
    0
    42
    83
    125
    167
    209
    250
    292
    334
    375
    417
    459
    501

    If you're using a program for viewing text files which tells you the number of lines in the text file, you should be able to get the frame count just by checking which line number the final entry falls on. Subtract 2 from that, to account for the initial "# timecode format v2" entry, and the last entry which I'm pretty sure isn't a new frame.
    For example, here's the last few entries from a timecodes file.

    Name:  Clipboard01.gif
Views: 141
Size:  2.6 KB

    The last entry is on line 166151. Subtract two and the video contains 166149 frames.
    Just to be certain, I indexed that MKV with ffmsindex and checked the frame count in MeGUI's preview. It agreed on the total number of frames.
    Last edited by hello_hello; 25th Dec 2013 at 14:57.
    Quote Quote  
  15. One thing you might want to try.....
    Open the MKV with MKVMergeGUI. Select the video track and under the "format specific options" tab specify a frame rate. ie 23.976 or 25fps.... whatever you think it should be. Click on Start Muxing to output a new MKV. It should have a constant frame rate using the frame rate you specified.

    If you do the above and save a new MKV while specifying 23.976 and then again specifying 25fps, does the audio stay in sync for either? If it doesn't stay in sync for either then you've probably eliminated the possibility of the original MKV having a constant 23.976 or 25fps frame rate.
    Quote Quote  
  16. Thanks hello_hello.

    I seem to have solved the problem on this specific file.
    Anyway I made some tests, just to understand a little more (for the future).

    I first tried the method suggested by selur but I must have made some mistake 'cause I wasn't able to get an output.
    Then I went for Endoro's (timecodes) and I got the file I enclose as "test_01".
    I don't know why the last line has that strange value, but according to the number of lines, the frame number matches the one I had found on my own.
    I made another test with MKVcleaver and I got a completely different output ("test_02").
    Attached Files
    Quote Quote  
  17. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    It's vfr . You can use a timecodes v2 to v1 converter to see more easily what is happening . v1 is easier to read for humans

    Basically it's speeding up & slowing down in sections . VFR usually means frames are missing from the video (e.g. duplicate frames, dropped on purpose for coding efficiency purposes), so the display time for each frame in that section is longer(fps is lower) , thus the running time is the same compared to the CFR version

    v1 timecodes are read like this: It goes start frame, end frame, frame rate . The 1st "assume" line means that frame rate is assumed unless other wise specified (29.97 in your example)

    e.g For this example, frames 1-4 have a 18.08fps , 5-109 run at 23.976, etc...
    Code:
    # timecodes format v1
    Assume 29.970
    1,4,18.981
    5,109,23.976
    110,113,18.981
    114,12398,23.976
    12399,12402,18.981
    12403,19343,23.976
    19344,19347,18.981
    19348,54557,23.976
    54558,54561,18.981
    54562,73336,23.976
    73337,73340,18.981
    73341,117375,23.976
    117376,117379,18.981
    117380,117447,23.976
    117448,117451,18.981
    117452,117456,23.976
    117457,117460,18.981
    117461,160279,23.976
    160280,160283,18.981
    160284,160335,23.976
    160336,160339,18.981
    160340,160343,23.976
    160344,160347,18.981
    160348,160357,23.976
    160358,160361,18.981
    160362,163519,23.976
    163520,163523,18.981
    163524,170147,23.976
    170148,170151,18.981
    170152,170802,23.976
    170803,170806,18.981
    170807,171809,23.976
    171810,171813,18.981
    171814,200877,23.976
    200878,200881,18.981
    200882,204152,23.976
    204153,204156,18.981
    204157,206825,23.976
    206826,206829,18.981
    206830,209368,23.976
    209369,209372,18.981
    209373,212323,23.976
    212324,212327,18.981
    212328,236554,23.976
    BTW, A 3rd way to generate v2 timecodes is with ffms2 in avisynth

    FFVideoSource("video.mkv", timecodes="timecodes_v2.txt")



    It looks like the base frame rate of the original, original video was 23.976 (makes sense if this was a theatrical production, film production) . It's only minimally variable in a few small sections if you look at the V1 timecodes. I say this because most sections run at 23.976. Only a few tiny sections run at a different frame rate. A way to approximately (it won't be perfect) insert back those missing frames is with DirectShowSource() and ConvertFPS=true , to convert it back to CFR . Of course going to DVD requires CFR; as DVD-video doesn't support VFR

    e.g

    Code:
    DirectShowSource("video.mkv", fps=23.976, convertfps=true)
    Once you get it back to the base frame rate CFR 23.976. Then you have to decide what method to convert it to PAL (25fps). , and how to get the proper resize, AR, and colors (SD colors with colormatrix). That's for another disucssion - there are several methods with pros/cons - and you can use search , as the options are laid out and explained well in other threads
    Attached Files
    Last edited by poisondeathray; 29th Dec 2013 at 12:33.
    Quote Quote  
  18. @poisondeathray
    thank you very much for the precious help.
    As I wrote here it looks like I solved this thing simply speeding up the audio from 23.220 to 25.
    I tested at several random points and it is synchronized.
    If I can go this way, lucky me.
    But I will find out if this is the case only by watching it on my SAP.
    If, on the contrary, I am not that lucky and I have to go back to work, I'll keep in mind your tips.
    Thank you.
    Quote Quote  
  19. Originally Posted by Instant Martian View Post
    I don't know why the last line has that strange value, but according to the number of lines, the frame number matches the one I had found on my own.
    I made another test with MKVcleaver and I got a completely different output ("test_02").
    I'm not sure what's going on there. I don't have a VFR video handy to play with.
    MKVCleaver does have an option under Settings/VFR Detection which can be enabled or disabled. Maybe that's why. I don't know how it's set by default.
    Quote Quote  
  20. It's ON by default.
    Quote Quote  



Similar Threads