Feature Request - File Split by Chapter

Everything related to MakeMKV
knobbi
Posts: 16
Joined: Mon Nov 08, 2010 2:18 am

Re: Feature Request - File Split by Chapter

Post by knobbi » Fri Aug 22, 2014 3:37 am

elain1 wrote: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}"

Hi Elain,

I made some patches to your script ;)

Code: Select all

#!/bin/bash

SCRIPT=`basename "$0"`
MKVEXTRACT=`which mkvextract`
MKVMERGE=`which mkvmerge`

outdir="./"
series=00

if [ "$1" == "" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
    echo "$SCRIPT: Give MKV to chapter-split as an argument, optionally an output dir, and optionally series number"
    echo "$SCRIPT: e.g.:  ripped_season_03.mkv ./ 3"
    echo "$SCRIPT: e.g.:  ripped_music_videos.mkv ~/Music_Clips/"
    exit 1
fi

if [ ! -f "$1" ]; then
    echo "$SCRIPT: MKV file not found [$1]"
    exit 1
fi    

if [ "$2" != "" ]; then
   outdir="$2"
   if [ ! -d "$outdir" ] || [ ! -x "$outdir" ] || [ ! -w "$outdir" ]; then
       echo "$SCRIPT: The output directory has a problem ($outdir)"
       echo "$SCRIPT: Not existing, not writable, not a dir, etc."
       exit 1
   fi
fi

if [ "$3" != "" ]; then
    series="$3"

    ### Check it's 2 digits, or make it so
    if [ ${#series} -gt 2 ]; then
        series=`echo $series | cut -b 1-2`
    elif [ ${#series} -lt 2 ]; then
        series="0$series"
    fi

    echo "$SCRIPT: Series number is [$series]"
fi    

if [ "$MKVEXTRACT" == "" ] || [ ! -x "$MKVEXTRACT" ]; then
    echo "$SCRIPT: 'mkvextract' seems to be missing"
    echo "Is MKVToolsNix Installed?"
    echo "sudo apt-get install mkvtoolsnix"
    exit 2
fi    

if [ "$MKVMERGE" == "" ] || [ ! -x "$MKVMERGE" ]; then
    echo "$SCRIPT: 'mkvmerge' seems to be missing"
    echo "Is MKVToolsNix Installed?"
    echo "sudo apt-get install mkvtoolsnix"
    exit 2
fi    

infile="$1"
timecodes=`"$MKVEXTRACT" chapters -s "${infile}"|grep "CHAPTER[0-9][0-9]="|sed '1,1d;:a;N;$!ba;s/CHAPTER[0-9][0-9]\=//g;s/\n/,/g'`

if [ "$series" == "00" ]; then
    # no series number
    "$MKVMERGE" --split timecodes:"${timecodes}" "${infile}" -o "${outdir}/${infile%.mkv}_%02d.mkv"
else    
    "$MKVMERGE" --split timecodes:"${timecodes}" "${infile}" -o "${outdir}/${infile%.mkv} S${series}E%02d.mkv"
fi


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

Re: Feature Request - File Split by Chapter

Post by fryk. » Thu Aug 28, 2014 2:57 pm

Mosu enhanced the --split function of mkvmerge by a chapter option.
Splitting before specific chapters.

Syntax: --split chapters:all or --split chapters:A[,B[,C...]]

Example: --split chapters:5,8

The parameters A, B, C etc must all be positive integers. Numbering starts at 1. The list of chapter numbers is separated by commas. Splitting will occur right before the first key frame whose timecode is equal to or bigger than the start timecode for the chapters whose numbers are listed. A chapter starting at 0s is never considered for splitting and discarded silently.

The keyword all can be used instead of listing all chapter numbers manually.

The 'chapters:' prefix must not be omitted.
https://www.bunkus.org/videotools/mkvto ... merge.html

DanielCoffey
Posts: 6
Joined: Thu Nov 13, 2014 6:45 pm

Re: Feature Request - File Split by Chapter

Post by DanielCoffey » Sun Jan 11, 2015 1:53 pm

Brilliant - just what I needed, thanks.

I used "mkvmerge -o ShallWeDancesplit.mkv --split chapters:2 ShallWeDance.mkv" and ended up with two files... ShallWeDancesplit-001.mkv which was that annoying 90 second intro and ShallWeDancesplit-002.mkv which was the rest of the movie in one piece.

mike admin
Posts: 3581
Joined: Wed Nov 26, 2008 2:26 am
Contact:

Re: Feature Request - File Split by Chapter

Post by mike admin » Tue Jan 13, 2015 11:36 am

By the way, now you can split any DVD title by chapters in any order with a so-called Manual DVD mode - /manualdvd/

Knocks
Posts: 10
Joined: Wed Jan 21, 2015 12:58 pm

Re: Feature Request - File Split by Chapter

Post by Knocks » Fri Jan 23, 2015 4:05 pm

Tried the new feature, and it's a lot more difficult than running one of the scripts provided by posters above.

Since MakeMKV is a program with a very intuitive and simple GUI, it makes no sense to learn complicated commands just to split a DVD by chapters. It'd be much easier to check a box in the GUI somewhere.

Music video and cartoon compilation DVDs are very common, so this is a much needed feature.

jcwillia1
Posts: 24
Joined: Wed Dec 24, 2014 11:27 pm

Re: Feature Request - File Split by Chapter

Post by jcwillia1 » Sat Mar 21, 2015 12:34 am

fryk. wrote: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

dude this was killer - thank you!

Post Reply