Feature Request - File Split by Chapter

Everything related to MakeMKV
Message
Author
booknut
Posts: 4
Joined: Sat Nov 28, 2009 6:56 am

Feature Request - File Split by Chapter

#1 Post by booknut » Sat Nov 28, 2009 7:09 am

First, let me give a big thanks for such a great product. I have tried the Windows version and used it extensively for digitizing my tv show collection. It is very handy for that. I will soon try the linux version as well (on Ubuntu 9.04 "Jaunty").

With my collection of TV shows well in hand, I have begun to think about other areas. One that would greatly increase the WAF of my system would be to digitize our music video dvds. Here too I would like to create a seperate file for each music video, but alas, the problem being that most music video dvds are created with a single title having seperate chapters for each video. I have been able to rip these seperate chapters as VOB, but the process of converting to MKV has proven a bit tedious with multiple steps and programs being called. I don't have time for this and was hoping that this might be made an option in MakeMKV.

The only other thing I would add is that an option be made to automatically select all english (or prefrred language) audio and subtitle tracks and deselecting all other language tracks.

Thanks again, let me go check if there is a donate link.

Mnemos
Posts: 24
Joined: Sun Feb 14, 2010 2:36 am

Re: Feature Request - File Split by Chapter

#2 Post by Mnemos » Sun Feb 14, 2010 2:44 am

I second this. The one feature that MakeMKV is lacking which makes it so that I have to use DVDFab to rip tracks from the DVD/BD before using MakeMKV is the fact that it always rips the whole title. I have quite a few discs from TV shows where all of the episodes are in one track, and I'm looking to be able to have each of them as separate mkv files.

If MakeMKV gave the ability to select a range of chapters from a title when ripping a title, it would be worth a lot to me. It would make it so that I would no longer need DVDFab (which is painfully expensive - especially since you have to pay separately for each type of disc and what kind of ripping you want to do with it).

MakeMKV is a great find, but being able to choose a range of chapters from a title rather than being forced to rip the whole title would make it a lot better.

tony55
Posts: 55
Joined: Fri Feb 05, 2010 6:42 pm

Re: Feature Request - File Split by Chapter

#3 Post by tony55 » Wed Feb 17, 2010 4:52 pm

For BR rips this would be a great feature since as far as I'm aware there is no HD program that performs this function.

To split out any of my BRs by chapter, I use TSDoctor or TSSNIPER. They are video editors without automatic features. tsMuxer will also do some chapter seperations. They will also split out each chapter. Then you have to put them back together including just the one you want.

There are so many DVD programs that do the chapter select process but so far nothing for BR that I could find.

Tony

Wasabi
Posts: 56
Joined: Mon Aug 17, 2009 11:09 pm

Re: Feature Request - File Split by Chapter

#4 Post by Wasabi » Sat Mar 20, 2010 1:49 am

I think this would be a great idea!

For now, though...If you load the MKV into MKVMerge, you can import the chapter list and cut and paste the chapter stops into the "split by" section of MKVMerge.

If you're a complete newbie to MKVMerge here's a simple step-by-step method:

1) Open the MKV in MKVMerge
2) Under the Chapter Editor menu item, choose Load, then choose the same MKV that you just opened - it will now take a few seconds to import the chapters.
3) Under the Global tab, check Enable Splitting and ...after timecodes.
4) Under the Chapter Editor tab, highlight Chapter 01 and select the long timecode from the start box below (you can skip the Chapter 00 that is all zeroes)
5) Click on the Global tab and paste this timecode into the ...after timecodes box, then add a comma
6) repeat 4 & 5 with each successive chapter
7) click Start Muxing

It's a little tedious, and I usually paste all the timecodes into Notepad first because the box under the Global tab fills up quickly and it makes it a bit tricky to paste properly.

lowflow
Posts: 9
Joined: Thu Mar 04, 2010 9:57 pm

Re: Feature Request - File Split by Chapter

#5 Post by lowflow » Tue Apr 06, 2010 2:20 am

HUGE thanks to Wasabi for this tip and for the step by step instructions.

:D

tony55
Posts: 55
Joined: Fri Feb 05, 2010 6:42 pm

Re: Feature Request - File Split by Chapter

#6 Post by tony55 » Tue Apr 06, 2010 3:41 pm

I also didn't know that even though I've used merge before.

Nice to know.
Tony

nclisby
Posts: 1
Joined: Tue Apr 13, 2010 11:12 am

Re: Feature Request - File Split by Chapter

#7 Post by nclisby » Tue Apr 13, 2010 11:18 am

I just want to add my thanks to Wasabi. As a newbie at manipulating mkv files I was finding it hard to track down how to do this, and the clear instructions in Wasabi's post helped a lot.

Wasabi
Posts: 56
Joined: Mon Aug 17, 2009 11:09 pm

Re: Feature Request - File Split by Chapter

#8 Post by Wasabi » Sat May 29, 2010 3:50 am

I've slapped something together in Visual Basic to automate this tedious chore. I'm sure my code would be laughed at by actual programmers (see code block below), but it works. I assume you will need the latest Microsoft .NET framework for this to work. I've tested it on Windows 7 & XP and it works fine.

If you have VB installed, you can compile it yourself, or download it from here: http://www.megaupload.com/?d=JTN6XLGT

The first time it's run, it will ask you for the folder that contains mkvmerge.exe & mkvextract.exe and write that location to a file called mkvchaps.ini. You choose an MKV and it will display the chapter breaks. Click SPLIT and it will run a command prompt with the appropriate command line for mkvmerge.exe. By default, mkvmerge.exe makes filenames called split-001.mkv, etc. You can change the prefix from "split" to something else in the box at the bottom.

That's it. It can't extract just one chapter or do anything else exciting.

Get mkvmerge.exe & mkvextract.exe as part of the MKVToolNix package here: http://www.bunkus.org/videotools/mkvtoo ... ml#windows


DISCLAIMER: Downloader is on his own. It works for me. If it sets your cat on fire or makes you sterile, I'm not liable. Check the download with your virus checker or whatever.

Code: Select all

Imports System.Xml
Imports System.IO
Imports System.Text

Public Class Form1

    Dim ini As String = "mkvchaps.ini"
    Dim folderName, result, path, splitname As String
    Dim chapters As String
    Dim cnt As Integer



    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        Me.Show()

        If File.Exists(ini) Then
            Dim t As New StreamReader(ini)
            folderName = t.ReadLine()

            CheckExists()

        Else
            CreateINI()
        End If

    End Sub
    Public Sub CheckExists()
        If My.Computer.FileSystem.FileExists(folderName & "\mkvmerge.exe") And My.Computer.FileSystem.FileExists(folderName & "\mkvextract.exe") Then

        Else
            MsgBox("MKVMerge & MKVExtract not found")
            CreateINI()
        End If
    End Sub

    Public Sub CreateINI()
        Dim fileOBJ As System.IO.FileStream
        Dim openFileDialog1 As New OpenFileDialog()
        Dim foldr As New FolderBrowserDialog


        foldr.Description = "Choose folder containing MKVmerge and MKV extract"


        Dim result As DialogResult = foldr.ShowDialog()

        folderName = foldr.SelectedPath
        File.Delete(ini)
        fileOBJ = File.Create(ini)
        Dim objReader As New StreamWriter(fileOBJ)
        objReader.WriteLine(folderName)
        objReader.Close()

        CheckExists()
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim openFileDialog1 As New OpenFileDialog()
        Dim temp As String


        openFileDialog1.Filter = "MKV files (*.mkv)|*.mkv"
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

            ListBox1.Items.Clear()
            cnt = 0
            result = openFileDialog1.FileName

            temp = "chapters " & Chr(34) & result & Chr(34)

            Dim startinfo1 As New ProcessStartInfo(folderName & "\mkvextract.exe")


            Dim p1 As New Process

            startinfo1.WindowStyle = ProcessWindowStyle.Hidden
            startinfo1.Arguments = temp
            startinfo1.UseShellExecute = False
            startinfo1.CreateNoWindow = True
            startinfo1.RedirectStandardOutput = True
            p1.StartInfo = startinfo1
            p1.Start()


            Dim SR As StreamReader = p1.StandardOutput

            path = IO.Path.GetDirectoryName(result)

            Dim STempFileName = System.IO.Path.GetTempFileName()

            Dim t As New StreamWriter(STempFileName)
            t.Write(SR.ReadToEnd)
            t.Close()
            p1.WaitForExit()
            SR.Close()


            Dim reader As XmlTextReader = New XmlTextReader(STempFileName)



            TextBox1.Text = result
            TextBox2.Text = "split"

            If FileLen(STempFileName) > 0 Then
                chapters = ""
                Do While (reader.Read())
                    Select Case reader.NodeType
                        Case XmlNodeType.Element
                            If reader.Name = "ChapterTimeStart" Then
                                reader.Read()
                                cnt += 1
                                ListBox1.Items.Add("CHAPTER " & Format(cnt, "000") & ": " & reader.Value)
                                If reader.Value <> "00:00:00.000000000" Then
                                    chapters = chapters & reader.Value & ","
                                End If

                            End If
                    End Select
                Loop
                Button2.Visible = True
                TextBox3.Visible = True
                TextBox2.Visible = True
                reader.Close()
            Else
                Button2.Visible = False
                TextBox3.Visible = False
                TextBox2.Visible = False
                ListBox1.Items.Add("no chapters found")
            End If

            File.Delete(STempFileName)
        End If

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim startinfo1 As New ProcessStartInfo(folderName & "\mkvextract.exe")
        Dim temp As String

        startinfo1 = New ProcessStartInfo(folderName & "\mkvmerge.exe")

        temp = Mid(chapters, 1, Len(chapters) - 1)

        temp = "--split timecodes:" & temp & " " & Chr(34) & result & Chr(34) & " -o " & Chr(34) & path & "\" & TextBox2.Text & ".mkv" & Chr(34)

        Dim P1 As New Process
        'startinfo1.WindowStyle = ProcessWindowStyle.Hidden
        startinfo1.Arguments = temp
        startinfo1.UseShellExecute = False
        '        startinfo1.CreateNoWindow = True
        '       startinfo1.RedirectStandardOutput = True
        p1.StartInfo = startinfo1
        P1.Start()
        P1.WaitForExit()


    End Sub

End Class

Qriist
Posts: 5
Joined: Sat Feb 20, 2010 10:13 pm

Re: Feature Request - File Split by Chapter

#9 Post by Qriist » Sun May 30, 2010 6:49 pm

Well this is interesting, two people developing a nearly identical tool at the same time. Great minds?

Anyways, this is written as the precursor to something completely different but I figured I'd share this with you guys.
http://qriist.livedrive.com/frameset.ph ... s/16673485

It is rough and has no GUI....but then again nothing I make does. Basically, you put your files in the "input" folder and it will create a folder in the output based on your original filename. Finished files and files with nothing to do (no chapters) will be moved to "Output Source." There are a number of different .exe files with a different angle on the same thing. These are:
Chapter Split.exe = Same thing as chopping your file into chapter points, nothing fancy
Chapter Split-all.exe = Splits video, audio, subtitles in to own separate chopped containers
Chapter Split-aud.exe = Extracts only split audio
Chapter Split-aud+sub.exe = Extracts only split audio AND subtiltes
Chapter Split-sub.exe = Extracts only split subtitles
Chapter Split-vid.exe = Extracts only split video

Finally, each file run will generate its own "run.bat" with verbosity enabled, so if you are having trouble you can see if there is a problem with your video or with the program proper. These are generated anew with each running of the given program, so it is always relevant to the task at hand.

Source code for the basic Chapter Split program, the others are identical minus tweaks regarding filenames and what to include. All source code is included in the download.

Code: Select all

SetBatchLines,-1
FileDelete,%a_scriptdir%\Run.bat
Loop, %a_scriptdir%\input\*.mkv
{
	Runwait,%a_scriptdir%\tools\mkvextract.exe -r "%a_loopfilelongpath%.chapterfile_xml" chapters "%a_scriptdir%\input\%a_loopfilename%",,min
	CurrentFileXML_size=0
	FileGetSize,CurrentFileXML_size,%a_loopfilelongpath%.chapterfile_xml
	If CurrentFileXML_size=0
	{
		FileDelete,%a_loopfilelongpath%.chapterfile_xml
		FileMove,%a_loopfilelongpath%,%a_scriptdir%\output source
		Continue
	}
	SplitPath,a_loopfilename,,,,FILE
	FileRead,ChapterFileXML,%a_loopfilelongpath%.chapterfile_xml
	Loop,parse,ChapterFileXML,`n
	{
		IfInString,a_loopfield,`<ChapterTimeStart`>00:00:00.000000000`<`/ChapterTimeStart`>
			Continue
		IfInString,a_loopfield,`<ChapterTimeStart`>
		{
			timecode=
			StringReplace,TimeCode,a_loopfield,`<ChapterTimeStart`>	
			StringReplace,TimeCode,TimeCode,`<`/ChapterTimeStart`>
			StringReplace,TimeCode,TimeCode,`n,,all
			StringReplace,TimeCode,TimeCode,`r,,all
			TimeCodeList=%TimeCodeList%
			TimeCodeList=%TimeCodeList% %TimeCode%
		}
	}
	TimeCodeList=%TimeCodeList%
	StringReplace,TimeCodeList,TimeCodeList,%a_space%,`,,all
	Loop
	{
		IfInString,timecodelist,`,`,
			StringReplace,TimeCodeList,TimeCodeList,`,`,,`,,all
		IfNotInString,timecodelist,`,`,
			Break
	}
	RunWait,%a_scriptdir%\tools\mkvmerge.exe -o "%a_scriptdir%\output\%file%\%a_loopfilename%" --no-chapters "%a_loopfilelongpath%" --split timecodes:%TimeCodeList%,,min
	FileAppend,"%a_scriptdir%\tools\mkvmerge.exe" -o "%a_scriptdir%\output\%file%\%a_loopfilename%" --no-chapters "%a_loopfilelongpath%" --split timecodes:%TimeCodeList% -v`n,run.bat
	timecodelist=
	FileCreateDir,%a_scriptdir%\output\%file%\
	FileMove,%a_loopfilelongpath%,%a_scriptdir%\output source\,1
	FileMove,%a_loopfilelongpath%.chapterfile_xml,%a_scriptdir%\output\%file%\%A_LoopFileName%.xml,1
}

tomtomtom
Posts: 1
Joined: Fri Oct 15, 2010 2:39 pm

Re: Feature Request - File Split by Chapter

#10 Post by tomtomtom » Fri Oct 15, 2010 2:58 pm

I second this request. I tried makemkv and it really works fine on my iMac. The only thing I'm missing is to rip all my Music BD to the single titles.
I'm aware that this is not the primary objective of this tool because I guess most people use it for ripping movies but on the other hand I don't think spliting the output to different files at the chapter borders is not a big deal at all.
So maybe we can get this feature in a future version because all the workarounds in this topic are a lot of work (and not platform independent) compared to a hopefully small change in your software.

Thomas

elain1
Posts: 1
Joined: Fri Oct 14, 2011 10:07 am

Re: Feature Request - File Split by Chapter

#11 Post by elain1 » Fri Oct 14, 2011 10:14 am

Also would like to see this feature in MakeMKV, but until that I wrote a little script to do it for me.

Code: Select all

#!/bin/sh
file=$1
timecodes=`mkvextract chapters -s "${file}"|grep "CHAPTER[0-9][0-9]="|sed '1,1d;:a;N;$!ba;s/CHAPTER[0-9][0-9]\=//g;s/\n/,/g'`
mkvmerge --split timecodes:"${timecodes}" "${file}" -o "%02d_${file}"

jjnvdm
Posts: 5
Joined: Sat Sep 03, 2011 4:56 pm

Re: Feature Request - File Split by Chapter

#12 Post by jjnvdm » Thu Dec 29, 2011 12:21 pm

I second for the feature to split by chapter when extracting to MKV. This is the one of the most useful features when I copy music DVDs and TV series DVDs. At the moment I do this manually and it is extremely tedious.

boe_d
Posts: 91
Joined: Sun Feb 05, 2012 5:58 pm

Re: Feature Request - File Split by Chapter

#13 Post by boe_d » Tue Feb 07, 2012 4:22 am

Make MKV is great but it would be nice if it can't convert the chapters from the source media if you could set a time that you want it to auto create chapters - e.g. every 5 minutes.

electroglyph
Posts: 5
Joined: Fri Oct 19, 2012 3:34 am

Re: Feature Request - File Split by Chapter

#14 Post by electroglyph » Sun Oct 21, 2012 6:48 am

Great suggestion, keeping with the trend of posting splitting scripts, here's one I just made in PowerShell format. First script I've made, but it works.
This will split every MKV found in the current directory. mkvmerge and mkvextract must be in the current directory or located in system path.

Code: Select all

$first = $TRUE;
$timecode = "";
$fileEntries = [IO.Directory]::GetFiles($(get-location),"*.mkv"); 
foreach($fileName in $fileEntries) 
{ 
	mkvextract chapters $fileName -s > temp.txt
	$lines = [IO.File]::ReadAllLines("temp.txt");
	foreach ($line in $lines) {
		if ($line.Contains("=")) {
			$split = $line.Split("=");
			if ($split[0].Contains("NAME")) {
				continue;
			}
			if (!$split[1].CompareTo("00:00:00.000")) {
				continue;
			}
			if ($first) {
				$timecode = $split[1];
				$first = $FALSE;
			}
			else {
			$timecode += "," + $split[1];
			}
		}
	}
	$bareFileName = [IO.Path]::GetFileNameWithoutExtension($fileName);
	mkvmerge --split timecodes:$timecode $fileName -o $bareFileName-%02d.mkv
	Remove-Item temp.txt
}
Write-Host "Press any key to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

fryk.
Posts: 35
Joined: Tue Oct 09, 2012 7:57 am

Re: Feature Request - File Split by Chapter

#15 Post by fryk. » Tue Oct 23, 2012 7:41 am

MKV split by chapters
Here is a little batch script for the windows command processor. Copy the code in your text editor and save it as 'SplitMKV.CMD' in your MKVToolNix program folder. The script can handle up to 400 chapters in a single MKV file (XP or better). It will search & find all the chapters, and split the MKV file on every chapter time mark. Usage: 'SplitMKV MyVideo.MKV'.

Code: Select all

@echo off &setlocal EnableDelayedExpansion

set source=%~1
set destination=output\%~nx1

if not exist output\ mkdir output

for /f "usebackq tokens=4" %%i in (`mkvinfo --ui-language en "%source%" ^| findstr /i /c:"ChapterTimeStart: "`) do (
  if defined timecodes set timecodes=!timecodes!,
  set timecodes=!timecodes!%%i
)

mkvmerge -o "%destination%" --split timecodes:%timecodes% "%source%"

endlocal

Post Reply