Log in

View Full Version : Can I improve the X264 to make the CPU loading half?


nwumengfei
31st March 2008, 05:39
Hello everyone :

I have to find a codec which have a good performance than MPEG4 especially at CPU loading and video quality. I have made survey of a series codecs such as X264 T264 MPEG4 VC-1 AVS XVID, but I found that the codec either have a good video quality but with high CPU loading such as X264/T264 or a low CPU loading but with poor quality such as MPEG4. Now, I want to improve the X264/T264 codec by remove some features to make the CPU loading lower.
Can anyone give me some advices? Thank you in advance!:helpful:

Dark Shikari
31st March 2008, 05:43
You can lower x264's settings as necessary to speed it up. But past the bottom end of x264 settings, if you wanted to go any faster you'd have to seriously start gutting the program.

nwumengfei
31st March 2008, 08:18
Thank you, but I think it's difficult for me to reduce the CPU Loadig a half. Does anyone have a try before?

nm
31st March 2008, 12:27
Post your current x264 command-line. Then we can suggest changes to it.

CruNcher
31st March 2008, 12:38
i could think disabling hpel for example could give a nice speedup tough i don't recomend it :D

foxyshadis
1st April 2008, 08:34
likely the bizarrest way to post the command line that I've ever seen, but there you go.

Want faster? Try --partitions none --me dia --subme 1. It'll suck, but it'll be fast. Then look up dark shikari's list of x264 presets and look for one that's slightly faster than default settings.

And while you're at it MAKE SURE YOU'RE COMPILING WITH THE ASM. If you aren't then you're crippling the speed for no good reason.

jeffy
1st April 2008, 10:30
Thank you, but I think it's difficult for me to reduce the CPU Loadig a half. Does anyone have a try before?


What exactly do you mean? Do you want faster encoding or do you want low CPU usage (and low speed) when encoding?

Do you want to just limit the CPU load when encoding?

:thanks:

nwumengfei
2nd April 2008, 02:53
In fact I work in security monitorng,now there is a requirement of replace the old MPEG4 codec which can encode 16 channels CIF video stream at 30fps at the same time. The performance of H.264 codec is good except the CPU usage and encoding speed, so I need to low the CPU usage and fast the encoding speed as much as possible.

nwumengfei
2nd April 2008, 03:07
likely the bizarrest way to post the command line that I've ever seen, but there you go.

Want faster? Try --partitions none --me dia --subme 1. It'll suck, but it'll be fast. Then look up dark shikari's list of x264 presets and look for one that's slightly faster than default settings.

And while you're at it MAKE SURE YOU'RE COMPILING WITH THE ASM. If you aren't then you're crippling the speed for no good reason.

Thank you, I'll have a try!

jeffy
2nd April 2008, 07:31
In fact I work in security monitorng,now there is a requirement of replace the old MPEG4 codec which can encode 16 channels CIF video stream at 30fps at the same time. The performance of H.264 codec is good except the CPU usage and encoding speed, so I need to low the CPU usage and fast the encoding speed as much as possible.

Thank you for your reply. 16 channels CIF video stream at 30fps at the same time...

1) What is your CPU? Dual core? Quad Core? I think someone might suggest something tailored to your needs based mainly on the CPU performance.

2) How low CPU usage do you need? 50% (1 core of 2/2 cores of 4)?

3) Post your current x264 command-line (as requested by nm).

Dark Shikari
2nd April 2008, 08:27
In fact I work in security monitorng,now there is a requirement of replace the old MPEG4 codec which can encode 16 channels CIF video stream at 30fps at the same time. The performance of H.264 codec is good except the CPU usage and encoding speed, so I need to low the CPU usage and fast the encoding speed as much as possible.
To give you a general idea, 1920x1080 at 30 FPS requires roughly an 8 core Core 2 system at 2.4Ghz or above, preferably more like 3.2Ghz.

16 CIF streams are about 22% less demanding, so a top-end quad core could do the trick, though I'd really recommend an 8-core system.

The requirement might be quite a bit less for security footage because most of the videos are motionless at any one time.

nwumengfei
3rd April 2008, 07:33
Thankyou Jeffy and Dark Shikari
1) My environment is as follow:
Hard ware: CPU is P4 3.0G HZ hyper thread;
RAM 1GMB;
Software: Windows XP + sp2+ vc6+sp5+nasm0.98

X264 version:http://lspbeyond.go1.icpcn.com/x264/downloads/x264-060805.rar

X264 param I just use the default param that you can see the append file,actually it is a function.

2) Test result:

Foreman CIF 1 Channel 30 fps
encode speed: not more than 29 fps
CPU usage: 53%

Foreman CIF 2 Channel 30 fps
encode speed: each channel less than 19 fps
CPU usage: 98%

Bus CIF 1 Channel 30 fps
encode speed: not more than 28 fps
CPU usage: 51%

Bus CIF 2 Channel 30 fps
encode speed: each channel less than 17 fps
CPU usage: 97%

3) Question:

1 Considered some algorithms time complexity in H.264, can I achieve the goal ( In my environment, encode speed 120 fps and CPU usage less than 50%) by remove some H.264 minor details?

2 If the answer to question1 is true, Is there going to be a possible of that the H.264 codec degenerates to H.263 if I realize the aim?

Dark Shikari
3rd April 2008, 07:50
CPU is P4 3.0G HZ hyper thread;You expect to encode 16 streams in realtime on that?

I doubt you could even do that with H.263 or MPEG-4 ASP; I wouldn't be surprised if you had trouble with MPEG-2! :p

nwumengfei
3rd April 2008, 07:57
Can it encode 4 Channels CIF stream each with 30 fps in realtime?

ImmortAlex
3rd April 2008, 10:18
x264-060805.rar - quiet old version, I think. Last month or two I see good improvements in encoding speed.
"--partitions none --me dia --subme 1" may be enough for some number of CIF streams at such hardware, but not for 16 of them at 30 fps, even in b/w picture with small number of motion.
And... why do you need for 30 fps in security monitorng?

nm
3rd April 2008, 10:28
Can it encode 4 Channels CIF stream each with 30 fps in realtime?
That could be just achievable if the video is mostly stationary. I have a machine with the same hardware specs (I run Linux however), so I did a quick test for you with the Foreman CIF source:

x264: Fast parameters, 2 concurrent encodes, both slightly over 59 fps
MEncoder command line: mencoder foreman_cif.y4m -of rawvideo -ovc x264 -x264encopts crf=30:me=dia:subq=1:bframes=16 -o test.1.264 &
mencoder foreman_cif.y4m -of rawvideo -ovc x264 -x264encopts crf=30:me=dia:subq=1:bframes=16 -o test.2.264
Result: http://www.cs.helsinki.fi/u/mikkila/video/foreman/test.264


Ok, let's try to match that with libavcodec's MPEG-4 ASP encoder (comparable with XviD in speed and quality)...

1. Aim for the same file size, as fast as possible.
lavc: Default parameters, 2 concurrent encodes, both over 212 fps
mencoder foreman_cif.y4m -ovc lavc -lavcopts vcodec=mpeg4:vqscale=12:turbo:autoaspect -o test-lavc-fast.1.avi &
mencoder foreman_cif.y4m -ovc lavc -lavcopts vcodec=mpeg4:vqscale=12:turbo:autoaspect -o test-lavc-fast.2.avi
Result: http://www.cs.helsinki.fi/u/mikkila/video/foreman/test-lavc-fast.avi

2. Aim for roughly the same file size and encoding speed to compare quality.
lavc: Better/slower parameters, lower QP, both encodings 53 fps
mencoder foreman_cif.y4m -ovc lavc -lavcopts vcodec=mpeg4:vqscale=11:autoaspect:mbd=2:trell:v4mv:turbo:autoaspect -o test-lavc-slow.1.avi &
mencoder foreman_cif.y4m -ovc lavc -lavcopts vcodec=mpeg4:vqscale=11:autoaspect:mbd=2:trell:v4mv:turbo:autoaspect -o test-lavc-slow.2.avi
Result: http://www.cs.helsinki.fi/u/mikkila/video/foreman/test-lavc-slow.avi

So, the conclusion is pretty much the same as you had in your first post. MPEG-4 ASP can be fast, but you would need to use much higher bitrates than with H.264.

However, I did get x264 to run faster than you did. Even with the default settings, two concurrent encodings run at 34 fps (and the quality is much better than with my faster settings). You should definitely use a more recent x264 version if yours is really from 2006 as the package name suggests.

foxyshadis
4th April 2008, 08:50
I forgot, try --no-cabac as well. Make sure you use --threads 1, the default (0) will create too many threads on your system. You really need to have a real dual-core (Pentium D) for 4-8 streams and a core2 for the full 16.

As an aside, the security camera server our company bought ended up being almost 2U of empty space and a tiny P4 HT board. (I guess they use a low-end core2 now.) What a letdown. You don't happen to be using cctvfactory equipment, do you? ;p

nwumengfei
7th April 2008, 09:58
However, I did get x264 to run faster than you did. Even with the default settings, two concurrent encodings run at 34 fps (and the quality is much better than with my faster settings). You should definitely use a more recent x264 version if yours is really from 2006 as the package name suggests.

I use the X264 version here:
http://mirror05.x264.nl/Sharktooth/force.php?file=./x264/x264-Src_r635.7z
I try the command line as follow:
--bframes 0 --no-b-adapt --pre-scenecut --non-deterministic --no-ssim --no-psnr --partitions none --me dia --subme 1 --threads 1 --no-cabac -B 300 -o test.264 foreman_cif.yuv 352x288
But the encode speed is only 58 fps.
(The 264 file is appended)

There are lots of patchs here:http://forum.doom9.org/showthread.php?t=130364
But I don't know how to do with the .diff file in the windows platform:mad:

nm
7th April 2008, 11:37
I use the X264 version here:
http://mirror05.x264.nl/Sharktooth/force.php?file=./x264/x264-Src_r635.7z
That is still quite old. Try r807 from http://x264.nl/

I try the command line as follow:
--bframes 0 --no-b-adapt --pre-scenecut --non-deterministic --no-ssim --no-psnr --partitions none --me dia --subme 1 --threads 1 --no-cabac -B 300 -o test.264 foreman_cif.yuv 352x288
But the encode speed is only 58 fps.
You should use b-frames, they'll probably improve both quality and speed (at least if you turn adaptive decision off).

Did you try two encodings at the same time, or only one?

There are lots of patchs here:http://forum.doom9.org/showthread.php?t=130364
But I don't know how to do with the .diff file in the windows platform:mad:
I don't think that there are any patches available that would help in your case, so I wouldn't bother.