138 changes: 138 additions & 0 deletions trunk/export_Trans_XviD.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package export_Trans_XviD;

# Load the nuv utilities
use nuv_utils;

# Make sure we have pointers to the main:: namespace for certain variables
*Prog = *main::Prog;
*gui = *main::gui;

sub new {
my $class = shift;
my $self = {
'name' => 'Transcode export to XviD',
'enabled' => 1,
'errors' => undef,
'episode' => undef,
'savepath' => '.',
'outfile' => 'out.avi',
'use_cutlist' => 1,
'a_bitrate' => 64,
'v_bitrate' => 512,
'h_res' => 320,
'v_res' => 240,
'sql_file' => undef,
'deinterlace' => 1,
'noise_reduction' => 0,
@_ #allows user-specified attributes to override the defaults
};
bless($self, $class);
# Return
return $self;
}

sub gather_data {
my $self = shift;
my $default_filename;
# Get the save path
$self->{savepath} = $gui->query_savepath();
# Ask the user for the filename
if($self->{episode}->{show_name} ne 'Untitled' and $self->{episode}->{title} ne 'Untitled')
{
$default_filename = $self->{episode}->{show_name}.' - '.$self->{episode}->{title};
}
elsif($self->{episode}->{show_name} ne 'Untitled')
{
$default_filename = $self->{episode}->{show_name};
}
elsif($self->{episode}->{title} ne 'Untitled')
{
$default_filename = $self->{episode}->{title};
}

$self->{outfile} = $gui->query_filename($default_filename, 'avi', $self->{savepath});
# Ask the user if he/she wants to use the cutlist
if ($self->{episode}->{cutlist} && $self->{episode}->{cutlist} =~ /\d/) {
$self->{use_cutlist} = $gui->query_text('Enable Myth cutlist?',
'yesno',
$self->{use_cutlist} ? 'Yes' : 'No');
}
else {
$gui->notify('No cutlist found. Hopefully this means that you already removed the commercials.');
}
# Ask the user what audio bitrate he/she wants
my $a_bitrate = $gui->query_text('Audio bitrate?',
'int',
$self->{a_bitrate});
$self->{a_bitrate} = $a_bitrate;
# Ask the user what video bitrate he/she wants
my $v_bitrate = $gui->query_text('Video bitrate?',
'int',
$self->{v_bitrate});
$self->{v_bitrate} = $v_bitrate;
# Ask the user what horiz res he/she wants
my $h_res = $gui->query_text('Horizontal resolution?', 'int', $self->{h_res});
$self->{h_res} = $h_res;
# Ask the user what vert res he/she wants
my $v_res = $gui->query_text('Vertical resolution?', 'int', $self->{v_res});
$self->{v_res} = $v_res;
# Noise reduction
$self->{noise_reduction} = $gui->query_text('Enable noise reduction (slower, but better results)?',
'yesno',
$self->{noise_reduction} ? 'Yes' : 'No');
$self->{deinterlace} = $gui->query_text('Enable deinterlacing?',
'yesno',
$self->{deinterlace} ? 'Yes' : 'No');

}

sub execute {
my $self = shift;

# Gather any necessary data
$self->{episode} = shift;
$self->gather_data;
# Load nuv info
my %nuv_info = nuv_info($self->{episode}->{filename});
# Set this to true so that the cleanup routine actually runs
$self->{started} = 1;

$safe_outfile = shell_escape($self->{outfile});
my $command = "nice -n 19 transcode -x mpeg2 -i $main::video_dir/$self->{episode}->{filename} -y xvid -Z $self->{h_res}x$self->{v_res} -o $safe_outfile -w $self->{v_bitrate} -b $self->{a_bitrate}";

if ($self->{use_cutlist}) {
@cuts = split("\n",$self->{episode}->{cutlist});
my @skiplist;
foreach $cut (@cuts) {
push @skiplist, (split(" - ", $cut))[0]."-".(split(" - ", $cut))[1];
}
$command .= " -J skip=\"".join(" ", @skiplist)."\"";
}

if ($self->{deinterlace}) {
$command .= " -V -J smartdeinter";
}
if ($self->{noise_reduction}) {
$command .= " -V -J yuvdenoise";
}

push @{$self->{children}}, fork_command($command);
# Wait for child processes to finish
1 while (wait > 0);
$self->{children} = undef;
}

sub cleanup {
my $self = shift;
return unless ($self->{started});
# Make sure any child processes also go away
if ($self->{children} && @{$self->{children}}) {
foreach my $child (@{$self->{children}}) {
kill('INT', $child);
}
1 while (wait > 0);
}
# Remove any temporary files
}

1; #return true
4 changes: 2 additions & 2 deletions trunk/export_VCD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ package export_VCD;
# Now we fork off a process to encode the audio
if ($Prog{mp2_encoder} =~ /\btoolame$/) {
$sample = $nuv_info{audio_sample_rate} / 1000;
$command = "nice -n 19 toolame -s $sample -m j -b 192 $self->{fifodir}/audout $self->{tmp_a}";
$command = "nice -n 19 toolame -s $sample -m j -b 224 $self->{fifodir}/audout $self->{tmp_a}";
}
else {
$command = "nice -n 19 ffmpeg -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i $self->{fifodir}/audout -vn -f wav -"
." | nice -n 19 mp2enc -b 192 -r $nuv_info{audio_sample_rate} -s -o $self->{tmp_a}";
." | nice -n 19 mp2enc -V -s -o $self->{tmp_a}";
}
push @{$self->{children}}, fork_command($command);
# And lastly, we fork off a process to encode the video
Expand Down
14 changes: 11 additions & 3 deletions trunk/nuvexport
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
our $gui;
our $video_dir;
our $num_shows;
our $dbh;
our $hostname;

# Load the nuv utilities
use nuv_utils;
Expand All @@ -103,6 +105,9 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
use export_SVCD;
use export_VCD;
use export_WMV;
use export_Trans_XviD;
use export_Trans_VCD;
use export_Trans_SVCD;

# Make sure that we have mythtranscode installed
$Prog{mythtranscode} = find_program('mythtranscode');
Expand Down Expand Up @@ -142,7 +147,10 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
export_NUV_SQL->new,
export_DivX->new,
export_WMV->new,
export_VCD->new;
export_VCD->new,
export_Trans_XviD->new,
export_Trans_VCD->new,
export_Trans_SVCD->new;

# Set up the signal handlers
$SIG{INT} = \&Quit;
Expand Down Expand Up @@ -174,11 +182,11 @@ format and use Microsoft's Windows Media Encoder to encode a WMV file.
close CONF;

# Connect to the database
my $dbh = DBI->connect("dbi:mysql:database=$db_name:host=$db_host", $db_user, $db_pass)
$dbh = DBI->connect("dbi:mysql:database=$db_name:host=$db_host", $db_user, $db_pass)
or die "Cannot connect to database: $!\n\n";

# Get the hostname of this machine
my $hostname = `hostname`;
$hostname = `hostname`;
chomp($hostname);

# Find the directory where the recordings are located, and grab all of the filenames
Expand Down