![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
May the Ubuntu Be With You!
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,585
|
HOWTO: Install and use the latest FFmpeg and x264
FFmpeg is a versatile tool to encode and convert a multitude of video and audio formats. x264 encodes high-quality video superior to other popular encoders.
Although FFmpeg and x264 are available in the Ubuntu repositories, you may need to compile from source. For example, the ffmpeg-user mailing list requires that you use the latest FFmpeg svn before asking for help. Since FFmpeg and x264 are updated frequently, you may also like to have the bleeding-edge for encoding videos. Also, FFmpeg in the Ubuntu repository may not support necessary encoders, decoders, and formats. Note: Those who are uncomfortable compiling can still enable restricted encoders in the repository FFmpeg: HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg Choose your Ubuntu 0.The instructions on the page are for Ubuntu Karmic Koala 9.10. Separate instructions are also available for older releases:
Install the Dependencies 1. Uninstall x264, libx264-dev, and ffmpeg if they are already installed. Open a terminal and run the following: Code:
sudo apt-get remove ffmpeg x264 libx264-dev Code:
sudo apt-get update sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libx11-dev libxvidcore4-dev zlib1g-dev Install x264 3. Get the most current source files from the official x264 git repository, compile, and install. You can run "./configure --help" to see what features you can enable/disable. If you are behind a firewall or unable to use git, then daily source tarballs are also available. Code:
cd git clone git://git.videolan.org/x264.git cd x264 ./configure make sudo checkinstall --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`" --backup=no --default Install FFmpeg 4. Get the most current source files from the official FFmpeg svn, compile, and install. Run "./configure --help" to see what features you can enable/disable. If you are behind a firewall or unable to use subversion, then nightly FFmpeg snapshots are also available. Code:
cd svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg cd ffmpeg ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab make sudo checkinstall --pkgname=ffmpeg --pkgversion "4:0.5+svn`date +%Y%m%d`" --backup=no --default Using FFmpeg and x264 The easiest method for high quality video encoding is by using the libx264 presets that are included with FFmpeg. I recommend reading the FFmpeg x264 encoding guide before trying these presets so you have a better idea of what to use. You can add options such as frame size (for example: -s 640x480) or tweak my examples to customize your encode. You can see a current list of other presets, such as lossless and ipod, available in the /usr/share/ffmpeg directory. One-pass CRF (Constant Rate Factor) using the hq preset. This is good for general encoding and is what I use most often. Adjust -crf to change the quality. Lower numbers mean higher quality and a larger output file size. A sane range is 18 to 28. Code:
ffmpeg -i input.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre hq -crf 22 -threads 0 output.mp4 Code:
ffmpeg -i input.avi -pass 1 -vcodec libx264 -vpre fastfirstpass -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 hq -b 512k -bt 512k -threads 0 output.mp4 Code:
ffmpeg -i input.avi -pass 1 -an -vcodec libx264 -vpre fastfirstpass -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 -f rawvideo -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre hq -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 output.mp4 Updating Your Installation Development of FFmpeg and x264 is active and an occasional update can give you new features and bug fixes. To update FFmpeg and x264 you will need to remove the packages, make distclean, update the source, recompile, and install. To update x264: Code:
sudo apt-get remove ffmpeg x264 libx264-dev cd ~/x264 make distclean git pull Code:
cd ~/ffmpeg make distclean svn update Reverting Changes Made by This Tutorial To remove FFmpeg/x264 and any changes made from this tutorial: Code:
sudo apt-get remove x264 ffmpeg build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libsdl1.2-dev libtheora-dev libx11-dev libxvidcore4-dev zlib1g-dev Additional Resources
If You Need Help Feel free to ask your questions here and I'll try to give you a good answer. Helpful information includes your Ubuntu version, names of any third-party repositories or PPAs you are using, FFmpeg command, and the complete FFmpeg output if applicable. Recent Tutorial Updates 2009-11-18: Split Karmic section from other Ubuntu versions due to the addition of libopencore-amr to the guide. Last edited by FakeOutdoorsman; 1 Day Ago at 09:57 PM.. |
|
|
|
|
|
#2 |
|
100% Pure Ubuntu
![]() |
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Great guide. Thanks a lot. One problem:
When I configure x264 I get the error: Code:
./configure --enable-pthread --enable-mp4-output --enable-shared No suitable assembler found. x264 will be several times slower. Please install 'yasm' to get MMX/SSE optimized code. But I figured it out! All I had to do was go to: http://www.tortall.net/projects/yasm/wiki/Download Grab the 0.7.0 tarball, then ./configure, make, sudo checkinstall, then build x264, then ffmpeg. Now I can encode much faster. A note to those who are interested: I used the ffmpeg encoding script: Code:
#!/bin/sh ffmpeg -i $1 -y -an -pass 1 -vcodec libx264 -threads 4 -b 1024kbps -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me epzs -subq 1 -trellis 0 -refs 1 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $2 ffmpeg -i $1 -y -acodec libfaac -ab 128k -pass 2 -vcodec libx264 -threads 4 -b 1024kbps -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $2 Code:
./scriptname myfile.avi myfile.mp4
__________________
Knowledge is half the battle. The other half is violence! |
|
|
|
|
|
#3 | |
|
May the Ubuntu Be With You!
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,585
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Quote:
As of March 14, '08 (I think), x264 requires a newer yasm >= 0.6.0 than what is in the Ubuntu universe repository (yasm 0.5.0). x264 should fallback to nasm if yasm isn't detected and worked for me just fine despite the following error: Code:
./configure: 330: yasm: not found Before I wrote this tutorial I tested the speed of x264 either using a compiled yasm 0.7.0, nasm from the repository, or no assembler. The speed differences were very small between compiled yasm and nasm from the repo: x264/mencoder/ffmpeg on a dual quad core. Edit: Tutorial updated with yasm compilation. Last edited by FakeOutdoorsman; May 12th, 2008 at 07:11 PM.. |
|
|
|
|
|
|
#4 |
|
100% Pure Ubuntu
![]() |
Re: HOWTO: Compile the latest ffmpeg and x264 from source
I tried using both nasm and yasm from the repos, and x264 would compile but it would say it was building without support for yasm and nasm.
Then, when I used it to convert a file it would say that it was using no cpu extensions, as opposed to saying "MMX SSE ...". It would also take significantly longer (like 2-5 times as long). But just installing the yasm from source fixed it, and it wasn't very difficult to do.
__________________
Knowledge is half the battle. The other half is violence! |
|
|
|
|
|
#5 |
|
First Cup of Ubuntu
![]() Join Date: Apr 2006
Beans: 1
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Thanks a million. Great in depth job on this one.
|
|
|
|
|
|
#6 |
|
First Cup of Ubuntu
![]() Join Date: Jan 2008
Beans: 1
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
This is a great howto, since in my opinion ffmpeg is broken due to these issues.
Therefore, what are the additional steps to fully replace ffmpeg, x64 and the libx264 packages such that it satisfies dependencies for other applications that use ffmpeg and my update manager does not keep asking me to upgrade from the checkinstall packages? |
|
|
|
|
|
#7 |
|
First Cup of Ubuntu
![]() Join Date: Jul 2005
Beans: 8
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
When I try to "make" x264, I get this error.
Code:
/usr/bin/ld: common/mc.o: relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC common/mc.o: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [libx264.so.60] Error 1 UPDATE: Never mind. Cleaned up my folder of a previous failed build attempt and it seems to be okay now. Thanks for the guide! Last edited by Nais; June 26th, 2008 at 01:08 PM.. |
|
|
|
|
|
#8 | |
|
May the Ubuntu Be With You!
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,585
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Quote:
Code:
sudo aptitude hold ffmpeg |
|
|
|
|
|
|
#9 |
|
Dipped in Ubuntu
![]() Join Date: Dec 2005
Beans: 644
Ubuntu 9.10 Karmic Koala
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Yes locking versions work but how about trying to get synaptic to see that you installed libx264 via the source code with checkinstall so far according to synaptic i only have x264 the binary installed and not libx264 and libx264-dev so now other multimedia apps will not install without using the repos version of libx264 if i try to install via synaptic
|
|
|
|
|
|
#10 | |
|
May the Ubuntu Be With You!
![]() Join Date: Sep 2006
Location: Alaska
Beans: 1,585
|
Re: HOWTO: Compile the latest ffmpeg and x264 from source
Quote:
|
|
|
|
|
| Bookmarks |
| Tags |
| encode, ffmpeg, h264, libx264, x264 |
| Thread Tools | |
| Display Modes | |
|
|