How to handle getAudioCodec Fatal errors?

86 views
Skip to first unread message

ffmpeg-php-newbe

unread,
Feb 11, 2009, 3:45:11 PM2/11/09
to ffmpeg-php
Hello, is there a way to handle the fatal error thrown by
getAudioCodec when trying to access a movie file with an unsupported
audio codec?

I have a bunch of videos I want ffmpeg-php to analyze, so I want to
loop thru the videos and get information from each video. However,
all php execution will stop at the first encounter of a video with an
unsupported audio codec. When execution stops, php will not get the
additional information of the video with the unsupported codec and
will not go on analyzing the rest of the videos.

I have used TRY or IF statements to catch other types of errors and
continue execution of the program, but these statements are not
working with the error generated by ffmpeg-php.

Please, any help as to how to handle these errors will be greatly
appreciated.

This is the error generated by php when it encounters the error:

Fatal error: Could not find decoder for testmovie.mov in /usr/home/me/
devphp/functions.php on line 9

Below is the function I am trying to use. If I change the "$audcodec
= @$movie->getAudioCodec();" line in the try statement to some other
line producing a different type of error, like trying to open an non-
existent folder, the program catches the error and continues
execution, but the program will not catch the audio codec error.

function getMovieInfo($movepath){
$movie = new ffmpeg_movie($movepath);
echo "Duration: ".formatime($movie->getDuration())."\n";
echo "File Name: ".$movie->getFilename()."\n";
echo "Frames: ".$movie->getFrameCount()."\n";
echo "vid Codec: ".$movie->getVideoCodec()."\n";
$audcodec = "";
try {
$audcodec = @$movie->getAudioCodec();
throw new Exception("Errormsg: $php_errormsg");
}catch (Exception $e) {
echo $e->getMessage(), "\n";
}
echo "Aud Codec: ".$audcodec."\n";
echo "Width: ".$movie->getFrameWidth()."\n";
echo "Height: ".$movie->getFrameHeight()."\n\n";
}

manupap1

unread,
Mar 2, 2009, 3:50:25 AM3/2/09
to ffmpeg-php
Hello,

I think it is not possible to handle php fatal errors with exceptions
or set_error_handler.
The only way I found is to patch the ffmpeg-php code to raise only a
php warning.
By looking the ffmpeg-php code I saw that this is the only exception
of the ffmpeg_movie object that is raised as a php error
I guess that's an oversight because I do not see any interest to block
the execution of the php script on this specific error.

My patch :
#######################################################
--- ffmpeg_movie.c 2009-03-02 08:49:37.000000000 +0100
+++ ffmpeg_movie.c 2009-03-02 08:50:17.000000000 +0100
@@ -501,7 +501,7 @@ static AVCodecContext* _php_get_decoder_
codec_id));
-
if (!decoder) {
- zend_error(E_ERROR, "Could not find decoder for %s",-
+ zend_error(E_WARNING, "Could not find decoder for %s",-
_php_get_filename(ffmovie_ctx));
return NULL;
}
#######################################################
Reply all
Reply to author
Forward
0 new messages