ffmpeg now has x265 support and while it is still early days for the codec this is great news as there are also a number of players out there now too, not to mention many devices now have the CPU to play back the codec. Note that quite a lot of services now support h265/hevc input and as it is such a small footprint it can make quite a good file for transfer to cloud encoding.
Setup on OS X (likely be similar for linux and will do that at some point)
- Make sure you have cmake e.g. >brew install cmake and you will also need yasm
- You will also need mercurial to clone x265 >brew install mercurial
- Also if you already have ffmpeg installed using something like brew then uninstall that first >brew uninstall ffmpeg
Anyhow here are the simple steps:
1. Make sure you have a current build of ffmpeg checked out of git along with any other libs you are using e.g. libx264
2. Download the libx265 repository and build as per the instructions here: https://bitbucket.org/multicoreware/x265/wiki/Home (note I assume no one still uses Windows for dev!)
hg clone https://bitbucket.org/multicoreware/x265 cd x265/build/linux ./make-Makefiles.bash make make install
3. On your ffmpeg configure it with –enable-libx265 (it is disabled by default). Sample from my configure below
./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-libvidstab --enable-libx265 make make install
4. You should now be ready to go, e.g.
ffmpeg -i myvideo.MP4 -c:v libx265 encodetest/myvideo.mkv
Update: now with mp4 support
ffmpeg -i anchorman2-trailer-ffmpeg.mp4 -y -s 640x360 -c:v libx265 -c:a libfdk_aac -profile:a aac_he -b:v 200k -b:a 32k anchorman2_640x360_x265.mp4
In some cases you may get an error like:
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
And you will see above it:
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX x265 [error]: Sample Aspect Ratio width must be greater than 0
There is a bug at present (2014-04-08) that requires the SAR to be set in the header, note that you can fix this by doing a pre-encode and write the SAR / DAR header by forcing the aspect -aspect 16:9 e.g.
ffmpeg -i anchorman2-trailer.mp4 -y -c:v libx264 -c:a copy -aspect 16:9 -crf 0 anchorman2-trailer-ffmpeg.mp4
Some things to note:
- Moderately slow! It is now much faster than it used to be and I am getting 17fps without tweaking which is pretty good
- Playback of a 1080P HD clip used 400% on my i7 based laptop, size was
- Compared to a 2000kbps x264 encode of the same file quality was very good!