Here is the (Windows) perl script that i use to pull all the chapters from a mkv file.
I like to use MakeMKV to pull
everything from the source and then process them one at a time.
#!c:/perl/bin/perl
# file: bluerayextract1.plx
# purpose: take a directory of MakeMKV bluray rips, pull out each chapter and create a list of the streams
# date: 20 December 2017
# auth: k.monte
[email protected]
# comments: automation from the notes Chris provided to pull the flac from bluray
# use: it is perl and open source/free software, use it and share it.
#-------------------------------------------------------------------------------------------------------------------
#
# required perl modules
#
#-------------------------------------------------------------------------------------------------------------------
# none, this is all about the software and using perl to loop and process it with system calls.
#-------------------------------------------------------------------------------------------------------------------
#
# static variable declaration
#
#-------------------------------------------------------------------------------------------------------------------
$Counter = "0";
#-------------------------------------------------------------------------------------------------------------------
#
# main section
#
#-------------------------------------------------------------------------------------------------------------------
#
# Split the makeMKV created MKV files by chapter
#
#-------------------------------------------------------------------------------------------------------------------
# mkvmerge -o ${OUTPUT} --split "chapters:all" ${SOURCE}
# Incremental numbers will be appended to the ${OUTPUT} filename.
# example: mkvmerge -o windogs.mkv --split "chapters:all" The_Winery_Dogs_t00.mkv
# notes
# if only the makeMKV files are in the directory this glob works, otherwise it needs more specificity
#-------------------------------------------------------------------------------------------------------------------
@BaseFiles = glob ("*.mkv");
foreach $BaseFile (@BaseFiles) {
$BaseOut = "chapter" . $Counter . ".mkv";
system ("mkvmerge -o $BaseOut --split \"chapters:all\" $BaseFile");
$Counter++
}
#-------------------------------------------------------------------------------------------------------------------
#
# Review audio streams
#
#-------------------------------------------------------------------------------------------------------------------
# ffmpeg -i ${SOURCE} 2>&1 |grep ' Stream'
# example: ffmpeg -i windogs.mkv 2>&1 |grep ' Stream'
# sample output
# Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc
# Stream #0:1(eng): Audio: dts (DTS-HD MA), 48000 Hz, 5.1(side), s32p (24 bit) (default)
# Stream #0:2(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s
# Stream #0:3(eng): Audio: dts (DTS-HD MA), 48000 Hz, stereo, s32p (24 bit)
# Stream #0:4(eng): Audio: dts (DTS), 48000 Hz, stereo, fltp, 1536 kb/s
# notes
# this stanza will create a Streams.txt file which has each files stream list in it.
# you will need the contents to manually modify bluerayextract2.plx for the streams you want
#-------------------------------------------------------------------------------------------------------------------
@ChapterFiles = glob ("chapter*001.mkv");
open(my $Stream_out_fh, '>', 'Streams.txt');
foreach $ChapterFile (@ChapterFiles) {
system ("ffmpeg -i $ChapterFile 2>TempFile");
open my $Streams_fh, 'TempFile' or die $!;
my @Streams = grep { / Stream/ } <$Streams_fh>;
print $Stream_out_fh "$ChapterFile\n";
foreach $i(@Streams){
print $Stream_out_fh "$i";
}
}
close $Streams_fh;
close $Stream_out_fh;
unlink <"TempFile">;
#-------------------------------------------------------------------------------------------------------------------
#
__END__