Wrong Chapter Timing

Please post here for issues related to Blu-ray discs
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Wrong Chapter Timing

Post by Dazkine »

Hi there i got a Problem with MMKV:

I created a mkv from a Bluray Disk with MMKV

MakeMKV (MediaInfo):

Menu
00:00:00.000 : en:Chapter 01
00:08:33.596 : en:Chapter 02
00:16:05.005 : en:Chapter 03
00:24:15.579 : en:Chapter 04
00:30:25.198 : en:Chapter 05
00:39:30.242 : en:Chapter 06
00:47:11.119 : en:Chapter 07
00:56:10.408 : en:Chapter 08
01:06:49.505 : en:Chapter 09
01:14:25.461 : en:Chapter 10
01:21:43.773 : en:Chapter 11
01:30:33.136 : en:Chapter 12


But when i use ChapterGen the Timings are (extracted from Bluray):

ChapterGen:

00:00:00.000
00:08:33.805
00:16:05.298
00:24:15.954
00:30:25.490
00:39:30.368
00:47:11.495
00:56:10.576
01:06:49.505
01:14:25.461
01:21:43.774
01:30:33.428
01:38:55.138


When i use VLC for playback and go to next chapter there are often a few frames which belong to the scene of the previous chapter.
With PowerDVD and the .mkv-file its the same (Original Bluray the timings are correct). So its seems that ChapterGen timings are right and the MakeMKV timings are a little bit too early.

Tested with two different machines. I use the current MakeMKV Version, but the problem occurs also on previous Releases.

edit:

ChapterGrabber:

00:00:00.000
00:08:33.804
00:16:05.297
00:24:15.954
00:30:25.490
00:39:30.368
00:47:11.495
00:56:10.575
01:06:49.505
01:14:25.461
01:21:43.773
01:30:33.428
mike admin
Posts: 4065
Joined: Wed Nov 26, 2008 2:26 am
Contact:

Re: Wrong Chapter Timing

Post by mike admin »

This is tricky. MakeMKV adjust chapter times so the chapter always points to a start of a GOP (I-frame). This is a requirement of MKV file, but it could produce artifacts you describe. Also, some players won't handle chapters that point to a middle of GOP correctly. It looks like VLC can handle the chapters properly. Can you play back the MKV file if you change chapter times in MKV chapter editor?
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

Well i tested something else:

I used MPC+ffdshow with OSD and "Current frame"

There is an I Frame where the original Chapter marker is set, but MMKV set the chapter marker one GOP earlier.

The GOP Sequence is:

...I(1) B P B P P I(2) I B ...

Original chapter marker is at 2, but MMKV chooses position 1.

It's Chapter 04. Some Chapters are fine but not all of them.
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

Is it possible to implement an option to disable this chapters at I-frames thingy? I generally only rip my disks so I can re-encode them using AVISynth and X264, I have a program that extracts the chapter info using MKVExtract and creates a qp file to feed to X264 which places I-Frames at the chapter markers, and it's a pain in the arse having to correct EVERY MKV, EVERY TIME so that the chapters markers match scene changes, rather than the now non-existent I-frames.
mike admin
Posts: 4065
Joined: Wed Nov 26, 2008 2:26 am
Contact:

Re: Wrong Chapter Timing

Post by mike admin »

ndjamena wrote:Is it possible to implement an option to disable this chapters at I-frames thingy?
Yes, that seems to be a right thing to do. Request noted, but I can't promise the timeframe though.
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

mh but why does MMKV set the Chapters sometimes one GOP too early?

On Bluray the Chapterpoints are already at the right position. I guess the Bluray Authoring Software keeps care of that.

So i dont really understand why some Chapterpoints (not all) are one GOP (I-Frame) too early.

Is there any software to correct the Chapterpoints without (re)mux ?

At the moment i use MPC to find the next I Frame but thats a lot of work. Is there a better way to find I-Frames ?
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

I use AVIDEMUX, it has buttons to skip to the next and previous key frames. The only problems I've found is AVIDEMUX doesn't seem to like MKVs and I need to remux the video to .ts first and sometimes it doesn't show the proper frame type (although it still seeks properly). I've never used MPC, maybe AVIDEMUX is better. (MKV chapter points seem to be one frame earlier than AVIDEMUX time-codes so make sure you find the correct frame and then move BACK ONE FRAME and use that time code.)

This is all a pain in the arse. I haven't ripped many DVDs recently but my pet peeve is the multitude of TV episodes I've found where the first chapters has started at 80ms, using AVIDEMUX I've found that the cause is that the video starts with 2 b-frames and MakeMKV has set the 1st chapter to point to the next I-frame. Whenever I play an MKV in VLC, press "Next Chapter" and it skips to the previous chapter I know EXACTLY what's causing it, and I remember I haven't run the files through THIS:

Code: Select all

$TargetDirectory="F:\Videos\MKV\Iron Man- Armored Adventures\Season 02"

function Remove-Tags
{
    param([string]$XMLLine)
    $XMLLine.Remove($XMLLine.LastIndexOf('<')).Remove(0, $XMLLine.IndexOf('>')+1)
}

function Get-Times
{
    param([string]$XMLLine)
    $BaseTime=Remove-Tags $XMLLine
    ([int64]$BaseTime.Remove($BaseTime.IndexOf(':'))*3600000000000) + ([int64]$BaseTime.Remove($BaseTime.LastIndexOf(':')).Remove(0, $BaseTime.IndexOf(':')+1)*60000000000) + ([int64]$BaseTime.Remove($BaseTime.IndexOf('.')).Remove(0, $BaseTime.LastIndexOf(':')+1)*1000000000) + ([int64]$BaseTime.Remove(0, $BaseTime.IndexOf('.') + 1))
}

function Get_Track
{
    param([string]$InfoLine = "File Blank")
    $InfoLine.Remove($InfoLine.IndexOf(' '))
}

function Get_Field
{
    param([string]$InfoLine = "File Blank")
    $Get_Field_Temp=$InfoLine.Remove(0,$InfoLine.IndexOf(' ') + 1)
    if ($Get_Field_Temp.IndexOf(' ') -ge 0)
    {
        $Get_Field_Temp=$Get_Field_Temp.Remove($Get_Field_Temp.IndexOf(' '))
    }
    $Get_Field_Temp
}

function Get_Data
{
    param([string]$InfoLine = "File Blank")
    $Get_Data_Temp=$InfoLine.Remove(0,$InfoLine.IndexOf(' ') + 1)
    if ($Get_Data_Temp.IndexOf(' ') -ge 0)
    {
        $Get_Data_Temp.Remove(0,$Get_Data_Temp.IndexOf(' ') + 1)
    } else {
        ""
    }
}

function Get_SourceInfo
{
    param([string]$Get_Info_Track = "File", [string]$Get_Info_Field = "Duration")
    for ($Get_Info_Count=0; $Get_Info_Count -lt $MediaInfo.Length; $Get_Info_Count++)
    {
        $Get_Info_Temp_Track = Get_Track $MediaInfo[$Get_Info_Count]
        $Get_Info_Temp_Field = Get_Field $MediaInfo[$Get_Info_Count]
        if (($Get_Info_Temp_Track -eq $Get_Info_Track) -and ($Get_Info_Temp_Field -eq $Get_Info_Field))
        {
            Get_Data $MediaInfo[$Get_Info_Count]
            break
        }
    }
}

cls

Get-ChildItem -Path $TargetDirectory -Filter *.mkv | foreach-object -process {
    "Prepping; " + $_.BaseName
    $FullName=$_.FullName
    $FileName=$_.BaseName
    $FileNameEx=$_.BaseName + $_.Extension
    $FilePath=$_.DirectoryName
    #$FilePath='D:\Source'

    $MediaInfo=MyMediaBatch "$FilePath\$FileNameEx"
    $TimeCode = (Get_SourceInfo "File" "TimeCode") + '000000'
    $ChapterCount = (Get_SourceInfo "File" "Chapters") -as [int]
    #$TimeCode
    #$ChapterCount 

    #$MediaInfo

    $NewChapters=@()
    
    if ($ChapterCount -lt 1)
    {
        $NewChapters=$NewChapters+'<?xml version="1.0"?>'
        $Newchapters=$NewChapters+'<!-- <!DOCTYPE Chapters SYSTEM "matroskachapters.dtd"> -->'
        $Newchapters=$NewChapters+'<Chapters>'
        $Newchapters=$NewChapters+'  <EditionEntry>'
        $Newchapters=$NewChapters+'    <EditionFlagHidden>0</EditionFlagHidden>'
        $Newchapters=$NewChapters+'    <EditionFlagDefault>0</EditionFlagDefault>'
        $Work_Var=[uint64](Get-Random -Maximum 18446744073709551615 -Minimum 1)
        $Work_Var='    <EditionUID>' + $Work_Var + '</EditionUID>'
        $Newchapters=$NewChapters+$Work_Var
        $Newchapters=$NewChapters+'    <ChapterAtom>'
        $Newchapters=$NewChapters+'      <ChapterDisplay>'
        $Newchapters=$NewChapters+'        <ChapterString>Chapter 00</ChapterString>'
        $Newchapters=$NewChapters+'        <ChapterLanguage>eng</ChapterLanguage>'
        $Newchapters=$NewChapters+'      </ChapterDisplay>'
        $Work_Var=[uint64](Get-Random -Maximum 18446744073709551615 -Minimum 1)
        $Work_Var='      <ChapterUID>'+$Work_Var+'</ChapterUID>'
        $Newchapters=$NewChapters+$Work_Var
        $Newchapters=$NewChapters+'      <ChapterTimeStart>00:00:00.000000000</ChapterTimeStart>'
        $Work_Var='      <ChapterTimeEnd>' + $TimeCode + '</ChapterTimeEnd>'
        $Newchapters=$NewChapters+$Work_Var
        $Newchapters=$NewChapters+'      <ChapterFlagHidden>0</ChapterFlagHidden>'
        $Newchapters=$NewChapters+'      <ChapterFlagEnabled>1</ChapterFlagEnabled>'
        $Newchapters=$NewChapters+'    </ChapterAtom>'
        $Newchapters=$NewChapters+'  </EditionEntry>'
        $Newchapters=$NewChapters+'</Chapters>'
    }
    else
    {
        $ChapterList=MKVEXTRACT chapters $FullName
        $StartTime=0
        $EndTime=0

        $ChapterCount=0

        $ChapterDelete=@()
        $DeleteCount=0

        $LastStartTime=0

        $FirstChapter=$true
    
        for ($LinePOS=0; $LinePOS -lt $ChapterList.length; $LinePOS++)
        {
            if ($ChapterList[$LinePOS].Contains("<ChapterTimeEnd>"))
            {
                $EndTime=Get-Times $ChapterList[$LinePOS]
            }
            if ($ChapterList[$LinePOS].Contains("<ChapterTimeStart>"))
            {
                if ($FirstChapter)
                {
                    $ChapterList[$LinePOS]=$ChapterList[$LinePOS].Replace((Remove-Tags $ChapterList[$LinePOS]), "00:00:00.000000000")
                    $FirstChapter=$false
                }
                $NewTime=Get-Times $ChapterList[$LinePOS]
                if (($NewTime-$StartTime) -gt 4000000000)
                {
                    $StartTime=$NewTime
                }
            }
            if ($ChapterList[$LinePOS].Contains("</ChapterAtom>"))
            {
                if (($EndTime-$StartTime) -le 4000000000)
                {
                    if ($StartTime -eq 0)
                    {
                        "Deleting Chapter: " + [string]($ChapterCount+2)
                        $ChapterDelete=$ChapterDelete + $ChapterCount + 1
                        $DeleteCount++
                    }
                    else
                    {
                        if ($ChapterDelete[$DeleteCount - 1] -ne $ChapterCount)
                        {
                            "Deleting Chapter: " + [string]($ChapterCount+1)
                            $ChapterDelete=$ChapterDelete + $ChapterCount
                            $DeleteCount++
                        }
                    }
                }
                $ChapterCount++
            }
        }
        $LastChapter = $ChapterCount
        $ChapterDelete=$ChapterDelete + 1024

        $ChapterCount=0
        $DeleteCount=0

        for ($LinePOS=0; $LinePOS -lt $ChapterList.length; $LinePOS++)
        {
            if ($ChapterCount -ne $ChapterDelete[$DeleteCount])
            {
                $NewChapters=$NewChapters+$ChapterList[$LinePOS]
            }
            if ($ChapterList[$LinePOS].Contains("<ChapterTimeStart>"))
            {
                if ($ChapterDelete[$DeleteCount] -eq $ChapterCount)
                {
                    $DeleteCount++
                }
                $ChapterCount++
            }
        }
        for ($LinePOS=$NewChapters.Length - 1; $LinePOS -ge 0; $LinePOS--)
        {
            if ($NewChapters[$LinePOS].Contains("<ChapterTimeEnd>"))
            {
                $NewChapters[$LinePOS] = $NewChapters[$LinePOS].Replace((Remove-Tags $NewChapters[$LinePOS]), $TimeCode)
                break
            }
        }
    }
    $XMLFile="Z:\Work\" + $FileName + ".xml"
    Out-File -FilePath $XMLFile -Encoding utf8 -InputObject $NewChapters
    #$NewChapters
    MKVPropEdit -c "$XMLFile" "$FilePath\$FileNameEx"

    Remove-Item $XMLFile

}
Yet.

--Edit: an open gop isn't what I thought it was...
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

I Frame = new gop begins
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

Yeah, I read about GOPs early on and never thought to revise my assumptions... B-Frames in an open gop can reference the next gop, but some of the diagrams make it look like the b-frames come BEFORE the i-Frame.

And yes, the original chapter info in my Iron Man episodes must have been off.

Still learning here :P .
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

mh is there anybody else who discovered the same problems i have with chapterpoints?
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

Well, one thing I noticed while using AVIDEMUX is that sometimes the ts and MKV timecodes are 1ms off. I believe it's caused by the fact that MKV can not in fact handle NTSC /1001 given the way it deals with divisors and MKV NTSC files are therefor the equivalent of variable frame rate to keep sync. I believe most players have a "close enough" view of MKV frame-rates and just ignore it. If MakeMKV decides chapter positions based on the original time-code rather than which frame it was referring to I'm sure that would mess with the chapters.

And as for VLC I HAVE noticed that if I move a chapter point to the middle of a gop it will begin playing one or two frames BEFORE where I set it, whereas if I set it at an I-frame it always starts at the right place. I try to set chapters on Source Video I-frames, I can only manage that if the black-screen cuts are long enough, otherwise I have no choice but to set chapters in the middle of GOPs.

Mike is right, this is tricky.


If there's a chapter marker in the middle of a GOP do you want to move it backwards or forwards? (it would be nice if MakeMKV could detect Blackscreens to help it decide)
Do the original Time-codes include over-extended Audio streams in a component M2TS that MakeMKV has removed for audio sync?
Were the original time-codes in the right place to begin with?

Keep pumping out info and Mike might think of something.
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

If there's a chapter marker in the middle of a GOP do you want to move it backwards or forwards?
The GOP Sequence is:

...I(1) B P B P P I(2) I B ...

Original chapter marker is at 2, but MMKV chooses position 1.
well i think that doesn't happen because the Bluray Authoring Software keeps care of that. The movie i was talking about has already a chapterpoint at an I-Frame. So i dont know why MMKV doesnt set the Chapterpoint here.

In MMKV the chapters have the timeformat H:MM:SS not ms. Does MMKV just hide ms?

If MMKV just calculates with seconds and not with ms it could be caused by rounding errors.

Like i said, its not always one GOP too early just sometimes.
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

ndjamena wrote:Well, one thing I noticed while using AVIDEMUX is that sometimes the ts and MKV timecodes are 1ms off. I believe it's caused by the fact that MKV can not in fact handle NTSC /1001 given the way it deals with divisors and MKV NTSC files are therefor the equivalent of variable frame rate to keep sync. I believe most players have a "close enough" view of MKV frame-rates and just ignore it. If MakeMKV decides chapter positions based on the original time-code rather than which frame it was referring to I'm sure that would mess with the chapters.

If there's a chapter marker in the middle of a GOP do you want to move it backwards or forwards?

ChapterGen: ChapterGrabber:

00:00:00.000 00:00:00.000
00:08:33.805 00:08:33.804
00:16:05.298 00:16:05.297
00:24:15.954 00:24:15.954
00:30:25.490 00:30:25.490
00:39:30.368 00:39:30.368
00:47:11.495 00:47:11.495
00:56:10.576 00:56:10.575
01:06:49.505 01:06:49.505
01:14:25.461 01:14:25.461
01:21:43.774 01:21:43.773
01:30:33.428 01:30:33.428
01:38:55.138

Well, your MKV timings have certainly moved backwards. Only mike can tell us for sure but I believe the point is, that if MakeMKV decides the chapter marker is a millisecond BEFORE where IT thinks the I-frame is it, it's technically in the middle of a GOP and MakeMKV MIGHT move the chapter marker to the previous I-frame.
Dazkine
Posts: 83
Joined: Wed Apr 09, 2014 9:52 am

Re: Wrong Chapter Timing

Post by Dazkine »

maybe. I would like to disable this automatic and just use the chaptertimings from my Disks.
ndjamena
Posts: 830
Joined: Mon Jan 07, 2013 12:23 am

Re: Wrong Chapter Timing

Post by ndjamena »

Ah, I realised something while I was wandering the shops this afternoon. I had it all backwards. Some of my Iron Man: Armored Adventures episodes had one second of the previous episode attached to the END, which mean I'm in the same boat as you. MakeMKV is putting some of the chapters ONE GOP earlier than it really ought to be. I'd consider that a bug that should be fixed (although I'd rather be able to split titles by M2TS, maybe that would be easier than by chapters). By the way, I'm pretty sure the majority (all) of my DVD chapters are slightly ahead of where they ought to be, are DVD and Blu ray chapters handled differently or were the DVD chapters already pointing to an I-frame on the disc?


[My thoughts are rather jumbled but I get there in the end]
Post Reply