php - PHP-FFMpeg 未转换后(ffmpeg 错误)

标签 php ffmpeg ffmpeg-php

我已经安装了带有所有依赖项的 ffmpeg 服务器端,并对其进行了更新。然后用 Composer 安装 PHP-FFMpeg。测试了 ffmpeg 是否安装了 ssh conexion。

root@host [/opt/ffmpeg]# ffmpeg
ffmpeg version N-81322-ge8b355a Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
configuration: --disable-yasm
libavutil      55. 28.100 / 55. 28.100
libavcodec     57. 51.100 / 57. 51.100
libavformat    57. 46.100 / 57. 46.100
libavdevice    57.  0.102 / 57.  0.102
libavfilter     6. 51.100 /  6. 51.100
libswscale      4.  1.100 /  4.  1.100
libswresample   2.  1.100 /  2.  1.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options]     outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

但是当我尝试使用 php 脚本转换视频文件时,它会抛出一个很长的错误。
PHP代码:
<?PHP
include($_SERVER['DOCUMENT_ROOT']."/vendors/install/vendor/autoload.php");
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($_SERVER['DOCUMENT_ROOT'].'/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.wmv');
$video
       ->filters()
       ->synchronize();
$format = new FFMpeg\Format\Video\X264();
$format->on('progress', function ($video, $format, $percentage) {
    echo "$percentage % transcoded";});
$video
      ->save($format,$_SERVER['DOCUMENT_ROOT'].'/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.mp4');
?>

显示错误:
<b>Fatal error</b>:  Uncaught exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 'ffmpeg failed to execute command '/usr/local/bin/ffmpeg' '-y' '-i' '/home/user/working/resources/uploads/23097/2efeb41a1a7085a1dbd469c4895ac23e.wmv' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'libfaac' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes57ad320a1b685j794u/pass-57ad320a1b716' '/home/user/working/resources/uploads/23097/2efeb41a1a7085a1dbd469c4895ac23e.mp4'' in /home/user/working/vendors/install/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100↵Stack trace:↵#0 /home/user/working/vendors/install/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner-&gt;doExecutionFailure(''/usr/bin/ffmpe...')↵#1 / in <b>/home/user/working/vendors/install/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php</b> on line <b>168</b><br />↵"

然后我把上面显示的基本代码直接通过ssh运行了。
'/usr/local/bin/ffmpeg' '-y' '-i' '/home/user/working/resources/uploads/23097/2efeb41a1a7085a1dbd469c4895ac23e.wmv' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'libfaac' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes57ad320a1b685j794u/pass-57ad320a1b716' '/home/user/working/resources/uploads/23097/2efeb41a1a7085a1dbd469c4895ac23e.mp4'

这是我得到的回应:
ffmpeg version N-81322-ge8b355a Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
  configuration: --disable-yasm
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.100 / 57. 51.100
  libavformat    57. 46.100 / 57. 46.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 51.100 /  6. 51.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, asf, from '/home/user/working/resources/uploads/23097/2efeb41a1a7085a1dbd469c4895ac23e.wmv':
  Metadata:
    SfOriginalFPS   : 299700
    WMFSDKVersion   : 11.0.6001.7000
    WMFSDKNeeded    : 0.0.0.0000
    comment         : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball
    title           : Wildlife in HD
    copyright       : © 2008 Microsoft Corporation
    IsVBR           : 0
    DeviceConformanceTemplate: AP@L3
  Duration: 00:00:30.09, start: 0.000000, bitrate: 6977 kb/s
    Stream #0:0(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 2 channels, fltp, 192 kb/s
    Stream #0:1(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x720, 5942 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc
Unknown encoder 'libx264'

我的问题是下一步该怎么做?我浪费了 3 天的时间来完成这项工作,这是我来得最远的一次。如何测试是否正确安装了 libx264?如果它没有正确安装,我该如何重新安装或使其工作?

经过一些修改

我使用了一个已经安装的 ffmpeg,并删除了一些命令(默认情况下是相同的),这次我只使用了命令行。

请求
'/home/user/working/vendors/install/ffmpeg-git-20160813-64bit-static/ffmpeg' '-y' '-i' '/home/user/working/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.wmv' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-vcodec' 'libx264' '-c:a' 'aac' '-b:v' '1000k' '-b:a' '128k' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes57b053ce14a12ljm8a/pass-57b053ce14ad3' '/home/user/working/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.mp4'

新结果:
ffmpeg version N-81328-gceab04f-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.1 (Debian 5.4.1-1) 20160803
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr --enable-frei0r --enable-libfribidi --disable-indev=sndio --disable-outdev=sndio --enable-librtmp --enable-libmfx --enable-libzimg --cc=gcc-5
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 51.102 / 57. 51.102
  libavformat    57. 46.101 / 57. 46.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 51.100 /  6. 51.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, asf, from '/home/user/working/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.wmv':
  Metadata:
    SfOriginalFPS   : 299700
    WMFSDKVersion   : 11.0.6001.7000
    WMFSDKNeeded    : 0.0.0.0000
    comment         : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball
    title           : Wildlife in HD
    copyright       : © 2008 Microsoft Corporation
    IsVBR           : 0
    DeviceConformanceTemplate: AP@L3
  Duration: 00:00:30.09, start: 0.000000, bitrate: 6977 kb/s
    Stream #0:0(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 2 channels, fltp, 192 kb/s
    Stream #0:1(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x720, 5942 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc
-async is forwarded to lavfi similarly to -af aresample=async=1:min_hard_comp=0.100000:first_pts=0.
[libx264 @ 0x442f5c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x442f5c0] ratecontrol_init: can't open stats file
Output #0, mp4, to '/home/user/working/resources/uploads/96048/ffd3c5e349fa5745159deef163b5c253.mp4':
  Metadata:
    SfOriginalFPS   : 299700
    WMFSDKVersion   : 11.0.6001.7000
    WMFSDKNeeded    : 0.0.0.0000
    comment         : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball
    title           : Wildlife in HD
    copyright       : © 2008 Microsoft Corporation
    IsVBR           : 0
    DeviceConformanceTemplate: AP@L3
    Stream #0:0(eng): Unknown: none
    Metadata:
      start_time      : 0
      encoder         : Lavc57.51.102 libx264
    Stream #0:1(eng): Unknown: none
    Metadata:
      encoder         : Lavc57.51.102 aac
Stream mapping:
  Stream #0:1 -> #0:0 (vc1 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (wmav2 (native) -> aac (native))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

最佳答案

不支持 x264

您的 ffmpeg未编译为支持通过 libx264 进行编码:缺少 --enable-gpl --enable-libx264在配置行中。最简单的解决方法是 download an already compiled ffmpeg binary并将您的脚本指向它。

其他的东西

您的 ffmpeg--disable-yasm .这很糟糕,会使事情变慢。

你的命令一团糟,看起来像是 2006 年的东西。你应该使用 x264 encoding presets而不是试图声明大量选项。删除 -refs , -coder , -sc_threshold , -flags +loop , -me_range , -subq , -i_qfactor , -qcomp , -qdiff , 和 -trellis因为这些都是默认自动处理的。

最好让这个编码器自动选择合适的线程数,所以去掉-threads 12 .

有传言说 libfaac 支持将从 FFmpeg 中删除。您的命令使用 -acodec libfaac但是你的ffmpeg没有编译来支持它。还有更好的选择,例如 libfdk_aac 或原生 FFmpeg AAC 编码器 (-c:a aac)。

关于php - PHP-FFMpeg 未转换后(ffmpeg 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38927352/

相关文章:

python-3.x - 结合 OpenCV 和 FFMPEG 以实现更快的视频处理

python - 一个接一个地运行两个ffmpeg命令

centos 6上的ffmpeg安装错误

video - 无法使用ffmpeg转码器转码视频

php - 支持模糊搜索的最容易实现的站点搜索应用程序是什么?

php - 从 Javascript->HTML->PHP 传递文本

php - html和主流浏览器支持的不同视频格式

php - 找不到类 'FFMpeg\FFMpeg\Coordinate\Dimension'

php - 如何计算数据库中的列,如果为空则返回 0 PHP

php - 如何在 PhpDoc 文档 block 中使用 NetBeans 和 SVN @version 标记?