2012-07-23 136 views
0

我想安裝FFMPEG-PHP進行後端視頻轉換,並捕獲我網站上傳的視頻用戶的縮略圖。但是我有問題,我不確定它到底是什麼。FFMPEG PHP似乎並不工作

環境: Ubuntu服務器12.04 PHP5和Apache2的(沒有用LAMP包單獨安裝。)

要安裝的ffmpeg我跟着本教程中,http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide

在命令行上工作: 當我試圖從命令行轉換,它的工作原理。

avconv -i test.mp4 test.flv - 工程 ffmpeg -i test.mp4 test.flv - 作品說,使用avconv

文件夾的權限已改爲R 777

phpinfo()函數:

  • 的ffmpeg的PHP版本: 0.6.0-svn
  • ffmpeg-php建立於:2012年2月25日17:59:17
  • 的ffmpeg的PHP GD支持:啓用
  • ffmpeg的libavcodec的版本:Lavc53.34.0
  • 的ffmpeg了libavformat版本:Lavf53.20.0
  • 的ffmpeg軟件縮放版本SwS2.1.0

我讀的地方試試以下代碼,

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

上述代碼在擴展加載成功時不應該給出任何輸出。而且我沒有顯示任何錯誤。

代碼在PHP不工作,

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); 

它打印命令失敗,因爲空數組,數組()。

希望有人能幫助引導我。

+0

如果你安裝了'ffmpeg-php',你爲什麼要用'exec()'?查看http://ffmpeg-php.sourceforge.net/doc/api/index.php瞭解如何使用它的更多信息。如果您仍想使用'exec()',請確保使用正確的文件位置。我猜測'test2.mp4'與您正在運行的PHP腳本不在同一個位置。 '$ result'的值是多少? – 2012-07-23 06:02:16

+0

test2.mp4與我的腳本位於同一個文件夾中,因爲我只是爲了測試而創建它。 '$ movie = new ffmpeg_movie(test.mp4)','$ movie-> getDuration()'返回正確的值。但是,我不知道如何使用引用的url從.mp4轉換爲.flv。另外,我嘗試了這個教程,_http://youtubeclone.wordpress.com/2007/05/26/how-to-convertencode-files-to-flv-using-ffmpeg-php/_。但是,它不起作用。 '$ result'沒有返回任何東西。 – 2012-07-23 06:29:53

+0

爲$結果提前解釋了你的qn。 $結果值是int(127)。 – 2012-07-24 05:58:44

回答

2

謝謝大衛指出的API。 FFMPEG-PHP一直在努力。我現在能夠創建視頻的圖像。代碼如下,如果任何人有類似的問題。

來源: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); 
?> 

但我還是從MP4轉換視頻到FLV有問題。希望有人能幫助我轉換。

+0

檢查http://stackoverflow.com/questions/7239380/phps-exec-not-executing-command-for-ffmpeg和http://stackoverflow.com/questions/4828083/ffmpeg-php-error-code-127和 – 2012-07-24 07:05:55

+0

這似乎是權限錯誤。我從PHP.ini中刪除了PHP5-ffmpeg插件。現在我指向/ usr/bin/ffmpeg。但是,現在當我從Web瀏覽器訪問時,該頁面甚至無法加載。但是,當我在終端,PHP test.php中嘗試時,它會起作用。它不會拋出任何錯誤。 – 2012-07-24 08:15:13

+0

仍然沒有好處。嘗試'$ cmd ='/ usr/bin/ffmpeg 2> &1'; exec(escapeshellcmd($ cmd),$ stdout,$ stderr); var_dump($ stderr); var_dump($ stdout); var_dump($ cmd); exit;'輸出爲int(127)數組(0){}字符串(20)「/ usr/bin/ffmpeg 2>&1」 – 2012-07-24 09:39:08