X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=make_mkv;h=04556e523fca95ddf1c500130cb2fdd4c31f7a49;hb=9580365135dbaa7c89e0e30f097c566e9a3a6650;hp=bfbaa11600041bd7c1636ffa020ae8f302f23f46;hpb=4c6323fdb10bcf8e8417676c9d867a853dd47be1;p=videoscripts%2F.git diff --git a/make_mkv b/make_mkv index bfbaa11..04556e5 100755 --- a/make_mkv +++ b/make_mkv @@ -23,7 +23,7 @@ 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"; +my $output_file_options = "--chapters $chapter_file --compression -1:none"; my $timezone = `cat /etc/timezone`; chomp($timezone); #################################################################################################### @@ -106,8 +106,44 @@ print "$chapter_file_contents\n"; print "-> Creating the MKV video file '$opt_o'\n"; my $cmd = "$mkvmerge --title \"$opt_t\" $output_file_options -o \"$opt_o\""; + +# Make our input file command line options for all the videos my $video_count = 0; +my @video_tmp_files; foreach my $video (sort{$videos{$a} <=> $videos{$b}} keys %videos) { + # Detect if the input file is interlaced or not. + # There is a bug in mkvmerge 5.0.1 and earlier where if the video content is 1080i, it doesn't mux it properly, and it stutters. + # The quick solution to this issue is to run the interlaced video file through ffmpeg and tell it to copy the video/audio streams to a mkv container. + # We will then merge this temporarily created mkv container into the final mkv container instead of the original interlaced video. + # http://ubuntuforums.org/showthread.php?t=1627194 + # http://forum.doom9.org/showthread.php?t=155732&page=31 + my $interlaced = system('ffmpeg -i "$video" 2>&1 | grep -q "frame rate differs"'); + if($interlaced != 0) { + my $video_mkv = $video; + my $video_ext = $video; + $video_ext =~ s/.*\.(\S+)$/$1/; + print " Detected interlaced video content: $video\n"; + if($video_ext !~ /mkv/i) { + $video_mkv =~ s/\.[^.]*$//; $video_mkv .= ".mkv"; + print " Re-muxing the interlaced video content as an mkv file: $video_mkv\n"; + my $make_mkv_cmd = "ffmpeg -i \"$video\" -scodec copy -acodec copy -vcodec copy -f matroska \"$video_mkv\" > /dev/null 2>&1"; + if(! defined $opt_s) { + my $errno = system("$make_mkv_cmd"); + $errno = $errno >> 8; + if($errno > 1) { + unlink "$video_mkv"; + die "-E- ffmpeg encountered some errors with exit code $errno\n"; + } + } + # Push the name of our intermediate video file onto a list of files to delete on exit + push(@video_tmp_files, "$video_mkv"); + # Update the name of our video file to equal the name of our new intermediate video file name + $video = $video_mkv; + } + } else { + print " Detected progressive video content: $video\n"; + } + # Create our intput file command line options for this video if($video_count == 0) { $cmd .= " $input_file_options \"$video\""; } else { @@ -115,15 +151,25 @@ foreach my $video (sort{$videos{$a} <=> $videos{$b}} keys %videos) { } $video_count++; } -print "$cmd\n"; + +# Execute our command line +print "\n$cmd\n"; if(! defined $opt_s) { my $errno = system("$cmd"); - if($errno > 0) { $errno = $errno - 255; } - if($errno > 1) { die "-E- mkvmerge encountered some errors with exit code $errno\n"; } + $errno = $errno >> 8; + if($errno > 1) { + unlink "$opt_o"; + die "-E- mkvmerge encountered some errors with exit code $errno\n"; + } } # Remove the temporary file used for the chapter generation if(-e "$tmpfile") { unlink "$tmpfile"; } +# Remove any temporary video files created during the merge process +foreach my $video (@video_tmp_files) { + if(-e "$video") { unlink "$video"; } +} + ####################################################################################################