hi i use below code for video convert in flv.

code work perfectly but when the out put comes file become 0kb.

 $srcFile = "upload_v/veer.avi";

 $destFile = "upload_v/veer.flv";

    $ffmpegPath = "/usr/bin/ffmpeg";
    $flvtool2Path = "/usr/bin/flvtool2";

    $ffmpegObj = new ffmpeg_movie($srcFile);
    $srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
    $srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
    $srcFPS = $ffmpegObj->getFrameRate();
    $srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
    $srcAR = $ffmpegObj->getAudioSampleRate();
    //$srcWidth = 320;
    //$srcHeight = 240;
    //$command = $ffmpegPath . " -i " . $srcFile .  " -f flv -s " . $srcWidth . "x" .      $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile;

extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

$command =$ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile;        


$type='flv';
$size='512x384';
$quality='450000';
$audio='11025';





    if($type=="flv"){ $call="/usr/bin/ffmpeg -i ".$srcFile." -vcodec flv -f flv -r 30 -b ".$quality." -ab 128000 -ar ".$audio." -s ".$size." ".$destFile;}


    $convert = (popen($call." >/dev/null &", "r"));
        pclose($convert);

function makeMultipleTwo ($value) {
$sType = gettype($value/2);
if($sType == "integer") {
return $value;
} else {
return ($value-1);
}
}
  echo  $convert = shell_exec($command);
    if(!$convert)
    {
    echo "FAILED!!!";
    }
    else
    {
        echo "SUCCESS";
    }

Hi,

First we need to see if the ffmpeg is outputting an error. This is very important, because we don't know what are the missing parameters if there are any.

1. Make sure the directory is CHMOD to 0755 or 755 or 0777 or 777 depending on your server settings.

2. Let's ignore the flvtool2 function first, and work on the ffmpeg diagnostic before anything else.

3. Copy codes below and run it on your server.

<?php
## written by PoorBoy from veedeoo.com
## or veedeoo Junior Poster in Training from daniweb.com
## define ffmpeg location

$ffmpeg_loc = "/usr/bin/ffmpeg";
## define location of video to be converted to flv and some other settings
$input = "upload_v/veer.avi";
$a_freq = "44100";
$a_br = "64";
$v_br = "600";
$v_fr = "30";
$out_flv = "upload_v/veer.flv";
$encodeVideo = ($ffmpeg_loc." -i ".$input." -ar ".$a_feq." -ab ".$a_br."k -b ".$v_br."k -r ".$v_fr." -ac 2 -f flv -y -s 640x420 ".$out_flv);

## now we need to fire up the $encodeVideo through exec command..
## while the ffmpeg is being executed, we need to trap any errors it may have.
exec($encodeVideo." 2>&1", $res, $err);
$errorlog = '' ;
foreach ($res as $errodata) {
$erorlog .= $errodata."<br>" ;
}
## you can echo the error if you want, by uncommenting the code below
//echo $errorlog;

## or you can write it as an html page for you view on the browser.
$errordatapath = "upload_v/erroroutput.html" ;
$file = fopen($errordatapath, "w") ;
fwrite($file, $erorlog) ;
fclose($file) ;

?>

Run the script above, and wait for a few seconds or minutes depending on the length of your video. Direct your browser to the upload_v/erroroutput.html. If you don't see any error in there, meaning that ffmpeg-php is not properly installed on your server.

Please allow me clarify the misunderstanding about the fffmpeg-php extension. There are some cases where this extension is not properly installed, and can cause problem. To test if the extension is properly installed on your server, we need to run the test separate and apart from the ffmpeg encoding exec command. To test if the ffmpeg-php extension is properly installed in your server, copy codes below and then run on your server.

<?php
## again, this is written by me PoorBoy from veedeoo.com 
## or veedeoo Junior Poster in Training from daniweb.com

$input = "upload_v/veer.avi";
if($veedeoo = new ffmpeg_movie($input)){
$duration = $veedeoo->getDuration(); 
echo $duration;

## if everything is well, you should be reading the video duration on your browser.
}

?>

Warning! I don't have the time to test my codes above, but I am pretty sure it will work, because it is almost the same codes I have on my open source youtube clone script.

Please let me know what are the errors (if any), so that we can move on to next diagnostic procedures.

What I meant by "1. Make sure the directory is CHMOD to 0755 or 755 or 0777 or 777 depending on your server settings." is the upload_v directory. The script needs to write in this directory..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.