From 7ab3d45a312e4e75da5656e1f3963d9c965d0fd9 Mon Sep 17 00:00:00 2001 From: Chris Petersen Date: Sun, 15 Feb 2004 02:43:23 +0000 Subject: [PATCH] lots of cleanup patches from Dennis Lou --- trunk/export_DVD.pm | 62 ++++++-------------------------------------- trunk/export_DivX.pm | 25 +++++++----------- trunk/export_MP3.pm | 15 +---------- trunk/export_SVCD.pm | 38 +++------------------------ trunk/export_VCD.pm | 10 +------ trunk/export_WMV.pm | 25 +++++++----------- trunk/gui_text.pm | 3 ++- trunk/nuv_utils.pm | 33 ++++++++++++++++++++++- 8 files changed, 66 insertions(+), 145 deletions(-) diff --git a/trunk/export_DVD.pm b/trunk/export_DVD.pm index 3275c7d..9c39aed 100644 --- a/trunk/export_DVD.pm +++ b/trunk/export_DVD.pm @@ -17,7 +17,6 @@ package export_DVD; *Args = *main::Args; *Prog = *main::Prog; *gui = *main::gui; - *DEBUG = *main::DEBUG; sub new { my $class = shift; @@ -223,23 +222,8 @@ package export_DVD; # Here, we have to fork off a copy of mythtranscode my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir} --fifosync"; $command .= ' --honorcutlist' if ($self->{use_cutlist}); - if ($DEBUG) { - print "\nmythtranscode command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } - # Sleep a bit to let mythtranscode start up - if (!$DEBUG) { - my $overload = 0; - while (++$overload < 30 && !(-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout")) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout") { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } - } + push @{$self->{children}}, fork_command($command); + fifos_wait($self->{fifodir}); # Now we fork off a process to encode the audio if ($Prog{toolame}) { $command = "nice -n 19 sox -t raw -r $nuv_info{audio_sample_rate} -s -w -c 2 $self->{fifodir}/audout -t raw -r 48000 -s -w -c 2 - | nice -n 19 toolame -s 48.0 -m j -b $self->{a_bitrate} - $self->{tmp_a}"; @@ -247,12 +231,7 @@ package export_DVD; $command = "nice -n 19 ffmpeg -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i $self->{fifodir}/audout -ac 2 -ar 48000 -ab $self->{a_bitrate} -vn -f mp2 $self->{tmp_a}"; } - if ($DEBUG) { - print "\naudio command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } + push @{$self->{children}}, fork_command($command); # And lastly, we fork off a process to encode the video # Multiple CPU's? Let's multiprocess $cpus = num_cpus(); @@ -283,12 +262,7 @@ package export_DVD; ." --reduction-4x4 2 --reduction-2x2 1 --keep-hf" .($cpus > 1 ? " --multi-thread $cpus" : '') ." -o $self->{tmp_v}"; - if ($DEBUG) { - print "\nmpeg2enc command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } + push @{$self->{children}}, fork_command($command); # Wait for child processes to finish 1 while (wait > 0); $self->{children} = undef; @@ -300,39 +274,19 @@ package export_DVD; else { $command = "nice -n 19 mplex -f 8 $self->{tmp_v} $self->{tmp_a} -o $safe_outfile"; } - if ($DEBUG) { - print "\nmultiplex command:\n\n$command\n\n"; - } else { system($command); - } if ($self->{author_now}) { $command = "nice -n 20 dvdauthor -t -o $self->{dvddir} $safe_outfile"; - if ($DEBUG) { - print "\nauthor command 1:\n\n$command\n\n"; - } else { - system($command); - } + system($command); $command = "nice -n 20 dvdauthor -T -o $self->{dvddir}"; - if ($DEBUG) { - print "\nauthor command 2:\n\n$command\n\n"; - } else { - system($command); - } + system($command); if ($self->{burn_now}) { $command = "nice -n 20 growisofs -speed=$self->{dvdr_speed} -Z $self->{dvdr_path} -dvd-video $self->{dvddir}"; - if ($DEBUG) { - print "\nburn command:\n\n$command\n\n"; - } else { - system($command); - } + system($command); } else { $command = "nice -n 20 mkisofs -dvd-video -udf -o $safe_outfile.dvd.iso $self->{dvddir}"; - if ($DEBUG) { - print "\nmkisofs command 1:\n\n$command\n\n"; - } else { - system($command); - } + system($command); } } } diff --git a/trunk/export_DivX.pm b/trunk/export_DivX.pm index aa978fc..cb49e73 100644 --- a/trunk/export_DivX.pm +++ b/trunk/export_DivX.pm @@ -16,6 +16,7 @@ package export_DivX; 'episode' => undef, 'savepath' => '.', 'outfile' => 'out.avi', + 'fifodir' => "fifodir.$$", 'use_cutlist' => 0, 'a_bitrate' => 64, 'v_bitrate' => 256, @@ -79,7 +80,7 @@ package export_DivX; sub execute { my $self = shift; # make sure that the fifo dir is clean - if (-e 'fifodir/vidout' || -e 'fifodir/audout') { + if (-e "$self->{fifodir}/vidout" || -e "$self->{fifodir}/audout") { die "Possibly stale mythtranscode fifo's in fifodir.\nPlease remove them before running nuvexport.\n\n"; } # Gather any necessary data @@ -90,25 +91,17 @@ package export_DivX; # Set this to true so that the cleanup routine actually runs $self->{started} = 1; # Create a directory for mythtranscode's fifo's - unless (-d 'fifodir') { - mkdir('fifodir', 0755) or die "Can't create fifodir: $!\n\n"; + unless (-d $self->{fifodir}) { + mkdir($self->{fifodir}, 0755) or die "Can't create $self->{fifodir}: $!\n\n"; } # Here, we have to fork off a copy of mythtranscode - my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f fifodir"; + my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir}"; $command .= ' --honorcutlist' if ($self->{use_cutlist}); push @{$self->{children}}, fork_command($command); - # Sleep a bit to let mythtranscode start up - my $overload = 0; - while (++$overload < 30 && !(-e 'fifodir/audout' && -e 'fifodir/vidout')) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e 'fifodir/audout' && -e 'fifodir/vidout') { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } + fifos_wait($self->{fifodir}); # Now we fork off a process to encode everything $safe_outfile = shell_escape($self->{outfile}); - $command = "nice -n 19 ffmpeg -y -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i fifodir/audout -f rawvideo -s $nuv_info{width}x$nuv_info{height} -r $nuv_info{fps} -i fifodir/vidout -b $self->{v_bitrate} -ab $self->{a_bitrate} -s $self->{h_res}x$self->{v_res} $safe_outfile"; + $command = "nice -n 19 ffmpeg -y -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i $self->{fifodir}/audout -f rawvideo -s $nuv_info{width}x$nuv_info{height} -r $nuv_info{fps} -i $self->{fifodir}/vidout -b $self->{v_bitrate} -ab $self->{a_bitrate} -s $self->{h_res}x$self->{v_res} $safe_outfile"; push @{$self->{children}}, fork_command($command); # Wait for child processes to finish 1 while (wait > 0); @@ -126,10 +119,10 @@ package export_DivX; 1 while (wait > 0); } # Remove any temporary files - foreach my $file ('fifodir/audout', 'fifodir/vidout') { + foreach my $file ("$self->{fifodir}/audout", "$self->{fifodir}/vidout") { unlink $file if (-e $file); } - rmdir 'fifodir' if (-e 'fifodir'); + rmdir $self->{fifodir} if (-e $self->{fifodir}); } 1; #return true diff --git a/trunk/export_MP3.pm b/trunk/export_MP3.pm index d1cf32a..cc14946 100644 --- a/trunk/export_MP3.pm +++ b/trunk/export_MP3.pm @@ -91,20 +91,10 @@ package export_MP3; # my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir} --fifosync"; my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir} --fifosync"; # $command .= ' --honorcutlist' if ($self->{use_cutlist}); - print "$command \n" ; push @{$self->{children}}, fork_command($command); - # Sleep a bit to let mythtranscode start up - my $overload = 0; - while (++$overload < 30 && !(-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout")) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout") { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } + fifos_wait($self->{fifodir}); # Now we fork off a process to extract the audio $command = "nice -19 cat < $self->{fifodir}/audout > $self->{tmp_a}" ; - print "$command \n"; push @{$self->{children}}, fork_command($command); # Null command for video @@ -119,13 +109,10 @@ package export_MP3; $sample = $nuv_info{audio_sample_rate} / 1000; my $safe_outfile = shell_escape($self->{outfile}); $command = "nice -n 19 toolame -t1 -s $sample -m j -b $self->{bitrate} $self->{tmp_a} $safe_outfile"; - #$command = "nice -n 19 lame -r -v -q 2 -s $sample -m j -V 2 -B $self->{bitrate} $self->{tmp_a} $safe_outfile"; -print "$command \n"; system($command); # Now tag it $command = "id3tag -A\"$self->{episode}->{title}\" -a\"$self->{episode}->{channel}\" -c\"$self->{episode}->{description}\" -s\"$self->{episode}->{show_name}\" $safe_outfile"; - print "$command \n"; system($command); } diff --git a/trunk/export_SVCD.pm b/trunk/export_SVCD.pm index 8db6d0d..fb91774 100644 --- a/trunk/export_SVCD.pm +++ b/trunk/export_SVCD.pm @@ -16,7 +16,6 @@ package export_SVCD; *Args = *main::Args; *Prog = *main::Prog; *gui = *main::gui; - *DEBUG = *main::DEBUG; sub new { my $class = shift; @@ -198,31 +197,11 @@ package export_SVCD; # Here, we have to fork off a copy of mythtranscode my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir} --fifosync"; $command .= ' --honorcutlist' if ($self->{use_cutlist}); - if ($DEBUG) { - print "\nmythtranscode command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } - # Sleep a bit to let mythtranscode start up - if (!$DEBUG) { - my $overload = 0; - while (++$overload < 30 && !(-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout")) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout") { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } - } + push @{$self->{children}}, fork_command($command); + fifos_wait($self->{fifodir}); # Now we fork off a process to encode the audio $command = "nice -n 19 ffmpeg -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i $self->{fifodir}/audout -ar 44100 -ab $self->{a_bitrate} -vn -f mp2 $self->{tmp_a}"; - if ($DEBUG) { - print "\naudio command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } + push @{$self->{children}}, fork_command($command); # And lastly, we fork off a process to encode the video # Multiple CPU's? Let's multiprocess $cpus = num_cpus(); @@ -256,12 +235,7 @@ package export_SVCD; ." --reduction-4x4 2 --reduction-2x2 1" .($cpus > 1 ? " --multi-thread $cpus" : '') ." -o $self->{tmp_v}"; - if ($DEBUG) { - print "\nmpeg2enc command:\n\n$command\n"; - } - else { - push @{$self->{children}}, fork_command($command); - } + push @{$self->{children}}, fork_command($command); # Wait for child processes to finish 1 while (wait > 0); $self->{children} = undef; @@ -273,10 +247,6 @@ package export_SVCD; else { $command = "nice -n 19 mplex -f 5 $self->{tmp_v} $self->{tmp_a} -o $safe_outfile"; } - if ($DEBUG) { - print "\nmultiplex command:\n\n$command\n\n"; - exit; - } system($command); } diff --git a/trunk/export_VCD.pm b/trunk/export_VCD.pm index b91b4f3..29f85ae 100644 --- a/trunk/export_VCD.pm +++ b/trunk/export_VCD.pm @@ -99,15 +99,7 @@ package export_VCD; my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir} --fifosync"; $command .= ' --honorcutlist' if ($self->{use_cutlist}); push @{$self->{children}}, fork_command($command); - # Sleep a bit to let mythtranscode start up - my $overload = 0; - while (++$overload < 30 && !(-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout")) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e "$self->{fifodir}/audout" && -e "$self->{fifodir}/vidout") { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } + fifos_wait($self->{fifodir}); # Now we fork off a process to encode the audio if ($Prog{mp2_encoder} =~ /\btoolame$/) { $sample = $nuv_info{audio_sample_rate} / 1000; diff --git a/trunk/export_WMV.pm b/trunk/export_WMV.pm index 6ae325f..90fe31e 100644 --- a/trunk/export_WMV.pm +++ b/trunk/export_WMV.pm @@ -16,6 +16,7 @@ package export_WMV; 'episode' => undef, 'savepath' => '.', 'outfile' => 'out.wmv', + 'fifodir' => "fifodir.$$", 'use_cutlist' => 0, 'a_bitrate' => 64, 'v_bitrate' => 256, @@ -81,7 +82,7 @@ package export_WMV; sub execute { my $self = shift; # make sure that the fifo dir is clean - if (-e 'fifodir/vidout' || -e 'fifodir/audout') { + if (-e "$self->{fifodir}/vidout" || -e "$self->{fifodir}/audout") { die "Possibly stale mythtranscode fifo's in fifodir.\nPlease remove them before running nuvexport.\n\n"; } # Gather any necessary data @@ -92,25 +93,17 @@ package export_WMV; # Set this to true so that the cleanup routine actually runs $self->{started} = 1; # Create a directory for mythtranscode's fifo's - unless (-d 'fifodir') { - mkdir('fifodir', 0755) or die "Can't create fifodir: $!\n\n"; + unless (-d $self->{fifodir}) { + mkdir($self->{fifodir}, 0755) or die "Can't create $self->{fifodir}: $!\n\n"; } # Here, we have to fork off a copy of mythtranscode - my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f fifodir"; + my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f $self->{fifodir}"; $command .= ' --honorcutlist' if ($self->{use_cutlist}); push @{$self->{children}}, fork_command($command); - # Sleep a bit to let mythtranscode start up - my $overload = 0; - while (++$overload < 30 && !(-e 'fifodir/audout' && -e 'fifodir/vidout')) { - sleep 1; - print "Waiting for mythtranscode to set up the fifos.\n"; - } - unless (-e 'fifodir/audout' && -e 'fifodir/vidout') { - die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; - } + fifos_wait($self->{fifodir}); # Now we fork off a process to encode everything $safe_outfile = shell_escape($self->{outfile}); - $command = "nice -n 19 ffmpeg -y -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i fifodir/audout -f rawvideo -s $nuv_info{width}x$nuv_info{height} -r $nuv_info{fps} -i fifodir/vidout -b $self->{v_bitrate} -ab $self->{a_bitrate} -s $self->{h_res}x$self->{v_res} $safe_outfile"; + $command = "nice -n 19 ffmpeg -y -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i $self->{fifodir}/audout -f rawvideo -s $nuv_info{width}x$nuv_info{height} -r $nuv_info{fps} -i $self->{fifodir}/vidout -b $self->{v_bitrate} -ab $self->{a_bitrate} -s $self->{h_res}x$self->{v_res} $safe_outfile"; push @{$self->{children}}, fork_command($command); # Wait for child processes to finish 1 while (wait > 0); @@ -128,10 +121,10 @@ package export_WMV; 1 while (wait > 0); } # Remove any temporary files - foreach my $file ('fifodir/audout', 'fifodir/vidout') { + foreach my $file ("$self->{fifodir}/audout", "$self->{fifodir}/vidout") { unlink $file if (-e $file); } - rmdir 'fifodir' if (-e 'fifodir'); + rmdir $self->{fifodir} if (-e $self->{fifodir}); } 1; #return true diff --git a/trunk/gui_text.pm b/trunk/gui_text.pm index f52ee19..abb80f6 100644 --- a/trunk/gui_text.pm +++ b/trunk/gui_text.pm @@ -6,6 +6,7 @@ package gui_text; *Shows = *main::Shows; *Functions = *main::Functions; *num_shows = *main::num_shows; + *DEBUG = *main::DEBUG; sub new { my $class = shift; @@ -25,7 +26,7 @@ package gui_text; # Display the show list while (1) { # Clear the screen - system('clear'); + system('clear') unless ($DEBUG); # Stage "quit" means, well, quit... if ($self->stage eq 'quit') { # Report the duration diff --git a/trunk/nuv_utils.pm b/trunk/nuv_utils.pm index b3945ff..25e0421 100644 --- a/trunk/nuv_utils.pm +++ b/trunk/nuv_utils.pm @@ -2,7 +2,9 @@ package nuv_utils; use Exporter; our @ISA = qw/ Exporter /; - our @EXPORT = qw/ generate_showtime find_program nuv_info num_cpus fork_command shell_escape mysql_escape Quit /; + our @EXPORT = qw/ generate_showtime find_program nuv_info num_cpus fork_command shell_escape mysql_escape Quit system fifos_wait /; + + *DEBUG = *main::DEBUG; # Returns a nicely-formatted timestamp from a specified time sub generate_showtime { @@ -187,6 +189,11 @@ package nuv_utils; # This subroutine forks and executes one system command - nothing fancy sub fork_command { my $command = shift; + if ($DEBUG) { + print "\nforking:\n$command\n"; + return undef; + } + # Fork and return the child's pid my $pid = undef; if ($pid = fork) { @@ -232,4 +239,28 @@ package nuv_utils; } } + sub system { + my $command = shift; + if ($DEBUG) { + print "\nsystem call:\n$command\n"; + } else { + system($command); + } + } + + sub fifos_wait { + # Sleep a bit to let mythtranscode start up + my $fifodir = shift; + my $overload = 0; + if (!$DEBUG) { + while (++$overload < 30 && !(-e "$fifodir/audout" && -e "$fifodir/vidout" )) { + sleep 1; + print "Waiting for mythtranscode to set up the fifos.\n"; + } + unless (-e "$fifodir/audout" && -e "$fifodir/vidout") { + die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n"; + } + } + } + 1; #return true