View Full Version : Is there a guide somewhere for compiling x264? Multithreading isn't working
penvzila
13th May 2007, 00:34
I'm using mencoder in linux, and when I encode x264 videos I've noticed that the 'threads' option doesn't load both processors when I set it to >1. When I run 2 instances on 2 separate files, I get full CPU loading on both cores, but this is only useful if I have more than one file to encode.
I have a Core 2 Duo processor, and I'm running 64bit Ubuntu Edgy. I am just using their default MPlayer package, so I'm thinking it either wasn't compiled with multithreading support, or the 264 part wasn't or whatever.
I've been searching around here for a while, and I've gotten the x264 source from CVS, but I don't know what switches to use to enable multithreading, SSE3, etc.
Trahald
13th May 2007, 00:41
http://forum.doom9.org/showthread.php?t=92726&highlight=compile
No switches are required, cd into x264 source and type ./configure
This is what I use on Feisty Fawn amd64:
To compile with SSSE3 support you need yasm 0.6.0 or greater. AFAIK Ubuntu repos contains version 0.5.0. Grab latest tar from yasm's website and compile it.
root@xenon:/home/nfm/x264src# ./configure --enable-shared
Platform: X86_64
System: LINUX
avis input: no
mp4 output: no
pthread: yes
gtk: no
debug: no
gprof: no
PIC: yes
shared: yes
visualize: no
You can run 'make' or 'make fprofiled' now.
root@xenon:/home/nfm/x264src#
5-7% speedup tweak on AMD Athlon64 X2 "K8" ;)
sudo gedit config.mak
These are the changes:
CFLAGS=-O4 -ffast-math -Wall -I. -DHAVE_MALLOC_H -DHAVE_MMX -DHAVE_SSE3 -DARCH_X86_64 -DSYS_LINUX -DHAVE_PTHREAD -fPIC -s -fomit-frame-pointer
CFLAGS=-march=k8 -O4 -ffast-math -Wall -I. -DHAVE_MALLOC_H -DHAVE_MMX -DHAVE_SSE3 -DARCH_X86_64 -DSYS_LINUX -DHAVE_PTHREAD -fPIC -s -fomit-frame-pointer
And then make fprofiled:
make fprofiled VIDS="/media/sda7/files/samples/video720x352.yuv"
To install:
make install
Or make debian package for cleaner management or later reuse (apt-get install checkinstall).
checkinstall -D --install=no
akupenguin
13th May 2007, 04:08
gedit config.mak
The simpler way is
CFLAGS=-march=k8 ./configure
although I never measured any significant speedup from that. -march mattered on x86_32, but all x86_64 cpus so far are similar enough that optimizing for a particular one doesn't make any difference.
fprofile still helps.
penvzila
13th May 2007, 04:38
Thanks for responding. I'll try this when I get home. I'm not unhappy with the speed at all, but I thought it would be nice if I could actually take advantage of both cores.
One last question though. Will I need to recompile MPlayer, or reinstall it, to take advantage of the newly compiled x264?
akupenguin
13th May 2007, 04:54
If you used a shared library the first time, then just replacing libx264.so is enough. If you used a static library then you have to relink MPlayer.
The simpler way is
CFLAGS=-march=k8 ./configure
although I never measured any significant speedup from that. -march mattered on x86_32, but all x86_64 cpus so far are similar enough that optimizing for a particular one doesn't make any difference.
Thanks for the tip :) . I compiled 2 versions of fprofiled x264, normal one and one with -march=k8. As you said, there's no speed gain on x86_64 cpus. I tested a yuv, 720x352, 253.8MB clip on 64-bit Linux and encode with k8 option proved to be faster by 0.5 sec (generic = 01min. 20.04sec. and k8 = 1min 19.49sec.).
The 5-7% speedup came from i386 Linux (still the same 64-bit cpu) with k8 option and no fprofiled build. This is what I got when I compared 2 encodes couple moths ago. Sorry for false information, maybe pfrofiled build is the key here. Good to know that there's no significant difference now.
Out of curiosity, akupenguin, what distribution do you use? Gentoo perhaps?
akupenguin
13th May 2007, 08:29
Gentoo at home, Debian on my server.
penvzila
14th May 2007, 20:53
If you used a shared library the first time, then just replacing libx264.so is enough. If you used a static library then you have to relink MPlayer.
I can see that the libx264.so I just compiled is in /usr/local/lib. Is this where MPlayer needs it? I haven't noticed a speed increase.
akupenguin
14th May 2007, 21:27
That just means you compiled a shared library, not that MPlayer used it. Run `ldd /usr/local/bin/mencoder` and see if libx264.so is listed. Also make sure the version mencoder is linked to has the same major version number as what you just built (libx264.so.55).
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.