| 1 | #
|
|---|
| 2 | # $Date: 2008-02-16 20:16:13 -0500 (Sat, 16 Feb 2008) $
|
|---|
| 3 | # $Revision: 16098 $
|
|---|
| 4 | # $Author: xris $
|
|---|
| 5 | #
|
|---|
| 6 | # export::mencoder::H264
|
|---|
| 7 | # Copied from transcode.pm
|
|---|
| 8 | # and modified by Ryan Dearing <mythtv@mythtv.us>
|
|---|
| 9 | #
|
|---|
| 10 |
|
|---|
| 11 | package export::mencoder::H264;
|
|---|
| 12 | use base 'export::mencoder';
|
|---|
| 13 |
|
|---|
| 14 | # Load the myth and nuv utilities, and make sure we're connected to the database
|
|---|
| 15 | use nuv_export::shared_utils;
|
|---|
| 16 | use nuv_export::cli;
|
|---|
| 17 | use nuv_export::ui;
|
|---|
| 18 | use mythtv::recordings;
|
|---|
| 19 |
|
|---|
| 20 | # Load the following extra parameters from the commandline
|
|---|
| 21 | add_arg('quantisation|q=i', 'Quantisation');
|
|---|
| 22 | add_arg('a_bitrate|a=i', 'Audio bitrate');
|
|---|
| 23 | add_arg('v_bitrate|v=i', 'Video bitrate');
|
|---|
| 24 | add_arg('multipass!', 'Enable two-pass encoding.');
|
|---|
| 25 |
|
|---|
| 26 | sub new {
|
|---|
| 27 | my $class = shift;
|
|---|
| 28 | my $self = {
|
|---|
| 29 | 'cli' => qr/\bH.264\b/i,
|
|---|
| 30 | 'name' => 'Export to H.264 (using mencoder)',
|
|---|
| 31 | 'enabled' => 1,
|
|---|
| 32 | 'errors' => [],
|
|---|
| 33 | 'defaults' => {},
|
|---|
| 34 | };
|
|---|
| 35 | bless($self, $class);
|
|---|
| 36 |
|
|---|
| 37 | # Initialize the default parameters
|
|---|
| 38 | $self->load_defaults();
|
|---|
| 39 |
|
|---|
| 40 | # Verify any commandline or config file options
|
|---|
| 41 | die "Audio bitrate must be > 0\n" unless (!defined $self->val('a_bitrate') || $self->{'a_bitrate'} > 0);
|
|---|
| 42 | die "Video bitrate must be > 0\n" unless (!defined $self->val('v_bitrate') || $self->{'v_bitrate'} > 0);
|
|---|
| 43 | die "Width must be > 0\n" unless (!defined $self->val('width') || $self->{'width'} =~ /^\s*\D/ || $self->{'width'} > 0);
|
|---|
| 44 | die "Height must be > 0\n" unless (!defined $self->val('height') || $self->{'height'} =~ /^\s*\D/ || $self->{'height'} > 0);
|
|---|
| 45 |
|
|---|
| 46 | # VBR, multipass, etc.
|
|---|
| 47 | if ($self->val('multipass')) {
|
|---|
| 48 | $self->{'vbr'} = 1;
|
|---|
| 49 | }
|
|---|
| 50 | elsif ($self->val('quantisation')) {
|
|---|
| 51 | die "Quantisation must be a number between 1 and 31 (lower means better quality).\n" if ($self->{'quantisation'} < 1 || $self->{'quantisation'} > 31);
|
|---|
| 52 | $self->{'vbr'} = 1;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | # Initialize and check for mencoder
|
|---|
| 56 | $self->init_mencoder();
|
|---|
| 57 |
|
|---|
| 58 | # Any errors? disable this function
|
|---|
| 59 | $self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
|
|---|
| 60 | # Return
|
|---|
| 61 | return $self;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | # Load default settings
|
|---|
| 65 | sub load_defaults {
|
|---|
| 66 | my $self = shift;
|
|---|
| 67 | # Load the parent module's settings
|
|---|
| 68 | $self->SUPER::load_defaults();
|
|---|
| 69 | # Not really anything to add
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | # Gather settings from the user
|
|---|
| 73 | sub gather_settings {
|
|---|
| 74 | my $self = shift;
|
|---|
| 75 | # Load the parent module's settings
|
|---|
| 76 | $self->SUPER::gather_settings();
|
|---|
| 77 | # Audio Bitrate
|
|---|
| 78 | $self->{'a_bitrate'} = query_text('Audio bitrate?',
|
|---|
| 79 | 'int',
|
|---|
| 80 | $self->val('a_bitrate'));
|
|---|
| 81 | # Video Bitrate
|
|---|
| 82 | $self->{'v_bitrate'} = query_text('Video bitrate?',
|
|---|
| 83 | 'int',
|
|---|
| 84 | $self->val('v_bitrate'));
|
|---|
| 85 |
|
|---|
| 86 | # Query the resolution
|
|---|
| 87 | $self->query_resolution();
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | sub export {
|
|---|
| 91 | my $self = shift;
|
|---|
| 92 | my $episode = shift;
|
|---|
| 93 | # Build the mencoder string
|
|---|
| 94 | my $params = " -vf scale=$self->{'width'}:$self->{'height'}";
|
|---|
| 95 | # Add the temporary file to the list
|
|---|
| 96 | push @tmpfiles, "/tmp/h264.$$.log";
|
|---|
| 97 | # Back up the path and use /dev/null for the first pass
|
|---|
| 98 | my $path_bak = $self->{'path'};
|
|---|
| 99 | $self->{'path'} = '/dev/null';
|
|---|
| 100 | # First pass
|
|---|
| 101 | print "First pass...\n";
|
|---|
| 102 | $self->{'mencoder_xtra'} = " $params"
|
|---|
| 103 | ." -passlogfile /tmp/h264.$$.log"
|
|---|
| 104 | ." -oac copy"
|
|---|
| 105 | ." -ovc x264 -x264encopts pass=1:bitrate=$self->{'v_bitrate'}:turbo=2:me=umh:me_range=24:dct_decimate:nointerlaced:no8x8dct:nofast_pskip:trellis=0:partitions=p8x8,b8x8,i4x4:mixed_refs:keyint=300:keyint_min=30:frameref=3:bframes=3:b_adapt:nob_pyramid:weight_b:subq=7:chroma_me:nocabac:deblock:nossim:nopsnr:level_idc=31:threads=auto";
|
|---|
| 106 | $self->SUPER::export($episode, '', 1);
|
|---|
| 107 | # Restore the path
|
|---|
| 108 | $self->{'path'} = $path_bak;
|
|---|
| 109 | # Second pass
|
|---|
| 110 | print "Final pass...\n";
|
|---|
| 111 | $self->{'mencoder_xtra'} = " $params"
|
|---|
| 112 | ." -oac faac -faacopts mpeg=4:br=$self->{'a_bitrate'}:object=2 "
|
|---|
| 113 | ." -passlogfile /tmp/h264.$$.log"
|
|---|
| 114 | ." -ovc x264 -x264encopts pass=2:bitrate=$self->{'v_bitrate'}:me=umh:me_range=24:dct_decimate:nointerlaced:no8x8dct:nofast_pskip:trellis=0:partitions=p8x8,b8x8,i4x4:mixed_refs:keyint=300:keyint_min=30:frameref=3:bframes=3:b_adapt:nob_pyramid:weight_b:subq=7:chroma_me:nocabac:deblock:nossim:nopsnr:level_idc=31:threads=auto";
|
|---|
| 115 | $self->SUPER::export($episode, '.avi');
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | 1; #return true
|
|---|
| 119 |
|
|---|
| 120 | # vim:ts=4:sw=4:ai:et:si:sts=4
|
|---|