[mythtv-users] My ffmpeg nuvexport module so far

Michael J. Lynch mlynch at gcom.com
Tue Nov 30 19:09:34 UTC 2004


So...is this the hack that makes nuvexport run fast?  I'm a noob, so if 
that's what
this is, what do I do with it?  Just copy it to where the other 
"xxxx.pl" export
scripts are?  Is there anything else that needs to be done, like 
modifying the
nuvexport script?  Sorry about the obviously basic questions but I want to
export recordings at a decent rate and have about 10 minutes worth of 
experience
with perl and/or nuvexport.



Jonathan Markevich wrote:

> Here (finally) is my module that I have been using with the most 
> success for exporting MPEG1.  Notice that I declare a bunch of KVCD 
> parameters in here, but am not using them right now.  When I try to 
> change the frame rate it becomes really jerky, though the matrix does 
> make for some better compression.
>
> I haven't figured out resizing either.  It always works quite slowly 
> and comes out as a green screen with some kind of tearing to it.  I 
> left out the reference to the size in the ffmpeg call.  It just does a 
> straight, non-resized copy.
>
> You need the latest version of ffmpeg for this, otherwise the -aspect 
> option will fail.
>
> Comments?  Improvements?
>
> Have fun!
>
>------------------------------------------------------------------------
>
>#!/usr/bin/perl -w
>#Last Updated: 2004.11.28 (jmarkevich)
>#
>#  export::MPG
>#  Originally export::WMV by Gavin Hurlbut <gjhurlbu at gmail.com>
>#
>
>package export::MPG;
>    use base 'export::ffmpeg';
>
># Load the myth and nuv utilities, and make sure we're connected to the database
>    use nuv_export::shared_utils;
>    use nuv_export::ui;
>    use mythtv::db;
>    use mythtv::recordings;
>
># Load the following extra parameters from the commandline
>    $cli_args{'a_bitrate|a=i'}    = 1; # Audio bitrate
>    $cli_args{'v_bitrate|v=i'}    = 1; # Video bitrate
>    $cli_args{'height|v_res|h=i'} = 1; # Height
>    $cli_args{'width|h_res|w=i'}  = 1; # Width
>
>    sub new {
>        my $class = shift;
>        my $self  = {
>                     'cli'             => qr/\bmpg\b/i,
>                     'name'            => 'Export to MPG',
>                     'enabled'         => 1,
>                     'errors'          => [],
>                    # ffmpeg-related settings
>                     'noise_reduction' => 0,
>                     'deinterlace'     => 0,
>                     'crop'            => 0,,
>                    # MPG-specific settings
>                     'a_bitrate'       => 224,
>                     'v_bitrate'       => 1152,
>                     'width'           => 352,
>                     'height'          => 240,
>                    };
>        bless($self, $class);
>
>    # Initialize and check for ffmpeg
>        $self->init_ffmpeg();
>
>    # 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
>        if ($Args{'a_bitrate'}) {
>            $self->{'a_bitrate'} = $Args{'a_bitrate'};
>            die "Audio bitrate must be > 0\n" unless ($Args{'a_bitrate'} > 0);
>        }
>        else {
>            $self->{'a_bitrate'} = query_text('Audio bitrate?',
>                                              'int',
>                                              $self->{'a_bitrate'});
>        }
>    # Ask the user what video bitrate he/she wants
>        if ($Args{'v_bitrate'}) {
>            die "Video bitrate must be > 0\n" unless ($Args{'v_bitrate'} > 0);
>            $self->{'v_bitrate'} = $Args{'v_bitrate'};
>        }
>        elsif ($self->{'multipass'} || !$self->{'vbr'}) {
>            # make sure we have v_bitrate on the commandline
>            $self->{'v_bitrate'} = query_text('Video bitrate?',
>                                              'int',
>                                              $self->{'v_bitrate'});
>        }
>    # Ask the user what resolution he/she wants
>        if ($Args{'width'}) {
>            die "Width must be > 0\n" unless ($Args{'width'} > 0);
>            $self->{'width'} = $Args{'width'};
>        }
>        else {
>            $self->{'width'} = query_text('Width?',
>                                          'int',
>                                          $self->{'width'});
>        }
>        if ($Args{'height'}) {
>            die "Height must be > 0\n" unless ($Args{'height'} > 0);
>            $self->{'height'} = $Args{'height'};
>        }
>        else {
>            $self->{'height'} = query_text('Height?',
>                                           'int',
>                                           $self->{'height'});
>        }
>    }
>
>    sub export {
>        my $self    = shift;
>        my $episode = shift;
>    # Load nuv info
>        load_finfo($episode);
>
> my $kvcd_params = " -intra_matrix "
>   . "8,9,12,22,26,27,29,34,"
>   . "9,10,14,26,27,29,34,37,"
>   . "12,14,18,27,29,34,37,38,"
>   . "22,26,27,31,36,37,38,40,"
>   . "26,27,29,36,39,38,40,48,"
>   . "27,29,34,37,38,40,48,58,"
>   . "27,29,34,37,38,40,48,58,"
>   . "34,37,38,40,48,58,69,79"
>   . " -inter_matrix "   
>   . "16,18,20,22,24,26,28,30,"
>   . "18,20,22,24,26,28,30,32,"
>   . "20,22,24,26,28,30,32,34,"
>   . "22,24,26,30,32,32,34,36,"
>   . "24,26,28,32,34,34,36,38,"
>   . "26,28,30,32,34,36,38,40,"
>   . "28,30,32,34,36,38,42,42,"
>   . "30,32,34,36,38,40,42,44"
>   . " -g 24"
>   . " -r 23.976";
> 
>    # Build the ffmpeg string
>        $self->{'ffmpeg_xtra'} = " -b "  . $self->{'v_bitrate'}
>                               . " -vcodec mpeg1video"
># these are not quite working yet
>#. " " . $kvcd_params
>                               . " -aspect 4:3"
>                               . " -qmin 3 -qmax 13"
>                               . " -ar 44100 "
>                               . " -ab " . $self->{'a_bitrate'}
>                               . " -acodec mp2"
>                               . " -hq"
>#  . $self->{'width'} . "x" . $self->{'height'} # this is set in ffmpeg.pm module
>                               . " -f vcd";
>    # Execute the parent method
>        $self->SUPER::export($episode, ".mpg");
>    }
>
>1;  #return true
>
># vim:ts=4:sw=4:ai:et:si:sts=4
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>mythtv-users mailing list
>mythtv-users at mythtv.org
>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>  
>

-- 
Michael J. Lynch

What if the hokey pokey IS what it's all about -- author unknown




More information about the mythtv-users mailing list