Changeset 395

Show
Ignore:
Timestamp:
04/24/07 01:13:37 (1 year ago)
Author:
miya
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/perl/trunk/FFmpeg-Command/Makefile.PL

    r210 r395  
    1414        'Class::ErrorHandler'   => 0, 
    1515        'IPC::Run'              => 0, 
     16        'MIME::Types'           => 0, 
    1617    }, 
    1718    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 
  • library/perl/trunk/FFmpeg-Command/lib/FFmpeg/Command.pm

    r272 r395  
    33use warnings; 
    44use strict; 
    5 our $VERSION = '0.06'; 
     5our $VERSION = '0.07'; 
    66 
    77use base qw( Class::Accessor::Fast Class::ErrorHandler ); 
     
    4545sub output_options { 
    4646    my ( $self, $args ) = @_; 
     47 
    4748    $self->output_file(delete $args->{file}); 
    4849    my $device = delete $args->{device} || 'ipod'; 
     50    my $media  = delete $args->{media}  || 'video'; 
     51 
     52    if ( delete $args->{auto_set_media} ) { 
     53        unless ( $self->input_file ) { 
     54            $self->error('You must call input_file() or input_options() for setting input file name before calling output_options() when you set auto_set_media to 1.'); 
     55            return; 
     56        } 
     57        require MIME::Types; 
     58        my $myme = MIME::Types->new; 
     59        $media = $mime->mimeTypeOf( $self->input_file ); 
     60        $media =~ s!(.[^/]+)/!$1!; 
     61    } 
     62 
     63    if ( $media ne 'video' and $media 'audio' ) { 
     64        $self->error("media '$media' is not valid.'video' or 'audio' is valid."); 
     65        return; 
     66    } 
    4967 
    5068    my %device_option = ( 
     
    6987    ); 
    7088 
    71     my %output_option = ( 
    72         %{ $device_option{$device} }, 
    73         %$args, 
     89    my %audio_option = ( 
     90        audio_codec         => 'mp3', 
     91        audio_sampling_rate => 48000, 
     92        audio_bit_rate      => 128, 
    7493    ); 
     94 
     95    my %output_option; 
     96    if ( $media eq 'video' ) { 
     97        %output_option = ( 
     98            %{ $device_option{$device} }, 
     99            %$args, 
     100        ); 
     101    } 
     102    else { 
     103        %output_option = ( 
     104            %audio_option, 
     105            %$args, 
     106        ); 
     107    } 
    75108 
    76109    for ( keys %output_option ){ 
     
    179212    $ffmpeg->exec(); 
    180213 
     214    # Convert a audio file into a mp3 formatted auto file. 
     215    $ffmed->output_options({ 
     216        media => 'audio', 
     217    }); 
     218 
     219    $ffmpeg->exec(); 
     220 
     221    # Convert a audio file into a aac formatted auto file. 
     222    $ffmed->output_options({ 
     223        media               => 'audio', 
     224        audio_codec         => 'aac', 
     225        audio_sampling_rate => 48000, 
     226        audio_bit_rate      => 128, 
     227    }); 
     228 
     229    $ffmpeg->exec(); 
     230 
     231    # Detect media type of an input file automatically and set output options automatically for the media type. 
     232    $ffmed->output_options({ 
     233        auto_set_media => 1, 
     234    }); 
     235 
     236    $ffmpeg->exec(); 
     237 
    181238    # Execute ffmpeg with any options you like. 
    182239    # This sample code takes a screnn shot. 
     
    269326Set the comment. 
    270327 
     328=item media 
     329 
     330Set the media type (video or audio) of an output file.Default is 'video'. 
     331 
     332=item auto_set_media 
     333 
     334Set the media type of an output file automatically from an input file. 
     335 
    271336=back 
    272337