alimziyan Posted August 27, 2011 Share Posted August 27, 2011 Hi, I am using a php script for converting avi,mpeg files to flv with ffmpeg.my code is $srcFile = "uploads/flame.avi"; $destFile = "uploads/flame.flv"; $ffmpegPath = "/usr/bin/ffmpeg"; $flvtool2Path = "/usr/bin/flvtool2"; $ffmpegObj = new ffmpeg_movie($srcFile); $srcWidth = 320; $srcHeight = 240; $command = $ffmpegPath . " -i " . $srcFile . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile; $convert = exec($command); if(!$convert) { echo "FAILED!!!"; } else { echo "SUCCESS"; } I can create a flv file using this script.But sometimes it creates a flv file with size 0 k.I don't know why this is happening.With the same avi file,sometimes it creates correct flv file and sometimes flv with size 0k.How can I confirm whether the conversion is success. In both the cases it displays SUCCESS. Quote Link to comment https://forums.phpfreaks.com/topic/245811-conversion-from-avimpeg-to-flv-using-ffmpeg/ Share on other sites More sharing options...
Clarkeez Posted August 27, 2011 Share Posted August 27, 2011 I'm thinking maybe you could check the filesize before processing the success/error messages. if(!$convert || $outputfileSize == 0kb): echo "error"; else: echo "success"; endif; Quote Link to comment https://forums.phpfreaks.com/topic/245811-conversion-from-avimpeg-to-flv-using-ffmpeg/#findComment-1262575 Share on other sites More sharing options...
alimziyan Posted August 29, 2011 Author Share Posted August 29, 2011 Thanks for your reply..But may I know why ffmpeg command produces strange result.Sometimes it neatly converts avi to flv. And sometimes the same avi is converted to 0 size flv.. Quote Link to comment https://forums.phpfreaks.com/topic/245811-conversion-from-avimpeg-to-flv-using-ffmpeg/#findComment-1263045 Share on other sites More sharing options...
Psycho Posted August 29, 2011 Share Posted August 29, 2011 Thanks for your reply..But may I know why ffmpeg command produces strange result.Sometimes it neatly converts avi to flv. And sometimes the same avi is converted to 0 size flv.. The PHP code is simply executing the command. If you have validated that you are passing the exact same values and getting different results then it is likely a problem with ffmpeg. Perhaps you have an earlier process that had not yet complete when you call another and the application can't handle that. Or, perhaps, when you are checking the file the process had not yet completed - it won't be instantaneous. I suggest you check into the documentation for ffmpeg. However, Clarkeez's solution will not work. Your code is just calling the application to start the process. It certainly won't be done by the time PHP gets to the next line in the code. You would have to implement a process for PHP to continually check for the file and the file size every x seconds, with a maximum execute time of y seconds. So, if the file isn't created (with a filesize > 0) by the max timeout you can guesstimate that the process failed. Certainly not an ideal solution. Quote Link to comment https://forums.phpfreaks.com/topic/245811-conversion-from-avimpeg-to-flv-using-ffmpeg/#findComment-1263049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.