ffmpeg:转换为mp4但出现错误:不支持的编解码器

时间:2013-02-10 13:51:05

标签: php ffmpeg

我正在使用最新版本的ffmpeg在php中转换视频文件:

exec("ffmpeg -y -i capture.wmv capture.mp4 2>&1", $output);
var_dump($output);

结果如下:

array(21) {
  [0]=>
  string(99) "FFmpeg version SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.3, Copyright (c) 2000-2009 Fabrice Bellard, et al."
  [1]=>
  string(451) "  configuration: --extra-version=4:0.5.9-0ubuntu0.10.04.3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static"
  [2]=>
  string(35) "  libavutil     49.15. 0 / 49.15. 0"
  [3]=>
  string(35) "  libavcodec    52.20. 1 / 52.20. 1"
  [4]=>
  string(35) "  libavformat   52.31. 0 / 52.31. 0"
  [5]=>
  string(35) "  libavdevice   52. 1. 0 / 52. 1. 0"
  [6]=>
  string(35) "  libavfilter    0. 4. 0 /  0. 4. 0"
  [7]=>
  string(35) "  libswscale     0. 7. 1 /  0. 7. 1"
  [8]=>
  string(35) "  libpostproc   51. 2. 0 / 51. 2. 0"
  [9]=>
  string(43) "  built on Jan 24 2013 19:42:59, gcc: 4.4.3"
  [10]=>
  string(34) "Input #0, asf, from 'capture.wmv':"
  [11]=>
  string(60) "  Duration: 00:04:11.45, start: 3.000000, bitrate: 1755 kb/s"
  [12]=>
  string(62) "    Stream #0.0: Audio: wmav2, 44100 Hz, stereo, s16, 128 kb/s"
  [13]=>
  string(82) "    Stream #0.1: Video: wmv2, yuv420p, 1280x720, 1600 kb/s, 1k tbr, 1k tbn, 1k tbc"
  [14]=>
  string(33) "Output #0, mp4, to 'capture.mp4':"
  [15]=>
  string(83) "    Stream #0.0: Video: mpeg4, yuv420p, 1280x720, q=2-31, 200 kb/s, 90k tbn, 1k tbc"
  [16]=>
  string(62) "    Stream #0.1: Audio: 0x0000, 44100 Hz, stereo, s16, 64 kb/s"
  [17]=>
  string(15) "Stream mapping:"
  [18]=>
  string(21) "  Stream #0.1 -> #0.0"
  [19]=>
  string(21) "  Stream #0.0 -> #0.1"
  [20]=>
  string(40) "Unsupported codec for output stream #0.1"
}

我需要一个标准的mp4文件,用于在网页上播放html5。哪里可能是问题?是不是安装了手抄本?或者控制台命令有问题吗?

编辑: 使用静态构建后,我尝试使用

将wmv转换为mp4
exec("/www/htdocs/xxxx/video/ffmpeg -y -i capture.wmv capture.mp4 2>&1", $output);

结果文件的大小只有几个字节 - 这是输出:

array(40) {
  [0]=>
  string(77) "ffmpeg version N-49805-gfd6a021 Copyright (c) 2000-2013 the FFmpeg developers"
  [1]=>
  string(61) "  built on Feb 11 2013 05:23:18 with gcc 4.6 (Debian 4.6.3-1)"
  [2]=>
  string(609) "  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx"
  [3]=>
  string(40) "  libavutil      52. 17.101 / 52. 17.101"
  [4]=>
  string(40) "  libavcodec     54. 91.102 / 54. 91.102"
  [5]=>
  string(40) "  libavformat    54. 62.100 / 54. 62.100"
  [6]=>
  string(40) "  libavdevice    54.  3.103 / 54.  3.103"
  [7]=>
  string(40) "  libavfilter     3. 37.101 /  3. 37.101"
  [8]=>
  string(40) "  libswscale      2.  2.100 /  2.  2.100"
  [9]=>
  string(40) "  libswresample   0. 17.102 /  0. 17.102"
  [10]=>
  string(40) "  libpostproc    52.  2.100 / 52.  2.100"
  [11]=>
  string(54) "Guessed Channel Layout for  Input Stream #0.0 : stereo"
  [12]=>
  string(34) "Input #0, asf, from 'capture.wmv':"
  [13]=>
  string(11) "  Metadata:"
  [14]=>
  string(32) "    WMFSDKNeeded    : 0.0.0.0000"
  [15]=>
  string(32) "    DeviceConformanceTemplate: @"
  [16]=>
  string(37) "    WMFSDKVersion   : 12.0.7601.17514"
  [17]=>
  string(23) "    IsVBR           : 0"
  [18]=>
  string(60) "  Duration: 00:04:13.40, start: 0.000000, bitrate: 1742 kb/s"
  [19]=>
  string(90) "    Stream #0:0(ger): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 128 kb/s"
  [20]=>
  string(125) "    Stream #0:1(ger): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 1280x720, 1600 kb/s, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc"
  [21]=>
  string(35) "[libx264 @ 0x2f082e0] using SAR=1/1"
  [22]=>
  string(63) "[libx264 @ 0x2f082e0] MB rate (3600000) > level limit (2073600)"
  [23]=>
  string(88) "[libx264 @ 0x2f082e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX"
  [24]=>
  string(45) "[libx264 @ 0x2f082e0] profile High, level 5.2"
  [25]=>
  string(684) "[libx264 @ 0x2f082e0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00"
  [26]=>
  string(33) "Output #0, mp4, to 'capture.mp4':"
  [27]=>
  string(11) "  Metadata:"
  [28]=>
  string(32) "    WMFSDKNeeded    : 0.0.0.0000"
  [29]=>
  string(32) "    DeviceConformanceTemplate: @"
  [30]=>
  string(37) "    WMFSDKVersion   : 12.0.7601.17514"
  [31]=>
  string(23) "    IsVBR           : 0"
  [32]=>
  string(35) "    encoder         : Lavf54.62.100"
  [33]=>
  string(122) "    Stream #0:0(ger): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 16k tbn, 1k tbc"
  [34]=>
  string(90) "    Stream #0:1(ger): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s"
  [35]=>
  string(15) "Stream mapping:"
  [36]=>
  string(39) "  Stream #0:1 -> #0:0 (wmv2 -> libx264)"
  [37]=>
  string(45) "  Stream #0:0 -> #0:1 (wmav2 -> libvo_aacenc)"
  [38]=>
  string(31) "Press [q] to stop, [?] for help"
  [39]=>
  string(96) "frame=  158 fps=0.0 q=33.0 size=       0kB time=00:00:00.10 bitrate=   3.6kbits/s dup=155 drop=0"
}

slhck - 谢谢你的提示 - 你看到了问题吗?

1 个答案:

答案 0 :(得分:4)

您的FFmpeg版本是0.5.9,来自2009年(!)的分支。机会是问题是由于古老的版本,并没有必要尝试解决完全不支持的事情。据我所知,FFmpeg无法找到合适的音频编解码器来编码视频。您也没有任何外部AAC或MP3编码器。

在任何情况下:安装较新版本。通过compiling it yourselfdownloading a static build执行此操作。


要制作支持HTML5的MP4视频,您可能会明确选择具有Baseline配置文件(以适应移动设备)和AAC音频的H.264编码视频:

ffmpeg -i capture.wmv -c:v libx264 -profile:v baseline -c:a aac -strict experimental -b:a 192k out.mp4

要更改视频质量,请添加-crf选项,其值介于18-28(默认为23)。降低意味着更好的质量有关详细信息,请参阅FFmpeg Wiki上的x264 Encoding Guide

您的视频应该包含文件开头的MOOV原子,这样您的用户就可以立即开始流式传输内容(否则他们必须下载整个文件)。您可以在编码时设置:

ffmpeg -i [stuff from above…] -movflags faststart out.mp4

如果您有支持FAAC的FFmpeg(请与ffmpeg -codecs | grep libfaac联系),您也可以使用以下内容,类似于上述内容:

ffmpeg -i -c:v libx264 -profile:v baseline -c:a libfaac -q:a 100 out.mp4

在这里,您将获得更高质量的VBR AAC音频,而不是上面的固定比特率流。质量以百分比表示,默认值为100。