Nasser wrote:
Hello, I've written a little perl script based on the example at the FFmpeg::Command cpan page. The code is as follows:
Always use strict; use warnings; and declare all of your variables using 'my' close to their point of use. That will stop a lot of simple errors from occurring.
use FFmpeg::Command; use Carp;
Why are you using Carp here? A call to die should be sufficient.
$input_file = "/tmp/NS051.avi"; print "Input file: $input_file\n"; $output_file = "/tmp/NS051.m4v"; print "Output file: $output_file\n"; print "Creating new ffmpeg command instance..."; $ffmpeg = FFmpeg::Command->new('/usr/local/bin/ffmpeg') || die("unable to create instance.\n"); print "success.\n"; print "Setting up file input options..."; $ffmpeg->input_options({file => $input_file}) || Carp::cluck "unable to set options:\n";
Looking at the documentation for this module, it doesn't say anything about the methods' return values anywhere. Why do you think it will return a true value for success?
print "done.\n"; print "Setting up the timeout to 300 seconds..."; $ffmpeg->timeout(300) || Carp::cluck("unable to set timeout.\n");; print "done.\n"; #convert a video into ipod playable format. print "Setting up the file output options..."; $ffmpeg->output_options({file => $output_file,device => 'ipod'}) || Carp::cluck("unable to set options.\n");; print "done.\n"; print "Executing the ffmpeg command, with the selected options..."; $ffmpeg->exec() || die("unable to execute.\n"); print "completed.\n" exit; ------ When I run it, I get this: Input file: /tmp/NS051.avi Output file: /tmp/NS051.m4v Creating new ffmpeg command instance...success. unable to set options: at /home/rock/bin/shazam line 20 Setting up file input options...done. Setting up the timeout to 300 seconds...done. unable to set options. at /home/rock/bin/shazam line 32 Setting up the file output options...done. Executing the ffmpeg command, with the selected options...unable to execute. ----- Now what I don't understand is why I get the "unable to set options:" before "Setting up file input options" even though in the script the later should have been executed before, so the error message should at least have appeared after the "Setting up file input options".
You are buffering the output to STDOUT, and it will only get flushed when the buffer is full. You can setup automatic flushing with: use IO::Handle; autoflush STDOUT; at the start of your code.
The second thing is, how come setting up the options failed? It is somewhat exactly like the example given on the page at http://search.cpan.org/~mizzy/FFmpeg-Command-0.07/lib/FFmpeg/Command.pm What am I doing wrong? Or is there a problem with the actual module?
Maybe there's a problem with the module, maybe not. You are certainly testing for undocumented return values. Did your program create an output file? HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/