161 changes: 161 additions & 0 deletions trunk/export/mencoder/XviD.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/perl -w
#Last Updated: 2005.02.28 (xris)
#
# export::mencoder::XviD
# Copied from transcode.pm
# and modified by Ryan Dearing <mythtv@mythtv.us>
#

package export::mencoder::XviD;
use base 'export::mencoder';

# Load the myth and nuv utilities, and make sure we're connected to the database
use nuv_export::shared_utils;
use nuv_export::cli;
use nuv_export::ui;
use mythtv::db;
use mythtv::recordings;

# Load the following extra parameters from the commandline
add_arg('quantisation|q=i', 'Quantisation');
add_arg('a_bitrate|a=i', 'Audio bitrate');
add_arg('v_bitrate|v=i', 'Video bitrate');
add_arg('multipass!', 'Enably two-pass encoding.');

sub new {
my $class = shift;
my $self = {
'cli' => qr/\bxvidmen\b/i,
'name' => 'Export to XviD (using mencoder)',
'enabled' => 1,
'errors' => [],
#Mencoder-related settings
'noise_reduction' => 1,
'deinterlace' => 1,
'crop' => 1,
};
bless($self, $class);

# Verify any commandline or config file options
die "Audio bitrate must be > 0\n" unless (defined $self->val('a_bitrate') && $self->{'a_bitrate'} > 0);
die "Video bitrate must be > 0\n" unless (defined $self->val('v_bitrate') && $self->{'v_bitrate'} > 0);
die "Width must be > 0\n" unless (!defined $self->val('width') || $self->{'width'} =~ /^\s*\D/ || $self->{'width'} > 0);
die "Height must be > 0\n" unless (!defined $self->val('height') || $self->{'height'} =~ /^\s*\D/ || $self->{'height'} > 0);

# VBR, multipass, etc.
if ($self->val('multipass')) {
$self->{'vbr'} = 1;
}
elsif ($self->val('quantisation')) {
die "Quantisation must be a number between 1 and 31 (lower means better quality).\n" if ($self->{'quantisation'} < 1 || $self->{'quantisation'} > 31);
$self->{'vbr'} = 1;
}

# Initialize and check for mencoder
$self->init_mencoder();

# Any errors? disable this function
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
# Return
return $self;
}

sub gather_settings {
my $self = shift;
# Load the parent module's settings
$self->SUPER::gather_settings();
# Audio Bitrate
$self->{'a_bitrate'} = query_text('Audio bitrate?',
'int',
$self->val('a_bitrate'));
# VBR options
if (!$is_cli) {
$self->{'vbr'} = query_text('Variable bitrate video?',
'yesno',
$self->val('vbr'));
if ($self->{'vbr'}) {
$self->{'multipass'} = query_text('Multi-pass (slower, but better quality)?',
'yesno',
$self->val('multipass'));
if (!$self->{'multipass'}) {
while (1) {
my $quantisation = query_text('VBR quality/quantisation (1-31)?', 'float', $self->val('quantisation'));
if ($quantisation < 1) {
print "Too low; please choose a number between 1 and 31.\n";
}
elsif ($quantisation > 31) {
print "Too high; please choose a number between 1 and 31\n";
}
else {
$self->{'quantisation'} = $quantisation;
last;
}
}
}
}
# Ask the user what audio and video bitrates he/she wants
if ($self->{'multipass'} || !$self->{'vbr'}) {
$self->{'v_bitrate'} = query_text('Video bitrate?',
'int',
$self->val('v_bitrate'));
}
}
# Query the resolution
$self->query_resolution();
}

sub export {
my $self = shift;
my $episode = shift;
# Make sure we have finfo
load_finfo($episode);
# Build the mencoder string
my $params = " -ovc xvid -vop scale=$self->{'width'}:$self->{'height'}"
#." -N 0x55" # make *sure* we're exporting mp3 audio

#." -oac mp3lame -lameopts vbr=3:br=$self->{'a_bitrate'}"
;
# unless ($episode->{'finfo'}{'fps'} =~ /^2(?:5|4\.9)/) {
# $params .= " -J modfps=buffers=7 --export_fps 23.976";
# }
# Dual pass?
if ($self->{'multipass'}) {
# Add the temporary file to the list
push @tmpfiles, "/tmp/xvid.$$.log";
# Back up the path and use /dev/null for the first pass
my $path_bak = $self->{'path'};
$self->{'path'} = '/dev/null';
# First pass
print "First pass...\n";
$self->{'mencoder_xtra'} = " $params"
." -passlogfile /tmp/xvid.$$.log"
." -nosound"
." -xvidencopts bitrate=$self->{'v_bitrate'}:pass=1 ";
$self->SUPER::export($episode, '', 1);
# Restore the path
$self->{'path'} = $path_bak;
# Second pass
print "Final pass...\n";
$self->{'mencoder_xtra'} = " $params"
." -oac mp3lame -lameopts vbr=3:br=$self->{'a_bitrate'}"
." -passlogfile /tmp/xvid.$$.log"
." -xvidencopts bitrate=$self->{'v_bitrate'}:pass=2 ";
}
# Single pass
else {
$self->{'mencoder_xtra'} = " $params"
." -oac mp3lame -lameopts vbr=3:br=$self->{'a_bitrate'}";
if ($self->{'quantisation'}) {
$self->{'mencoder_xtra'} .= " -xvidencopts fixed_quant=".$self->{'quantisation'};
}
else {
$self->{'mencoder_xtra'} .= ":bitrate=$self->{'v_bitrate'} ";
}
}
# Execute the (final pass) encode
$self->SUPER::export($episode, '.avi');
}

1; #return true

# vim:ts=4:sw=4:ai:et:si:sts=4
28 changes: 20 additions & 8 deletions trunk/nuv_export/cli.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ package nuv_export::cli;
# --ffmpeg, --transcode and --config
our $export_prog = undef;
our $config_file = undef;
GetOptions('ffmpeg' => sub { $export_prog = 'ffmpeg'; },
'transcode' => sub { $export_prog = 'transcode'; },
'config|c=s' => \$config_file,
GetOptions('ffmpeg' => sub { $export_prog = 'ffmpeg'; },
'transcode' => sub { $export_prog = 'transcode'; },
'mencoder' => sub { $export_prog = 'mencoder'; },
'config|c=s' => \$config_file,
);

# Make sure the specified config file exists
Expand Down Expand Up @@ -82,13 +83,17 @@ package nuv_export::cli;
# Make sure the export_prog exists
if (!$export_prog) {
if ($export_prog = lc($rc_args{'nuvexport'}{'export_prog'})) {
if ($export_prog !~ /(?:ffmpeg|transcode)$/) {
if ($export_prog !~ /(?:ffmpeg|transcode|mencoder)$/) {
print "Unknown export_prog in nuvexportrc: $export_prog\n\n";
exit;
}
}
else {
$export_prog = find_program('ffmpeg') ? 'ffmpeg' : 'transcode';
$export_prog = find_program('ffmpeg')
? 'ffmpeg'
: find_program('transcode')
? 'transcode'
: 'mencoder';
}
}

Expand Down Expand Up @@ -174,10 +179,17 @@ package nuv_export::cli;
# Remove an unused package parent name, and any leftovers from $self
$package =~ s/^export:://;
$package =~ s/=.+?$//;
# Scan the package from parent to child, looking for matches
my $path = $package;
while ($path) {
return $rc_args{$path}{$arg} if (defined $rc_args{$path}{$arg});
last unless ($path =~ s/^.+?:://);
}
# Scan the package from child to parent, looking for matches
while ($package) {
return $rc_args{$package}{$arg} if (defined $rc_args{$package}{$arg});
last unless ($package =~ s/::.+?$//);
$path = $package;
while ($path) {
return $rc_args{$path}{$arg} if (defined $rc_args{$path}{$arg});
last unless ($path =~ s/::.+?$//);
}
# Finally, try "generic"
return $rc_args{'generic'}{$arg} if (defined $rc_args{'generic'}{$arg});
Expand Down
3 changes: 2 additions & 1 deletion trunk/nuv_export/shared_utils.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
#Last Updated: 2005.02.25 (xris)
#Last Updated: 2005.02.28 (xris)
#
# nuv_export::shared_utils
#
Expand Down Expand Up @@ -210,6 +210,7 @@ BEGIN {
my $command = shift;
if ($DEBUG) {
$command =~ s#\ [12]\s*>\s*/dev/null##sg;
$command =~ s/\ [12]\s*>\s*\&[12]\s*$//sg;
print "\nsystem call:\n$command\n";
}
else {
Expand Down
11 changes: 10 additions & 1 deletion trunk/nuvexport
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
# Last Updated: 2005.02.25 (xris)
# Last Updated: 2005.02.28 (xris)

# Version
$VERSION = '0.2 cvs20050221';
Expand Down Expand Up @@ -56,6 +56,12 @@
require export::ffmpeg::ASF;
require export::ffmpeg::MP3;
}
elsif ($export_prog eq 'mencoder') {
find_program('mencoder')
or die "You need mencoder in order to use nuvexport in --mencoder mode\n";
# ffmpeg - seems to work better and is the default
require export::mencoder::XviD;
}

# Load the other export modules
require export::MPEG2_cut;
Expand All @@ -82,6 +88,9 @@
push @Exporters, export::ffmpeg::ASF->new;
push @Exporters, export::ffmpeg::MP3->new;
}
elsif ($export_prog eq 'mencoder') {
push @Exporters, export::mencoder::XviD->new;
}
push @Exporters, export::MPEG2_cut->new;
push @Exporters, export::NUV_SQL->new;

Expand Down
71 changes: 41 additions & 30 deletions trunk/nuvexportrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<nuvexport>

#
# Set export_prog to ffmpeg or transcode, depending on your preference of
# program for exports. This is equivalent to --ffmpeg or --transcode.
# Set export_prog to ffmpeg, transcode or mencoder, depending on your
# preference of program for exports. This is equivalent to --ffmpeg,
# --transcode or --mencoder
#
export_prog=transcode

Expand Down Expand Up @@ -48,51 +49,61 @@ underscores=no

<generic>

path = /home/xris/Video
path = /home/xris/Video

use_cutlist = yes
multipass = yes
use_cutlist = yes
multipass = yes

noise_reduction = yes
deinterlace = yes
crop = yes
noise_reduction = yes
deinterlace = yes
crop = yes

</generic>

#
# You can create settings for each export module type. These are the
# second-most generic sections, and will only be reached if there are no
# matches in the full or generic module names.
#

<ffmpeg>
noise_reduction = no
</ffmpeg>

<ffmpeg::XviD>
<transcode>
</transcode>

vbr = yes # Enable vbr to get the multipass/quantisation options
# (enabling multipass or quantisation automatically enables vbr)
multipass = yes # You get either multipass or quantisation; multipass will override
quantisation = 6 # 4 through 6 is probably right... 1..31 are allowed (lower is better quality)
<mencoder>
</mencoder>

a_bitrate = 128 # Audio bitrate of 128 kbps
v_bitrate = 960 # Remember, quantisation overrides video bitrate
#
# You can also create settings for generic export module names. These will
# only be overridden by full module names.
#

width = 624 # Height adjusts automatically to width, according to aspect ratio
height = auto
<XviD>

</ffmpeg::XviD>
vbr = yes # Enable vbr to get the multipass/quantisation options
# (enabling multipass or quantisation automatically enables vbr)
multipass = yes # You get either multipass or quantisation; multipass will override
quantisation = 6 # 4 through 6 is probably right... 1..31 are allowed (lower is better quality)

<transcode>
</transcode>
a_bitrate = 128 # Audio bitrate of 128 kbps
v_bitrate = 960 # Remember, quantisation overrides video bitrate

width = 624 # Height adjusts automatically to width, according to aspect ratio
height = auto

<transcode::XviD>
</XviD>

vbr = yes # Enable vbr to get the multipass/quantisation options
# (enabling multipass or quantisation automatically enables vbr)
multipass = yes # You get either multipass or quantisation; multipass will override
quantisation = 6 # 4 through 6 is probably right... 1..31 are allowed (lower is better quality)
#
# If you want to provide settings for a very specific export module, you can
# use its full name, and it will override any more generic settings.
#

a_bitrate = 128 # Audio bitrate of 128 kbps
v_bitrate = 960 # Remember, quantisation overrides video bitrate
<mencoder::XviD>

width = 624 # Height adjusts automatically to width, according to aspect ratio
height = auto
multipass = no

</transcode::XviD>
</mencoder::XviD>