Split MKV based on Chapters

split mkv video by chapters using mkvmerge

mkvmerge -o output.mkv --split chapters:all input.mkv

https://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge.html


I can't find a reliable way to do this with ffmpeg / avconv - but I can find a way to do this with HandBrakeCLI.

 HandBrakeCLI -c 3 -i whatever.mkv -o 3.mkv

Will extract chapter 3 from an mkv.


brute force solution, hehe:

ffmpeg -i long.mkv | grep 'start.*end.*[0-9]*' | sed -r 's/.*#[0-9]\.([0-9]*).* ([0-9]*\.[0-9]*).*( [0-9]*\.[0-9]*)/ ffmpeg -i long.mkv -ss \2 -to\3 -acodec copy -vcodec copy chapter\1.mkv/g;'

You can add xargs to run the output in cowboy style: | xargs -I cmd bash -c 'cmd'