Jump to content

conversion from avi,mpeg to flv using ffmpeg


alimziyan

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.