Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top