Recently I realized that the x265 codecs are not using the GPU as the x264 codecs does, at least in Linux. Then, you need a quite new CPU to smoothly reproduce these videos, which is quite annoying for people using a Raspberry Pi or a similar device as home-cinema. Like me.
Well, I downloaded a whole series encoded with this x265 codecs. And after a few minutes cursing this crazy-codecs world, I decided to take my time and learning how to transform videos from x265 to x264 format (the good and fast one). This re-encoding process takes about 2x or 3x the time of each video, which means several hours for a whole series, so I preferred to use my Raspberry Pi server to do the process during the nights.
(By the way, to see how to install ffmpeg and x265 support on Ubuntu 14.04, click here)
First, I needed the last version of ffmpeg command, with both x265 and x264 support in my Raspberry. Sadly, there is no packages for that, so I had to download, compile and install them. This is the whole process:
Install dependencies:
1 |
sudo apt-get install cmake cmake-curses-gui build-essential yasm |
x265 codecs:
Download source, compile and install:
1 2 3 |
wget http://ftp.videolan.org/pub/videolan/x265/x265_1.8.tar.gz tar -xzvf x265_1.8.tar.gz cd x265_1.8/build/linux |
After the next command, it will ask you for cmake option. Press c to configure and g to generate and exit:
1 |
./make-Makefiles.bash |
Compile and install:
1 2 |
make sudo make install |
ffmpeg with x264 support:
Download, compile and install the last version of ffmpeg (with x264):
x264 codecs:
1 2 3 4 5 6 |
sudo apt-get install git # In case you don't have it already installed git clone git://git.videolan.org/x264 cd x264 ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl make -j4 sudo make install |
The -j4 param for the make command is just in case you have a Model B+, so you can take advantaje of all their 4 cores 🙂
ffmpeg:
1 2 3 4 5 |
git clone git://source.ffmpeg.org/ffmpeg.git cd ffmpeg sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree make -j4 sudo make install |
Note the -j4 param again…
And that’s it!.
Now, to convert a video file:
1 |
ffmpeg -i INPUT_x265_encoded_file.mkv -c:a copy -x265-params crf=25 OUTPUT_x264_encoded_file.mkv |
I also make a quick script to launch this command for a list of files. It is something like this. Please don’t take it as it is, it is too simple, just adapt it to your needs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash # Usage: # First param: Source dir # Second param: Dest dir. DO NOT INCLUDE THE TRAILING SLASH. # The rest of the params should be the files from the workdir. You can use a list with wildcards as usual... # Go to the source folder: cd $1 for f in ${@:3} do # Substitute the "x265" part in the the filename with "x264": ffmpeg -i "$f" -c:a copy -x265-params crf=25 "$2/${f//x265/x264}" done |
Usage example:
1 |
./the-name-you-gave-to-the-script.sh /path/to/videos/folder /path/to/videos/output/folder file-one*.mkv other-files-names.S01E0[1-9]* |
By the way, you can also install ffmpeg and x265 support on Ubuntu 14.04, and then you can use the same command for converting videos as mentioned above:
ffmpeg:
1 2 3 |
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next sudo apt-get update sudo apt-get install ffmpeg |
x265 codecs:
1 2 3 |
sudo apt-add-repository ppa:strukturag/libde265 sudo apt-get update sudo apt-get install gstreamer0.10-libde265 gstreamer1.0-libde265 vlc-plugin-libde265 |
Thanks to:
http://raspberrypi.stackexchange.com/a/33816
http://www.jeffreythompson.org/blog/2014/11/13/installing-ffmpeg-for-raspberry-pi/
http://askubuntu.com/questions/362745/how-to-install-h-265-hevc-codec-on-ubuntu-linux
http://www.noobslab.com/2014/12/ffmpeg-returns-to-ubuntu-1410.html
Hi,
Raspberry PI 2? how many fps ?
From my experience, you need to add –enable-libx265 to the ffmpeg’s configure command.
I got “Unrecognized option ‘x265-params'” when strictly following your guide. Now it works for me.
However, I can’t get libx264 to encode, but that’s another subject.