Linux 使用 ffmpeg 将视频转换为 MP4 (H.264/AAC)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1839841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert a video to MP4 (H.264/AAC) with ffmpeg
提问by user176455
If I don't make a mistake, Safari currently need MP4 (H.264/AAC) video encoded for the HTML5 <video>
element.
如果我没记错的话,Safari 目前需要为 HTML5<video>
元素编码的 MP4 (H.264/AAC) 视频。
So I tried to convert a video to this format with ffmpeg
. However when I enter the shell command ffmpeg -i video.flv video.mp4
, the returned error is :
所以我尝试将视频转换为这种格式ffmpeg
。但是,当我输入 shell 命令时ffmpeg -i video.flv video.mp4
,返回的错误是:
Seems stream 0 codec frame rate differs from container frame rate: 2000.00 (2000/1) -> 29.92 (359/12) Input #0, flv, from 'video.flv':
Duration: 00:05:01.20, start: 0.000000, bitrate: 66 kb/s Stream #0.0: Video: h264, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 66 kb/s, 29.92 tbr, 1k tbn, 2k tbc Stream #0.1: Audio: aac, 22050 Hz, stereo, s16 Output #0, mp4, to 'video.mp4': Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.92 tbc Stream #0.1: Audio: 0x0000, 22050 Hz, stereo, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0
Stream #0.1 -> #0.1 Unsupported codec for output stream #0.1
似乎流 0 编解码器帧速率与容器帧速率不同:2000.00 (2000/1) -> 29.92 (359/12) Input #0, flv, from 'video.flv':
Duration: 00:05:01.20, start: 0.000000 , 比特率:66 kb/s Stream #0.0:视频:h264、yuv420p、320x240 [PAR 1:1 DAR 4:3]、66 kb/s、29.92 tbr、1k tbn、2k tbc Stream #0.1:音频:ac 22050 Hz,立体声,s16 输出 #0,mp4,到“video.mp4”:流 #0.0:视频:mpeg4,yuv420p,320x240 [PAR 1:1 DAR 4:3],q=2-31,200 kb/ s、90k tbn、29.92 tbc 流 #0.1:音频:0x0000、22050 Hz、立体声、s16、64 kb/s 流映射:流 #0.0 -> #0.0
流 #0.1 -> #0.1 输出流 #0 不支持的编解码器。
An AAC codec is required but I'm quite newbie with ubuntu and I dont really now how to fix this problem. I'm using Ubuntu 9.10 Karmik Koala (for amd64).
需要一个 AAC 编解码器,但我是 ubuntu 的新手,我现在真的不知道如何解决这个问题。我正在使用 Ubuntu 9.10 Karmik Koala(用于 amd64)。
Thank you very much. :)
非常感谢。:)
回答by mouviciel
You need to compile ffmpeg with an AAC encoder. You can find one at AudioCoding.
您需要使用 AAC 编码器编译 ffmpeg。您可以在AudioCoding找到一个。
回答by axel_c
You can also try adding the Motumedia PPAto your apt sources and update your ffmpeg packages.
您还可以尝试将Motumedia PPA添加到您的 apt 源并更新您的 ffmpeg 包。
回答by Peter Cordes
Software patents led Debian/Ubuntu to disable the H.264 and AAC encoders in ffmpeg. See /usr/share/doc/ffmpeg/README.Debian.gz.
软件专利导致 Debian/Ubuntu 在 ffmpeg 中禁用 H.264 和 AAC 编码器。请参阅 /usr/share/doc/ffmpeg/README.Debian.gz。
So go install x264, mplayer/mencoder, and Nero's AAC encoder. (Or, if you want to use all Free software, and don't care so much about audio quality, then sudo aptitude install faac.)
所以去安装 x264、mplayer/mencoder 和 Nero 的 AAC 编码器。(或者,如果您想使用所有免费软件,并且不太关心音频质量,那么 sudo aptitude install faac。)
I don't remember if the medibuntu package of mencoder includes x264 vid encoding, since I build my own from git x264 and svn mplayer sources. (x264 is very actively developed, with significant quality and speed improvements frequently added.) http://git.videolan.org/?p=x264.git;a=summary
我不记得 mencoder 的 medibuntu 包是否包含 x264 vid 编码,因为我是从 git x264 和 svn mplayer 源构建自己的。(x264 的开发非常积极,经常添加显着的质量和速度改进。) http://git.videolan.org/?p=x264.git;a=summary
x264 is also packaged, but you should check that it's up to date enough to include weightpwith recent bugfixes, and even more recent speed improvements...
x264 也已打包,但您应该检查它是否是最新的,以将weightp包含在最近的错误修正中,以及最近的速度改进......
Or if you're already willing to convert from .flv, instead of going from the high-quality source the flv was made from, then probably whatever recent version of x264 you can find will be fine.
或者,如果您已经愿意从 .flv 转换,而不是从制作 flv 的高质量来源进行转换,那么您能找到的任何最新版本的 x264 都可以。
回答by ogrisel
http://handbrake.fris a nice high level tool with a lot of useful presets for mp4 for iPod, PS3, ... with both GUI and CLI interfaces for Linux, Windows and Mac OS X.
http://handbrake.fr是一个很好的高级工具,它为 iPod、PS3 的 mp4 提供了许多有用的预设,......具有适用于 Linux、Windows 和 Mac OS X 的 GUI 和 CLI 界面。
It comes with its own dependencies as a single statically linked fat binary so you have all the x264 / aac codecs included.
它带有自己的依赖项,作为单个静态链接的胖二进制文件,因此您拥有所有 x264 / aac 编解码器。
$ HandBrakeCLI -Z Universal -i myinputfile.mov -o myoutputfile.mp4
To list all the available presets:
列出所有可用的预设:
$ HandBrakeCLI -z
回答by ogrisel
You need to recompile ffmpeg (from source) so that it supports x264. If you follow the instructions in this page, then you will be able to peform any kind of conversion you want.
您需要重新编译 ffmpeg (从源代码),以便它支持 x264。如果您按照此页面中的说明进行操作,那么您将能够执行您想要的任何类型的转换。
回答by user1808087
Had this problem recently with converting nasty WMV into Final Cut Pro X for editing. Flow player can do it but it leaves a water mark, so I fiddled a bit with ffmpeg till I got something going.
最近在将讨厌的 WMV 转换为 Final Cut Pro X 进行编辑时遇到了这个问题。Flow player 可以做到,但它会留下水印,所以我摆弄了 ffmpeg 直到我有所作为。
First install ffmpeg - I used
brew install ffmpeg
Obviously you need brew installed first, google that bit.
首先安装 ffmpeg - 我用过brew install ffmpeg
显然你需要先安装
brew,谷歌一下。
Next I wrote a simple command line script with the following content - you can substitute the $1 for an input / output file or just create a shell script file... vi convert.sh Paste.
接下来,我编写了一个包含以下内容的简单命令行脚本 - 您可以将 $1 替换为输入/输出文件,或者只是创建一个 shell 脚本文件... vi convert.sh 粘贴。
echo "Pass one"
ffmpeg -y -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 1 -c:a libfaac -b:a 256k -f mp4 /dev/null &&
echo "Pass two"
ffmpeg -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 2 -c:a libfaac -b:a 256k "$1.mp4"
echo "Pass one"
ffmpeg -y -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 1 -c:a libfaac -b:a 256k -f mp4 /dev/null &&
echo "Pass two"
ffmpeg -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 2 -c:a libfaac -b:a 256k "$1.mp4"
Then to convert your video... sh convert.sh myvideofile.wmv If all went well you should see a new file called myvideofile.wmv.mp4.
然后转换您的视频... sh convert.sh myvideofile.wmv 如果一切顺利,您应该会看到一个名为 myvideofile.wmv.mp4 的新文件。
Hope that works for you.
希望这对你有用。
回答by Octavian Naicu
You're trying to convert a (rather rare) .flv file that (already) contains H.264 video and AAC audio.
您正在尝试转换(已经)包含 H.264 视频和 AAC 音频的(相当少见的).flv 文件。
Formatting your console's output as FFmpeg brings out these details.
将控制台的输出格式化为 FFmpeg 会显示这些详细信息。
Input #0, flv, from 'video.flv':
Duration: 00:05:01.20, start: 0.000000, bitrate: 66 kb/s
Stream #0.0: Video: h264, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 66 kb/s, 29.92 tbr, 1k tbn, 2k tbc
Stream #0.1: Audio: aac, 22050 Hz, stereo, s16
The original flv is converted to an .mp4 file with H.264 video and AAC audio (just like the original .flv):
原始 flv 转换为带有 H.264 视频和 AAC 音频的 .mp4 文件(就像原始 .flv 一样):
Output #0, mp4, to 'video.mp4':
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.92 tbc
Stream #0.1: Audio: 0x0000, 22050 Hz, stereo, s16, 64 kb/s
Because the audio and video data in the .flv are already in the format/codecs you need for the .mp4, you can just copy everything to the new .mp4 container. This process will be massively faster than decoding and reencoding everything:
由于 .flv 中的音频和视频数据已经采用 .mp4 所需的格式/编解码器,因此您可以将所有内容复制到新的 .mp4 容器中。这个过程将比解码和重新编码所有内容要快得多:
ffmpeg -i video.flv -vcodec copy -acodec copy video.mp4
or more simply:
或更简单地说:
ffmpeg -i video.flv -codec copy video.mp4
The real error you're getting is:
你得到的真正错误是:
Unsupported codec for output stream #0.1
不支持的输出流编解码器 #0.1
Which means FFmpeg can't convert audio (stream #0.1) to AAC.
这意味着 FFmpeg 无法将音频(流 #0.1)转换为 AAC。
You can skipthe error by:
您可以通过以下方式跳过错误:
- copying the audio data since it's already AAC encoded (use the copy command above)
- 复制音频数据,因为它已经是 AAC 编码的(使用上面的复制命令)
or you can solvethe error by:
或者您可以通过以下方式解决错误:
- using a FFmpeg build with AAC decode/encode support. FFmpeg currently supports 4 AAC libraries (see FFmpeg and AAC Encoding Guide).
- 使用具有 AAC 解码/编码支持的 FFmpeg 构建。FFmpeg 目前支持 4 个 AAC 库(参见FFmpeg 和 AAC 编码指南)。
For more details you should also read Converting FLV to MP4 With FFmpeg The Ultimate Guide
有关更多详细信息,您还应该阅读使用 FFmpeg 将 FLV 转换为 MP4 终极指南