From 6c55dc07095bccd36b29a0bd904b4ea3483f8b89 Mon Sep 17 00:00:00 2001 From: Martin Matusiak Date: Sat, 27 Sep 2008 22:17:22 +0200 Subject: [PATCH] remux_container works --- common.pm | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- encvid.pl | 18 ++++++++++-- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/common.pm b/common.pm index 4d07272..4ad4a84 100644 --- a/common.pm +++ b/common.pm @@ -35,6 +35,7 @@ our @EXPORT = qw( set_acodec_opts set_vcodec_opts run_encode + remux_container ); @@ -67,6 +68,9 @@ our $defaults = { xvid_2pass_bpp => .200, container => "avi", + + prescale => "", + postscale => ",harddup", }; @@ -208,6 +212,23 @@ sub run { return ($out, $exit, $err); } +# aggregate invocation results +sub run_agg { + my ($invokes, $fh_logfile) = @_; + + my ($out, $exit, $err); + foreach my $args (@$invokes) { + my ($o, $x, $e) = run($args); + $out .= $o; + $exit += $x; + $err .= $e; + print $fh_logfile join(" ", @$args)."\n"; + print $fh_logfile $o.$e."\n"; + } + + return ($out, $exit, $err); +} + # check for missing dependencies sub init_cmds { my $verbose = shift; @@ -799,7 +820,7 @@ sub run_encode { use POSIX ":sys_wait_h"; while ((my $kid = waitpid($pid, WNOHANG)) != -1) { - sysread($reader, my $s, 1000); + sysread($reader, my $s, 1024*1024); $exit = $? >> 8; print $fh_logfile $s; @@ -830,5 +851,76 @@ sub run_encode { } } +# run remux and print updates +sub remux_container { + my ($root, $ext, $fps, $container, $acodec, $vcodec) = @_; + + if ($container =~ /(mp4|mkv|ogm)/) { + + # Set logging + + my $base = basename($root); + my $logfile = $defaults->{logdir} . "/$base.remuxlog"; + + my $fh_logfile; + open($fh_logfile, ">", $logfile); + + sub pre { + if (-f "$root.$container") { + unlink("$root.$container"); + } + my @args1 = ($tools->{mplayer}, "$root.$ext", + "-dumpaudio", "-dumpfile", "$root.$acodec"); + my @args2 = ($tools->{mplayer}, "$root.$ext", + "-dumpvideo", "-dumpfile", "$root.$vcodec"); + return (\@args1, \@args2); + } + + sub post { + unlink "$root.$acodec"; + unlink "$root.$vcodec"; + unlink "$root.$ext"; + } + + my $remux; + + if ($container eq "mp4") { + $remux = sub { + my @args1 = ($tools->{mp4creator}, "-create", "$root.$acodec", + "$root.$container"); + my @args2 = ($tools->{mp4creator}, "-create", "$root.$vcodec", + "-rate=$fps", "$root.$container"); + my @args3 = ($tools->{mp4creator}, "-hint=1", "$root.$container"); + my @args4 = ($tools->{mp4creator}, "-hint=2", "$root.$container"); + my @args5 = ($tools->{mp4creator}, "-optimize", "$root.$container"); + + my @a = (pre, \@args1, \@args2, \@args3, \@args4, \@args5); + my ($out, $exit, $err) = run_agg(\@a, $fh_logfile); + post(); + return ($out, $exit, $err); + }; + } + + # Print initial status message + + my $status = trunc(59, 1, "[.] Remuxing"); + print "$status\r"; + + # Execute remux in the background + + my ($out, $exit, $err) = &$remux(); + + # Report exit code + + close($fh_logfile); + + if ($exit == 0) { + print "${status}[ " . s_ok("done") . trunc(15, 1, " ]") . "\n"; + } else { + print "${status}[ " . s_err("failed") . " ] check log" . "\n"; + } + } +} + 1; diff --git a/encvid.pl b/encvid.pl index c5a8730..61e0d46 100755 --- a/encvid.pl +++ b/encvid.pl @@ -39,10 +39,13 @@ my $adv_usage = "Advanced usage: " . s_b($suite->{tool_name}) . " " --acodec set audio codec --vcodec set video codec\n"; -my ($opts_start, $opts_end, $target_size, $bpp, $autocrop, $prescale, $postscale); +my ($opts_start, $opts_end, $target_size, $bpp, $autocrop); my ($dry_run, $opts_acodec, $opts_vcodec, $opts_cont); + my $custom_scale = "off"; my $target_passes = 1; +my $prescale = $defaults->{prescale}; +my $postscale = $defaults->{postscale}; my $parse = GetOptions( "start=f"=>\$opts_start, @@ -58,7 +61,7 @@ my $parse = GetOptions( "2"=> sub { $target_passes = 2; }, "c|crop"=> sub { $autocrop = 1; }, "r|scale=s"=>\$custom_scale, - "f|smooth"=> sub { $prescale = "spp,"; $postscale = ",hqdn3d"; }, + "f|smooth"=> sub { $prescale .= "spp,"; $postscale = ",hqdn3d$postscale"; }, "D|dryrun"=> sub { $dry_run = 1; }, "cont=s"=>\$opts_cont, @@ -244,6 +247,17 @@ foreach my $file (@files) { $ntitle->{passes}, $pass); } + if (-f "$title_name.$ext.partial") { + rename("$title_name.$ext.partial", "$title_name.$ext"); + } + + if (-f "divx2pass.log") { + unlink("divx2pass.log"); + } + + remux_container($title_name, $ext, $ntitle->{fps}, $container, + $ntitle->{aformat}, $ntitle->{vformat}); + } } -- 2.11.4.GIT