# mkvtoolnix - http://www.bunkus.org/videotools/mkvtoolnix/
# ffmpeg
-###########################
+####################################################################################################
# Includes
use File::Copy;
use File::Basename;
use DateTime::Duration;
use DateTime::Format::Duration;
-###########################
-# Configuration parameters
+####################################################################################################
+# Configuration parameters - CHANGE THESE TO SUITE YOUR NEEDS
my $mkvmerge=`which mkvmerge`; chomp($mkvmerge);
my $ffmpeg=`which ffmpeg`; chomp($ffmpeg);
my $tmpfile = `tempfile`; chomp($tmpfile);
my $chapter_file = $tmpfile;
my $input_file_options = "-S";
my $output_file_options = "--chapters $chapter_file";
+####################################################################################################
-###########################
-# Options
+
+####################################################################################################
+# Command Line Options
getopts("st:o:i:h");
if(! -x $mkvmerge) { die "-E- Unable to find required program: mkvmerge\n"; }
return 1;
}
-###########################
+####################################################################################################
# Helper Subroutines
sub epoch_to_date {
my ($epoch) = @_;
return sprintf("%4d",$mtime->year)."-".sprintf("%02d",$mtime->month)."-".sprintf("%02d",$mtime->day)." ".$mtime->hms;
}
-###########################
+####################################################################################################
# MAIN
# Turn the list of input videos into a hash with a value equal to the modification time in epoch seconds
print CHAPTERS "CHAPTER".sprintf("%02d",$chapter_num)."=".$start_time."\n";
print CHAPTERS "CHAPTER".sprintf("%02d",$chapter_num)."NAME=".$mdate."\n";
my $dt = DateTime::Duration->new(years => 1900, hours => $hour, minutes => $min, seconds => $sec);
- my $prev_dt = DateTime::Duration->new(years => 1900, hours => $prev_hour, minutes => $prev_min, seconds => $prev_sec);
- $new_duration = $dt + $prev_dt;
- $prev_hour = $hour; $prev_min = $min; $prev_sec = $sec;
+ $new_duration = $dt + $new_duration;
}
close(CHAPTERS);
print "\n-> Creating the following chapter file for this video:\n";
if($errno > 1) { die "-E- mkvmerge encountered some errors with exit code $errno\n"; }
}
-# Remove the temporary file
+# Remove the temporary file used for the chapter generation
if(-e "$tmpfile") { unlink "$tmpfile"; }
-###########################
+####################################################################################################