x264 benchmark compilation & installation for FreeBSD 9.x
To be able to compile the x264 benchmark on FreeBSD 9.x a set of basic software needs to be present on the system. To install the required packages we will be using the BSD package manager. Please install the following packages as root as shown below:
- pkg_add -r autoconf
- pkg_add -r gmake
- pkg_add -r yasm
- pkg_add -r wget
- pkg_add -r git
- pkg_add -r easygit
- pkg_add -r gsed
- pkg_add -r gawk
- pkg_add -r bzip2
- pkg_add -r firefox (satisfies a few dependencies and allows us to browse the web and download necessary files.)
- pkg_add -r texi2html
- pkg_add -r gcc49 (The stock GCC 4.2.1 will not work for newer x264 versions, which is why we have to use 4.9.)
- pkg_add -r nano (A useful text editor for the command line.)
Now to the interesting part:
The benchmarking software itself
To be able to use x264, we need the decoder filters from libavcodec (in short libav) and of course the x264 encoder itself, which will be linked against libav during the course of configuration and compilation. Additionally, we need the benchmark input video, download mirrors for that are available at the bottom of the x264 [benchmark results list]. If you like, you may also use ffmpeg/ffms as a replacement for libav.
For simplicities sake, we shall assume, that the files are now placed in /usr/home/user/x264src/. So on the terminal we switch to that directory and start with libav. Please unpack the archive like tar -xzvf <filename.tgz>, after which you will see a new libav subfolder. Change to that new folder, so that you can begin to set the necessary environment variables, for which we shall take the bash shell as a given:
- chsh -s /usr/local/bin/bash (Please log out and back into the system after this step.)
- export CC=/usr/local/bin/gcc49
- export CXX=/usr/local/bin/g++49
- export CPP=/usr/local/bin/cpp49
- export CFLAGS="-march=native -mtune=native -O3 -ffast-math -I/usr/local/include -L/usr/local/lib
- export CXXFLAGS="-march=native -mtune=native -O3 -ffast-math -I/usr/local/include -L/usr/local/lib
- export LDFLAGS="-L/usr/local/lib
The shell in which you have set those environment variables should stay open from now on. If you do close it accidentally or on purpose, you will need to re-set those variables in a newly opened shell. After that we can continue with modifying the libav configuration script. So we shall open the file configure that you can find in the folder libav has been extracted to with a text editor like nano. The following parts require modification:
Modify those two lines like this:
Additionally to that all calls of sed are to be replaced with gsed and all calls of awk need to be similarily replaced with gawk! After that we can launch the configuration script:
- ./configure --prefix=/usr/local --enable-gpl --enable-nonfree --disable-bzlib --disable-zlib
The bzlib and zlib libraries are switched off here as linking x264 against a libav enabled in such a way will not work on FreeBSD 9.x. Those libraries are used for MKV (Matroska container) header compression, which we can just safely forget about. Now we may compile and install:
- su (If su says "Sorry", you need to add your user to the wheel group as root: pw usermod user -G wheel)
- gmake install
With that done, we have installed libav and can carry on with x264.
First, let's unpack x264, again in folder /usr/home/user/x264src like: tar -xjvf <x264 archive> and change to the newly created x264 subfolder right afterwards.
Now we need to apply a small trick for x264 which will affect the configure and version.sh scripts. The two have a shebang line pointing at the bash shell, which sits in a different path on FreeBSD though. A simple solution is to just set a system-wide link to the bash, so we don't have to modify the scripts.
- ln -s /usr/local/bin/bash /bin/bash
Additionally to that we need to modify the configure script to tell it to use the new GCC 4.9 compiler, just like we did for libav before. Search and replace:
Change that line to::
Additionally to that we need to replace all calls of sed with gsed and all calls of awk with gawk, just like for libav, but in all the following scripts: version.sh, config.guess, config.sub, configure!
After that we can configure the source tree and compile as well as install the whole thing:
- ./configure --prefix=/usr/local (After that you need to check whether it shows "lavf yes". If not you need to inspect "config.log"!)
- gmake install
Now x264 is installed and ready for operation, which may be verified by running x264 --version. If that works and if the binary shows as being linked against libswscale and libavformat, then everything should be in perfect order. Now please download the benchmark script:
Copy the file launchbenchmark.sh into a subfolder dedicated to the benchmark, if you do not have one yet, just create it: mkdir -p /usr/home/user/x264benchmark. Also, you should put the input video elephantsdream_source.264 into that folder.
Now you're ready for launch. Just enter the following command while sitting in the folder /usr/home/user/x264benchmark, having verified that the benchmark script is executable (chmod +x ./launchbenchmark.sh):
- time ./launchbenchmark.sh
That might look like the following screenshot (click for enlargement), the result can be read from the terminal window after completion, just pay attention to the "real" value after it's done:
(Wallpaper is © 2002 by Billy Nolen)
Depending on the machine this may take hours, in extreme cases even days, weeks or months. If you have any further questions about building the x264 benchmark on PC-BSD, please do not hesitate to ask in the [corresponding forum thread]. The forum may be german, but if you ask in english, you should still get a response.
[Back to the x264 benchmark results list]
[Comment on this guide]