0

I am trying to install FFMPEG-PHP for backend video conversion and to capture a thumbnail of the videos users of my website upload. However i am having problem and I am not sure what is it exactly.

Environment: Ubuntu Server 12.04 PHP5 and Apache2 (Did not use LAMP package. Installed separately.)

To install ffmpeg I followed this tutorial, http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide.

Works on command line: When I tried to convert from the command line, it works.

avconv -i test.mp4 test.flv - works ffmpeg -i test.mp4 test.flv - works, says that use avconv

Folder permission has been changed to R 777.

PhpInfo():

  • ffmpeg-php version: 0.6.0-svn
  • ffmpeg-php built on: Feb 25 2012 17:59:17
  • ffmpeg-php gd support: enabled
  • ffmpeg libavcodec version: Lavc53.34.0
  • ffmpeg libavformat version: Lavf53.20.0
  • ffmpeg swscaler version SwS2.1.0

I read somewhere to try the following code,

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

The above code should not give any output if the extension loaded successfully. And mine did not show any errors.

Code in PHP that is not working,

exec("ffmpeg -i test2.mp4 test2.flv", $command_output, $result);
if ($result !== 0) {
echo 'Command failed!<br>';
print_r($command_output);
die();
}
echo 'success!';
print_r($command_output);

It prints Command failed with as empty array, Array ( ).

Hope someone can help to guide me in this.

Haja Mohaideen
  • 157
  • 3
  • 18
  • Why are you using `exec()` if you have `ffmpeg-php` installed? Take a look at http://ffmpeg-php.sourceforge.net/doc/api/index.php for more information on how to use it. If you still want to use `exec()`, make sure to use correct file locations. I'm guessing `test2.mp4` is not in the same location as the PHP script you are running. What is the value of `$result`? – David Kuridža Jul 23 '12 at 06:02
  • test2.mp4 is in the same folder as my script as I created this just to test. '$movie = new ffmpeg_movie(test.mp4)', '$movie->getDuration()' returns the correct value. However, I am not sure how to convert from .mp4 to .flv using the url that referred. Also, I tried this tutorial, _http://youtubeclone.wordpress.com/2007/05/26/how-to-convertencode-files-to-flv-using-ffmpeg-php/_. However, it is not working. '$result' is not returning anything. – Haja Mohaideen Jul 23 '12 at 06:29
  • Interpreted your qn wrongly earlier for the $result. $result value is int(127). – Haja Mohaideen Jul 24 '12 at 05:58

1 Answers1

1

Thank you David for pointing out to the api. FFMPEG-PHP was working all this while. I am now able to create an image of the video. Code as below if anyone has similar problem.

Source: http://itwigle.com/twig/Capturing_video_thumbnails_with_PHP

<?php
if (! extension_loaded (ffmpeg)) exit ('ffmpeg was not loaded ');
$movie_file = "test2.mp4";

// Instantiates the class ffmpeg_movie so we can get the information you want the video  
$movie = new ffmpeg_movie($movie_file);  

//Need to create a GD image ffmpeg-php to work on it  
$image = imagecreatetruecolor($width, $height); 

//Create an instance of the frame with the class ffmpeg_frame  
$frame = new ffmpeg_frame($Image);  

//Choose the frame you want to save as jpeg  
echo $thumbnailOf = $movie->getFrameRate() * 5;  

//Receives the frame  
$frameImg = $movie->GetFrame($thumbnailOf);

// Resizes the frame to 200, 100
//$frameImg-> resize(200, 100);  

//Convert to a GD image  
$image = $frameImg->toGDImage(); 

//Save to disk.  
imagejpeg($image, $movie_file.'.jpg', 100); 
?>

But I am still having problem in converting the video from mp4 to flv. hope someone can help me out for the conversion.

Haja Mohaideen
  • 157
  • 3
  • 18
  • check http://stackoverflow.com/questions/7239380/phps-exec-not-executing-command-for-ffmpeg and http://stackoverflow.com/questions/4828083/ffmpeg-php-error-code-127 and – David Kuridža Jul 24 '12 at 07:05
  • It seems like permission error. I removed PHP5-ffmpeg plugin from PHP.ini. Now I am pointing to /usr/bin/ffmpeg. However, now the page does not even load when i access from web browser. But it works when I try in the terminal, PHP test.php. It does not throw any error. – Haja Mohaideen Jul 24 '12 at 08:15
  • Still no good. Tried '$cmd = '/usr/bin/ffmpeg 2>&1'; exec(escapeshellcmd($cmd), $stdout, $stderr); var_dump($stderr); var_dump($stdout); var_dump($cmd); exit;' Output is int(127) array(0) { } string(20) "/usr/bin/ffmpeg 2>&1" – Haja Mohaideen Jul 24 '12 at 09:39