# SUBROUTINES
sub detect_ext {
- my ($ffmpeg_info, $interlaced) = @_;
+ my ($ffmpeg_info, $progressive) = @_;
my $h264 = 0;
my $h264_high = 0;
# Quicktime/MOV
if($h264 && $pcm_s16le) { return "mov"; }
# MTS
- if($h264_high && $ac3) { if($interlaced) { return "mkv"; } else { return "mp4"; } }
+ if($h264_high && $ac3) { if(!$progressive) { return "mkv"; } else { return "mp4"; } }
# 3GP/MP4
- if($h264 && $aac) { if($interlaced) { return "mkv"; } else { return "mp4"; } }
+ if($h264 && $aac) { if(!$progressive) { return "mkv"; } else { return "mp4"; } }
return "UNKNOWN";
}
if($opt_c =~ /all/) { $all_chapters = 1; }
print "-> Extracting the following chapters from $opt_i: @chapters\n";
-my $interlaced = system('ffmpeg -i "$opt_i" 2>&1 | grep -q "frame rate differs"');
-if($interlaced != 0) {
+my $progressive = system('ffmpeg -i "$opt_i" 2>&1 | grep -q "frame rate differs"');
+if(!$progressive) {
print " Detected interlaced video content\n";
} else {
print " Detected progressive video content\n";
# For each chapter specified on the command line, use ffmpeg to extract a video clip from that chapter
my @ffmpeg_info = `$ffmpeg -i $opt_i 2>&1`;
foreach $line (@ffmpeg_info) {
- if($line =~ /Chapter #\d+\.(\d+): start (\S+), end (\S+)/) {
+ if($line =~ /Chapter #\d+\:(\d+): start (\S+), end (\S+)/) {
$chapter = $1;
$start = $2;
if($start > 0) { $start += 1; } # Add some margin to prevent taking a piece of the previous clip
if($all_chapters || &export_chapter(\@chapters,$chapter)) {
$ext = "UNKNOWN";
if(defined $opt_e) { $ext = $opt_e; }
- else { $ext = &detect_ext(\@ffmpeg_info, $interlaced); }
+ else { $ext = &detect_ext(\@ffmpeg_info, $progressive); }
if($ext =~ /UNKNOWN/) { die "-E- Unable to determine the file type/extension to use for the output videos. Specify it with the -e <ext> option.\n"; }
$dstfile = $opt_o . ".c" . sprintf("%03d",$chapter) . "." . $ext;
print "-> Exporting $chapter to $dstfile:\n";
$errno = $errno >> 8;
if($errno > 0) { die "-E- ffmpeg encountered some errors with exit code $errno\n"; }
}
- if($interlaced && $ext =~ /mkv/i) {
+ if(!$progressive && $ext =~ /mkv/i) {
$ext = "mp4";
$srcfile = $dstfile;
$dstfile = $dstfile = $opt_o . ".c" . sprintf("%03d",$chapter) . "." . $ext;