Changeset 395
- Timestamp:
- 04/24/07 01:13:37 (1 year ago)
- Files:
-
- library/perl/trunk/FFmpeg-Command/Makefile.PL (modified) (1 diff)
- library/perl/trunk/FFmpeg-Command/lib/FFmpeg/Command.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
library/perl/trunk/FFmpeg-Command/Makefile.PL
r210 r395 14 14 'Class::ErrorHandler' => 0, 15 15 'IPC::Run' => 0, 16 'MIME::Types' => 0, 16 17 }, 17 18 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, library/perl/trunk/FFmpeg-Command/lib/FFmpeg/Command.pm
r272 r395 3 3 use warnings; 4 4 use strict; 5 our $VERSION = '0.0 6';5 our $VERSION = '0.07'; 6 6 7 7 use base qw( Class::Accessor::Fast Class::ErrorHandler ); … … 45 45 sub output_options { 46 46 my ( $self, $args ) = @_; 47 47 48 $self->output_file(delete $args->{file}); 48 49 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 } 49 67 50 68 my %device_option = ( … … 69 87 ); 70 88 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, 74 93 ); 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 } 75 108 76 109 for ( keys %output_option ){ … … 179 212 $ffmpeg->exec(); 180 213 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 181 238 # Execute ffmpeg with any options you like. 182 239 # This sample code takes a screnn shot. … … 269 326 Set the comment. 270 327 328 =item media 329 330 Set the media type (video or audio) of an output file.Default is 'video'. 331 332 =item auto_set_media 333 334 Set the media type of an output file automatically from an input file. 335 271 336 =back 272 337
