View Full Version : libx264 versus x264cli
bartnovsky
22nd September 2009, 19:58
Here is a strange observation:
when encoding video to h264 using ffmpeg (and hence using libx264) cores of my cpu are loaded as follows:
core1: 60%
core2: 10%
core3: 10%
core4: 10%
and when encoding the same video (with the same preset converted for x264cli) i get (approximately) the following:
core1: 50%
core2: 50%
core3: 50%
core4: 50%
Does that mean that libx264 doesn't support multi-threading?.. (I took ffmpeg here (http://tripp.arrozcru.org/))
Dark Shikari
22nd September 2009, 20:00
You need to enable threading (-threads 0).
bartnovsky
22nd September 2009, 20:08
Indeed i put "-threads 0" into command line options for ffmpeg, but it doesn't seem to work...
nm
22nd September 2009, 20:12
Show us the full ffmpeg command-line and custom preset settings if you're using any. What kind of a source (format, resolution, bitrate) are you encoding?
LoRd_MuldeR
22nd September 2009, 20:20
bartnovsky, you can check the output file in a tool like Avinaptic or MediaInfo too see the actual value of the "threads" parameter ;)
If you see "threads=1" in the file, then you know that ffmpeg isn't forwarding the parameter properly to libx264...
bartnovsky
21st October 2009, 09:59
First of all my apologies for a delayed answer.
LoRd_MuldeR, you turned out to be quite right:
i took both Avinaptic or MediaInfo to view the info of file encoded by ffmpeg into h264 by means of libx264: and amazingly i saw there "threads=1"!!!
Briefly the problem: ffmpeg seems to not use multithreading when encoding by means of libx264 and loads only 1 core (though i put threads=0 in options)
Here is the details:
1.somehow if i encode a video using unofficial release from http://ffmpeg.arrozcru.org/builds/ neither Avinaptic nor MediaInfo (which is newer and more advanced) shows "Encoding settings" - so that i just can't view the "threads" parameter... That's another reason to make own build.
2.ok, i built ffmpeg with pthreads and libx264 (./configure --enable-memalign-hack --enable-pthreads --enable-libx264 --enable-gpl --extra-cflags="-fno-common")
and get the same result - only 1 core is being used when encoding. But MediaInfo now shows "Encoding settings" for the output file:
Encoding settings: cabac=0 / ref=1 / deblock=0:0:0 /
analyse=0x3:0 / me=dia / subme=1 / psy=1 / psy_rd=0.0:0.0 /
mixed_ref=0 / me_range=16 / chroma_me=0 / trellis=0 /
8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 /
threads=1 / nr=0 / decimate=1 / mbaff=0 /
constrained_intra=0 / bframes=0 / keyint=250/keyint_min=50/
scenecut=40 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=25 /
ratetol=160.0 / qcomp=0.60 / qpmin=10 / qpmax=51 /
qpstep=4 / ip_ratio=1.41 / aq=1:1.00
So ffmpeg isn't forwarding the parameter properly to libx264...
It seems to be rather a bug... Should i write about this to ffmpeg mailing list?
x264 is a great thing! but it neither can decode video nor it can encode audio. If ffmpeg worked as it is supposed to with libx264 - it would be just fine!
Dark Shikari
21st October 2009, 10:21
First of all my apologies for a delayed answer.
LoRd_MuldeR, you turned out to be quite right:
i took both Avinaptic or MediaInfo to view the info of file encoded by ffmpeg into h264 by means of libx264: and amazingly i saw there "threads=1"!!!
Briefly the problem: ffmpeg seems to not use multithreading when encoding by means of libx264 and loads only 1 core (though i put threads=0 in options)
Here is the details:
1.somehow if i encode a video using unofficial release from http://ffmpeg.arrozcru.org/builds/ neither Avinaptic nor MediaInfo (which is newer and more advanced) shows "Encoding settings" - so that i just can't view the "threads" parameter... That's another reason to make own build.
2.ok, i built ffmpeg with pthreads and libx264 (./configure --enable-memalign-hack --enable-pthreads --enable-libx264 --enable-gpl --extra-cflags="-fno-common")
and get the same result - only 1 core is being used when encoding. But MediaInfo now shows "Encoding settings" for the output file:
Encoding settings: cabac=0 / ref=1 / deblock=0:0:0 /
analyse=0x3:0 / me=dia / subme=1 / psy=1 / psy_rd=0.0:0.0 /
mixed_ref=0 / me_range=16 / chroma_me=0 / trellis=0 /
8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 /
threads=1 / nr=0 / decimate=1 / mbaff=0 /
constrained_intra=0 / bframes=0 / keyint=250/keyint_min=50/
scenecut=40 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=25 /
ratetol=160.0 / qcomp=0.60 / qpmin=10 / qpmax=51 /
qpstep=4 / ip_ratio=1.41 / aq=1:1.00
So
It seems to be rather a bug... Should i write about this to ffmpeg mailing list?
x264 is a great thing! but it neither can decode video nor it can encode audio. If ffmpeg worked as it is supposed to with libx264 - it would be just fine!ffmpeg works just fine. Update your ffmpeg+x264 and read the guide (http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide/).
bartnovsky
21st October 2009, 11:26
Dark Shikari, would you be a little more specific, when saying
ffmpeg works just fine. Update your ffmpeg+x264 and read the guide.
Because i do use the last version of ffmpeg+x264 and made my encoding script relying on the mentioned guide (http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide/)
Here is my script to ffmpeg:
ffmpeg -an -y -b 1000k -i input_video.mp4 -vcodec libx264 -vpre libx264-fastfirstpass.ffpreset output.mkv
here is my libx264-fastfirstpass.ffpreset:
threads=0
coder=1
flags=+loop
cmp=+chroma
partitions=-parti8x8-parti4x4-partp8x8-partp4x4-partb8x8
me_method=dia
subq=1
me_range=16
g=250
keyint_min=25
sc_threshold=40
i_qfactor=0.71
b_strategy=1
qcomp=0.6
qmin=10
qmax=51
qdiff=4
bf=3
refs=1
directpred=3
trellis=0
flags2=-bpyramid-wpred-mixed_refs-dct8x8+fastpskip
Here is a screenshot of working ffmpeg:
http://photofile.name/photo/bartnovsky/150198202/small/156066391.jpg (http://photofile.name/users/bartnovsky/150198202/156066391/)
SVN-r16573 is the last revision as far as i know.
Here is a screenshot of task manager taken at the same moment:
http://photofile.name/photo/bartnovsky/150198202/small/156066392.jpg (http://photofile.name/users/bartnovsky/150198202/156066392/)
Obviously ffmpeg doesn't send parameter "threads=0" to libx264.
Dark Shikari, I will greatly appreciate it if you share with me your version of ffmpeg, where multi threading works.
Blue_MiSfit
21st October 2009, 11:32
@bartnovsky:
I suggest you use a third party image hosting site, as attachments tend to take forever to get approved here, if at all :)
Regarding your problem, where did you get the specific ffmepg build you're using?
~MiSfit
Dark Shikari
21st October 2009, 11:38
ffmpeg -an -y -b 1000k -i input_video.mp4 -vcodec libx264 -vpre libx264-fastfirstpass.ffpreset output.mkvIt sounds like you didn't read the guide as your commandline doesn't even make sense.
You've put half the options in the wrong place (options before -i affect the input, not the output), you didn't use -threads 0 like the guide told you to, and you didn't put -pass 1 despite using fastfirstpass.
bartnovsky
21st October 2009, 12:05
Blue_MiSfit, i took ffmpeg here (http://tripp.arrozcru.com/builds/ffmpeg-18639.7z).
I put threads=0 right into libx264-fastfirstpass.ffpreset (the only modification i made to the preset)...ups, a stupid mistake. And now i noticed that if i put -threads 0 right into the command line it really utilizes all cores. Thank you, Dark Shikari.
(Though it utilizes something like 60% still...but from all of my cores)
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.