http://wiki.ubuntu.org.cn/UbuntuSkills Ubuntu安装FFmpeg编码出MP4文件的方法 2011-09-06 16:42 佚名 linux公社 字号:T | T FFmpeg是Ubuntu下强大的视频、音频编解码工具。 x264可以编码出高质量的h.264视频,iPad必须要h.264编码或mpeg-4编码的视频才能正常播放。Ubuntu官方源默认是不提供h.264编码的,这就需要我们手工编译安装FFmpeg的h.264支持,使之能够编码出MP4文件。
AD:2013云计算架构师峰会课程资料下载
FFmpeg是Ubuntu下强大的视频、音频编解码工具。 x264可以编码出高质量的h.264视频,iPad必须要h.264编码或mpeg-4编码的视频才能正常播放。Ubuntu官方源默认是不提供h.264编码的,这就需要我们手工编译安装FFmpeg的h.264支持,使之能够编码出MP4文件。
AD:2013云计算架构师峰会课程资料下载
FFmpeg是Ubuntu下强大的视频、音频编解码工具。 x264可以编码出高质量的h.264视频,iPad必须要h.264编码或mpeg-4编码的视频才能正常播放。
由于版权方面尚未确定,虽然全国很多网站都在使用h.264编码,但将来很有可能会被版权问题所困扰,所以Ubuntu官方源默认是不提供h.264编码的,这就需要我们手工编译安装FFmpeg的h.264支持,使之能够编码出MP4文件。
Ubuntu下安装、使用和升级FFmpeg的方法如下
1、安装支持包
- #libMP3lame
- sudo apt-get remove libMP3lame-dev
- sudo apt-get install nasm
- wget
- tar xzvf lame-3.98.4.tar.gz
- cd lame-3.98.4
- ./configure --enable-nasm --disable-shared
- make
- sudo checkinstall --pkgname=lame-ffmpeg --pkgversion="3.98.4" --backup=no --default --deldoc=yes
#卸载现有的 x264、libx264-dev、FFmpeg
- sudo apt-get remove ffmpeg x264 libx264-dev
#安装所有的 FFmpeg 和 x264 支持包
- sudo apt-get update
- sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libMP3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
2、安装x264
- cd
- git clone git://git.videolan.org/x264.git
- cd x264
- #./configure
- ./configure --enable-static --enabled-shared
- make
- sudo checkinstall --pkgname=x264 --pkgversion "2:0.`grep X264_BUILD x264.h -m1 | cut -d' ' -f3`.`git rev-list HEAD | wc -l`+git`git rev-list HEAD -n 1 | head -c 7`" --backup=no --deldoc=yes --fstrans=no --default
3、安装FFmpeg
- cd
- svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
- cd ffmpeg
- ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
- #--enable-x11grab
- gcc使用正确的版本http://forums.debian.net/viewtopic.php?f=10&t=103908
- http://www.linuxquestions.org/questions/linux-software-2/managed-environment-ffmpeg-install-4175461262/
- make
- sudo checkinstall --pkgname=ffmpeg --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default
- hash x264 ffmpeg ffplay
4、安装qt-faststart(可选)
这是个重要的x264再编码工具, 它的作用是使得视频不必等待下载完成即可开始播放。
使用方法:
- qt-faststart input.foo output.foo
安装方法:
- cd ~/ffmpeg
- make tools/qt-faststart
- sudo checkinstall --pkgname=qt-faststart --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default install -D -m755 tools/qt-faststart /usr/local/bin/qt-faststart
5、基本安装完成,你可以保留 ~/x264、~/ffmpeg目录以便将来升级时使用。
6、升级 FFmpeg 和 x264
- sudo apt-get remove ffmpeg x264 libx264-dev libvpx
- cd ~/x264
- make distclean
- git pull
- cd ~/ffmpeg
- make distclean
- svn update
- ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libMP3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab
- make
- sudo checkinstall --pkgname=ffmpeg --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default
- hash x264 ffmpeg ffplay
7、使用 FFmpeg and x264
容易的输出高质量视频的方法是使用FFmpeg中libx264的预设模式。你可以手工调整一些选项 (例如窗口大小: -s 640×480) 。 另外你可以参考 libx264 预设模式在线列表或再 /usr/local/share/ffmpeg 目录中查找帮助。
One-pass CRF (Constant Rate Factor) 使用预设模式:slow. One-pass CRF是经常使用的常规编码方式. 调整 -crf 可以改变输出质量. 数字越小输出质量越高同时输出尺寸越大. 可使用的数字范围是:18 ~ 28。
- ffmpeg -i input.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 output.MP4
Two-Pass encode 使用预设模式: fast. 想要精确设置目标编码率、文件大小的时候会使用到这个编码模式。
- ffmpeg -i input.avi -pass 1 -vcodec libx264 -vpre fast_firstpass -b 512k -bt 512k -threads 0 -f rawvideo -an -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre fast -b 512k -bt 512k -threads 0 output.MP4
iPod/iPad 640×480,使用预设值: slow 和 ipod640:
- ffmpeg -i input.avi -acodec libfaac -aq 100 -ac 2 -vcodec libx264 -vpre slow -vpre ipod640 -crf 26 -map_meta_data 0:0 -vf scale=640:-1 -threads 0 output.MP4
总结:
欲知更多有关Ubuntu安装FFmpeg编码出MP4文件的方法,请点击Ubuntu如何转换mp4与x264和h.264。
https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
Compile FFmpeg on Ubuntu, Debian, or Mint
Contents
- Get the Dependencies
- Compilation & Installation
- Finish
- Updating FFmpeg
- Reverting Changes Made by This Guide
- If You Need Help
- Also See
This guide for supported releases of Ubuntu, Debian, and Linux Mint will provide a local install of the latest FFmpeg tools and libraries including several external encoding and decoding libraries (codecs). This will not provide a system installation and therefore will not interfere with anything such as repository packages. Recent static builds are also available for lazy people or those who are unable to compile.
Get the Dependencies
Copy and paste the whole code box for each step.
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential git libass-dev libgpac-dev \libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
mkdir ~/ffmpeg_sources
- Server users can omit the ffplay and x11 dependencies: libsdl1.2-dev libva-dev libvdpau-dev libx11-dev libxext-dev libxfixes-dev.
- Ubuntu 10.04 Lucid users will need to install the git-core package instead of the git package. Lucid lacks the package libva-dev. This can be ignored.
Compilation & Installation
One advantage to compiling is that you can build ffmpeg to your liking. If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libopus is not needed, then skip that section and then remove --enable-libopus from the Install FFmpeg section.
Yasm
Yasm is an assembler used by x264 and FFmpeg.
Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the yasm package from the repository instead of compiling.
cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean
. ~/.profile
x264
H.264 video encoder. See the x264 Encoding Guide for more information and examples.
cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264.git
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean
Note: You can download the nightly x264 source snapshot as an alternative to using git.
fdk-aac
AAC audio encoder. See the AAC Encoding Guide for more information and examples.
cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
Note: You can download a fdk-aac source snapshot as an alternative to using git.
libmp3lame
MP3 audio encoder.
Most users can install the repository package:
sudo apt-get install libmp3lame-dev
Ubuntu 10.04 and Debian Squeeze users must compile:
sudo apt-get install nasm
cd ~/ffmpeg_sources
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared
make
make install
make distclean
libopus
Opus audio decoder and encoder.
Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the libopus-dev package from the repository instead of compiling.
cd ~/ffmpeg_sources
wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
tar xzvf opus-1.0.3.tar.gz
cd opus-1.0.3
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
libvpx
VP8/VP9 video encoder and decoder. See the vpx (WebM) Encoding Guide for more information and examples.
Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the libvpx-dev package from the repository instead of compiling.
cd ~/ffmpeg_sources
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean
Note: You can download a libvpx source snapshot as an alternative to using git.
ffmpeg
Note: Server users should remove --enable-x11grab from the following command:
cd ~/ffmpeg_sources
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
export PKG_CONFIG_PATH
./configure --prefix="$HOME/ffmpeg_build" \--extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" \--bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-libass --enable-libfdk-aac \--enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx \--enable-libx264 --enable-nonfree --enable-x11grab
make
make install
make distclean
hash -r
Note: You can download the nightly FFmpeg source snapshot as an alternative to using git.
Finish
- Installation is now complete and ffmpeg is now ready for use. See the x264 Encoding Guide for examples.
- If you do not see FFmpeg developers in your ffmpeg console output then something went wrong and you're probably using the fake "ffmpeg" from the repository.
- HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.
- You can keep the ffmpeg_sources directory if you plan on updating later. See Updating FFmpeg below for more details followed by instructions for reverting all changes made by this guide.
Updating FFmpeg
Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First, remove (or move) the old files and then update the dependencies:
rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,yasm,ytasm}
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential git libass-dev libgpac-dev \libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
Server users can omit: libsdl1.2-dev libva-dev libvdpau-dev libx11-dev libxext-dev libxfixes-dev.
x264
cd ~/ffmpeg_sources/x264
make distclean
git pull
Now run ./configure, make, and make install as shown in the Install x264 section.
fdk-aac
cd ~/ffmpeg_sources/fdk-aac
make distclean
git pull
Now run ./configure, make, and make install as shown in the Install fdk-aac section.
libvpx
cd ~/ffmpeg_sources/libvpx
make clean
git pull
Now run ./configure, make, and make install as shown in the Install libvpx section.
ffmpeg
cd ~/ffmpeg_sources/ffmpeg
make distclean
git pull
Now run ./configure, make, and make install as shown in the Install FFmpeg section.
Reverting Changes Made by This Guide
To remove ffmpeg, x264, and dependencies installed for this guide:
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,yasm,ytasm}
sudo apt-get autoremove autoconf automake build-essential git libass-dev libgpac-dev \libmp3lame-dev libopus-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \libvorbis-dev libvpx-dev libx11-dev libxext-dev libxfixes-dev texi2html zlib1g-dev
hash -r
If You Need Help
Feel free to ask questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.
Also See
- x264 Encoding Guide
- AAC Encoding Guide
External Links
- Howto: Compile the development version of VLC under the latest Ubuntu release
- Howto: Build the svn MPlayer under the latest release version of Ubuntu