【问题标题】:FFMPEG PHP does not seem to workFFMPEG PHP 似乎不起作用
【发布时间】:2012-07-23 05:48:24
【问题描述】:

我正在尝试安装 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 libav格式版本:Lavf53.20.0
  • ffmpeg swscaler 版本 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);

它打印 Command failed with as empty array, Array ( ).

希望有人可以帮助指导我。

【问题讨论】:

  • 如果您安装了ffmpeg-php,为什么还要使用exec()?查看ffmpeg-php.sourceforge.net/doc/api/index.php 以获取有关如何使用它的更多信息。如果您仍想使用exec(),请确保使用正确的文件位置。我猜test2.mp4 与您正在运行的 PHP 脚本不在同一个位置。 $result 的值是多少?
  • test2.mp4 与我的脚本在同一个文件夹中,因为我创建它只是为了测试。 '$movie = new ffmpeg_movie(test.mp4)', '$movie->getDuration()' 返回正确的值。但是,我不确定如何使用引用的 url 从 .mp4 转换为 .flv。另外,我尝试了本教程,youtubeclone.wordpress.com/2007/05/26/…。但是,它不起作用。 '$result' 没有返回任何内容。
  • 之前为 $result 错误地解释了您的 qn。 $result 值为 int(127)。

标签: ffmpeg-php


【解决方案1】:

感谢 David 指出 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 时仍然遇到问题。希望有人可以帮助我进行转换。

【讨论】:

  • 好像是权限错误。我从 PHP.ini 中删除了 PHP5-ffmpeg 插件。现在我指向/usr/bin/ffmpeg。但是,现在当我从 Web 浏览器访问时,页面甚至没有加载。但是当我在终端 PHP test.php 中尝试时它可以工作。它不会抛出任何错误。
  • 还是不行。试过'$cmd ='/usr/bin/ffmpeg 2>&1'; exec(escapeshellcmd($cmd), $stdout, $stderr); var_dump($stderr); var_dump($stdout); var_dump($cmd);出口;'输出为 int(127) array(0) { } string(20) "/usr/bin/ffmpeg 2>&1"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-10
  • 2016-01-28
  • 2010-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多