PDA

View Full Version : How to use a CLI version of x264 codec


Kostarum Rex Persia
6th June 2005, 16:09
How to use a CLI version of x264 codec,I am confused a lot.Where I can find a help for CLI,and why is CLI made after all.

celtic_druid
6th June 2005, 16:23
For help. Run it.

I guess originally it was made as an example app for the project. It showcases all new options before anything else. However now that it has avi/avs input and mp4 output, I would think it fair to say that it has outgrown its original purpose (assuming that I got that right).

bond
6th June 2005, 16:40
ok a small howto:

A) use x264gui, which is available here (http://forum.doom9.org/showthread.php?t=95415)
it doesnt offer all options as the vfw gui, but it allows you to output directly to .mp4 and also offers anamorphic resize


B) if you want to use the full power of the commandline encoder you have to feed it with commandlines that way:

1) create a .txt file and place it in the same folder as x264.exe and your source .avs
2) write down a commandline in the .txt which looks for example like this:
x264 --pass 1 --bitrate 700 --bframe 3 --b-pyramid --ref 5 --filter -5:-5 --analyse all --8x8dct --weightb --progress -o NUL input.avs
x264 --pass 2 --bitrate 700 --bframe 3 --b-pyramid --ref 5 --filter -5:-5 --analyse all --8x8dct --weightb --progress -o output.mp4 input.avs this is for a 2pass encode which uses 3 b-frames max, b-pyramid, 5 reference frames, loop, cabac, weighted biprediction and i8x8 of high profile

the currently available commandline switches are the following (but you dont need to set most of them anyways):
Options:

-h, --help Print this help

Frame-type options:

-I, --keyint <integer> Maximum GOP size [250]
-i, --min-keyint <integer> Minimum GOP size [25]
--scenecut <integer> How aggressively to insert extra I-frames [40]
-b, --bframes <integer> Number of B-frames between I and P [0]
--no-b-adapt Disable adaptive B-frame decision
--b-bias <integer> Influences how often B-frames are used [0]
--b-pyramid Keep some B-frames as references

--no-cabac Disable CABAC
-r, --ref <integer> Number of reference frames [1]
--nf Disable loop filter
-f, --filter <alpha:beta> Loop filter AlphaC0 and Beta parameters [0:0]

Ratecontrol:

-q, --qp <integer> Set QP [26]
-B, --bitrate <integer> Set bitrate
--qpmin <integer> Set min QP [10]
--qpmax <integer> Set max QP [51]
--qpstep <integer> Set max QP step [4]
--ratetol <float> Allowed variance of average bitrate [1.0]
--vbv-maxrate <integer> Max local bitrate [0]
--vbv-bufsize <integer> Size of VBV buffer [0]
--vbv-init <float> Initial VBV buffer occupancy [0.9]

--ipratio <float> QP factor between I and P [1.40]
--pbratio <float> QP factor between P and B [1.30]
--chroma-qp-offset <integer> QP difference between chroma and luma [0]

-p, --pass <1|2|3> Enable multipass ratecontrol:
- 1: First pass, creates stats file
- 2: Last pass, does not overwrite stats file
- 3: Nth pass, overwrites stats file
--stats <string> Filename for 2 pass stats ["x264_2pass.log"]
--rceq <string> Ratecontrol equation ["blurCplx^(1-qComp)"]
--qcomp <float> QP curve compression: 0.0 => CBR, 1.0 => CQP [0.60]
--cplxblur <float> Reduce fluctuations in QP (before curve compression) [20.0]
--qblur <float> Reduce fluctuations in QP (after curve compression) [0.5]

--zones <zone0>/<zone1>/...
Tweak the bitrate of some regions of the video
Each zone is of the form
<start frame>,<end frame>,<option>
where <option> is either
q=<integer> (force QP)
or b=<float> (bitrate multiplier)

Analysis:

-A, --analyse <string> Partitions to consider ["p8x8,b8x8,i8x8,i4x4"]
- p8x8, p4x4, b8x8, i8x8, i4x4
- none, all
(p4x4 requires p8x8. i8x8 requires --8x8dct.)
--direct <string> Direct MV prediction mode ["temporal"]
- none, spatial, temporal
-w, --weightb Weighted prediction for B-frames
--me <string> Integer pixel motion estimation method ["hex"]
- dia: diamond search, radius 1 (fast)
- hex: hexagonal search, radius 2
- umh: uneven multi-hexagon search
- esa: exhaustive search (slow)
--merange <integer> Maximum motion vector search range [16]
-m, --subme <integer> Subpixel motion estimation quality: 1=fast, 5=best. [5]
--no-chroma-me Ignore chroma in motion estimation
-8, --8x8dct Adaptive spatial transform size

Input/Output:

--level <integer> Specify level (as defined by Annex A)
--sar width:height Specify Sample Aspect Ratio
--fps <float|rational> Specify framerate
--seek <integer> First frame to encode
--frames <integer> Maximum number of frames to encode
-o, --output Specify output file

--threads <integer> Parallel encoding (uses slices)
--no-asm Disable all CPU optimizations
--no-psnr Disable PSNR computation
--quiet Quiet Mode
-v, --verbose Print stats for each frame
--progress Show a progress indicator while encoding
--visualize Show MB types overlayed on the encoded video
--aud Use access unit delimiters
3) after you have written down your commandline in the .txt, rename the .txt extension to .bat
4) doubleclick on the .bat file to execute it and start the twopass encode

thats it ;)

rawr
6th June 2005, 17:40
--filter -5:-5o_O'

rawr.

Kostarum Rex Persia
7th June 2005, 01:44
I was tried to compress x264 CLI from x264gui.exe,but when I set all the options,nothing happens,program didn't start to encode.I manualy enable Windows 95 compatibility mode from Windows XP,but again it not working at all.Suggestions?

bob0r
7th June 2005, 03:23
I was tried to compress x264 CLI from x264gui.exe,but when I set all the options,nothing happens,program didn't start to encode.I manualy enable Windows 95 compatibility mode from Windows XP,but again it not working at all.Suggestions?

@Kostarum Rex Persia:
I state again: you have to learn english a bit better.

bond already explained what you should do:
1: put x264.exe and x264gui.exe in the same directory
2: set your input/output and your settings
3: save your settings to the .bat files.
Combine those .bat files and START the .bat files via CMD
For example my .bat file setup:

I:\cap\_x264\cap.bat

start /belownormal /b /w x264 --progress --pass 1 --filter -2:-2 --qp 22 --bframes 2 --b-pyramid --ref 2 --subme 5 --8x8dct --analyse all --output NUL cap.avs
start /belownormal /b /w x264 --progress --pass 2 --filter -2:-2 --bitrate 1000 --bframes 2 --b-pyramid --ref 3 --8x8dct --analyse all --output cap.mp4 cap.avs
start /belownormal /b /w MP4Box -sbr -add cap.aac cap.mp4 -out x264.mp4

line1: encode x264 pass1
line2: encode x264 pass2(final pass)
line3: mux(merge) audio into the .mp4 file x264.exe created.

The x264gui.exe now ONLY CREATES the .BAT file lines for you, it does NOT START the encode itself, you have to do that yourself!

How?
Start > Run > CMD
-and in my case:
i:
cd cap\_x264
cap.bat

See also: http://x264.nl/public/x264cli_output.gif

I hope this helped you a little...


P.S.
x264.exe and x264cli.exe work fine in Windows XP, you don't have to use compatibility mode.

hpn
7th June 2005, 18:49
4) doubleclick on the .bat file to execute it and start the twopass encode

thats it ;)
Plus after starting the .bat file don't forget to change the x264.exe priority in Windows Task Manager (Ctrl+Alt+Del) to "low" as the CLI apps tend to run at almost "realtime" no matter that they are set to "normal" by default. This way you can completely forget that you're now encoding and keep working with your PC in the next 15 hours or so :)

p.s.
if you want the ultimate quality (It's very arguable though) you could try running this .bat:
x264 --pass 1 --bitrate 700 --bframe 5 --b-pyramid --ref 16 --qcomp 0.75 --ipratio 1.10 --pbratio 1.40 --filter -5:-5 --analyse all --8x8dct --weightb --me "esa" --merange 32 --progress -o NUL input.avs
x264 --pass 2 --bitrate 700 --bframe 5 --b-pyramid --ref 16 --qcomp 0.75 --ipratio 1.10 --pbratio 1.40 --filter -5:-5 --analyse all --8x8dct --weightb --me "esa" --merange 32 --progress -o ouput.mp4 input.avs
I've never heard of anyone encoding a complete movie this way, as it would take a month or so, but it's usable for short stuff like music videos :D

Leak
7th June 2005, 23:53
Plus after starting the .bat file don't forget to change the x264.exe priority in Windows Task Manager (Ctrl+Alt+Del) to "low" as the CLI apps tend to run at almost "realtime" no matter that they are set to "normal" by default.

This might be a bit offtopic, but why does everyone seem to use Ctrl+Alt+Del to bring up the Task Manager when Ctrl+Shift+Escape does the same thing, minus having to click another button? :)

Also, you can use the "start /low" command in a batch file to run a program at low priority without resorting to the Task Manager...

caisersousa
8th June 2005, 12:53
Hi, is possible make a 720*576 (full video without resize) and then resize this to 16/9 ?? (as mpeg2 but with x264)
Can I do this with SAR??

berrinam
8th June 2005, 14:17
This might be a bit offtopic, but why does everyone seem to use Ctrl+Alt+Del to bring up the Task Manager when Ctrl+Shift+Escape does the same thing, minus having to click another button? :)


In Ctrl+Alt+Del brings up Task Manager without any intermediate dialogs on WinXP. Anyway, Ctrl+Alt+Del is more comfortable to do than Ctrl+Shift+Escape (probably just because I never use Ctrl+Shift+Escape :D )

Leak
8th June 2005, 14:36
In Ctrl+Alt+Del brings up Task Manager without any intermediate dialogs on WinXP. Anyway, Ctrl+Alt+Del is more comfortable to do than Ctrl+Shift+Escape (probably just because I never use Ctrl+Shift+Escape :D )

Eh? I only have WinXP Pro at work (and W2K at home), but both here and at home Ctrl+Alt+Del brings up the Windows Security dialog with a few buttons like Lock Computer, Task Manager and Shutdown...

I assume you're using WinXP home, then? :p

(Oh, and Ctrl+Shift+Escape is easier to do with using only one hand than Ctrl+Alt+Delete... yeah, I'm lazy... :D)

bond
8th June 2005, 19:05
Hi, is possible make a 720*576 (full video without resize) and then resize this to 16/9 ?? (as mpeg2 but with x264)
Can I do this with SAR??
yepaa

berrinam
8th June 2005, 22:10
Eh? I only have WinXP Pro at work (and W2K at home), but both here and at home Ctrl+Alt+Del brings up the Windows Security dialog with a few buttons like Lock Computer, Task Manager and Shutdown...

I assume you're using WinXP home, then? :p

No, I'm on XP Pro, but I have no security dialog.


(Oh, and Ctrl+Shift+Escape is easier to do with using only one hand than Ctrl+Alt+Delete... yeah, I'm lazy... :D)

Well, I think that means bending the left hand too much. ;)


Sorry I'm so OT, I'll stop now

plonk420
9th June 2005, 07:13
shouldn't --merange be closer to 128 or 256? or at least 64? that's pixels, right?

akupenguin
9th June 2005, 07:22
shouldn't --merange be closer to 128 or 256? or at least 64? that's pixels, right?
You're thinking of mv_range, which defaults to 512. (It's in the API but not any frontends.)
For dia and hex, me_range is the max number of iterations.
For umh, it's the radius of the initial cross+grid, which is then followed by an interative hex.
For esa, it's the radius of exhaustive search.
In all cases, the search starts centered on a predicted mv, which is usually pretty close to the final one. And if it isn't close enough, dia and hex will just fail; more than ~16 iterations doesn't help.

plonk420
9th June 2005, 07:34
i guess i didn't (don't) understand motion estimation as much as i thought i did...

also, does --progress not consistantly work? i'm pretty sure the last time i used it (36 hours ago) on a P4 Dell somewhere else, it worked fine (build 253 IIRC). it doesn't seem to be working for me (both 253 and 255). the only difference is i'm on an athy64 now and using SP1a instead of SP2... --wtf no strikethru?

here's my current CLI:
x264 --bframes 3 --ref 3 --weightb --me "umh" --analyse all --progress --pass 2 --stats *.log --bitrate * --output *.mp4 *.avs

edit: i'm using bframes and ref based losely on what i used in the Nero h264 beta... (or what defaulted)

edit2: i'll look thru some threads after this thing is crunching away, but... 1000+ posts in one thread and a few more threads to go thru... *sighs* x264 needs a wiki... :\

cast42
9th June 2005, 13:30
Plus after starting the .bat file don't forget to change the x264.exe priority in Windows Task Manager (Ctrl+Alt+Del) to "low" as the CLI apps tend to run at almost "realtime" no matter that they are set to "normal" by default. This way you can completely forget that you're now encoding and keep working with your PC in the next 15 hours or so :)

p.s.
if you want the ultimate quality (It's very arguable though) you could try running this .bat:
x264 --pass 1 --bitrate 700 --bframe 5 --b-pyramid --ref 16 --qcomp 0.75 --ipratio 1.10 --pbratio 1.40 --filter -5:-5 --analyse all --8x8dct --weightb --me "esa" --merange 32 --progress -o NUL input.avs
x264 --pass 2 --bitrate 700 --bframe 5 --b-pyramid --ref 16 --qcomp 0.75 --ipratio 1.10 --pbratio 1.40 --filter -5:-5 --analyse all --8x8dct --weightb --me "esa" --merange 32 --progress -o ouput.mp4 input.avs
I've never heard of anyone encoding a complete movie this way, as it would take a month or so, but it's usable for short stuff like music videos :D

5 bframes is certainly not an ultimate setting. In a high motion scene, the quality of the B-frames will drop significantly because the interpolated frame is to different from surrounding P (or I) frame. Only for fairly static scenes it may makes sense. A first try with 2 or 3 b-frames might result in higher overall PSNR. Of course full search motion estimation will not bring you a lot extra.

Sergejack
9th June 2005, 15:46
5 bframes is certainly not an ultimate setting. In a high motion scene, the quality of the B-frames will drop significantly because the interpolated frame is to different from surrounding P (or I) frame. Only for fairly static scenes it may makes sense. A first try with 2 or 3 b-frames might result in higher overall PSNR. Of course full search motion estimation will not bring you a lot extra.

Would lower the reduction ratio of B-frame help ? (--pbratio 1.20)

----

I didn't quite get the "For esa, it's the radius of exhaustive search."
Does this make sense : [--me "esa" --merange 32] ? Much Sense ? ^^

anyway here is what I'm about to try :

x264 --pass 1 --bitrate 162 --keyint 1000 --min-keyint 250 --bframe 4 --b-pyramid --pbratio 1.20 --ref 15 --analyse all --8x8dct --weightb --progress --me "esa" --merange 32 -o NUL input.avs

x264 --pass 2 --bitrate 162 --keyint 1000 --min-keyint 250 --bframe 4 --b-pyramid --pbratio 1.20 --ref 15 --analyse all --8x8dct --weightb --progress --me "esa" --merange 32 -o output.mp4 input.avs

EDIT : it make my computer shut down after a while ^^'

superdump
9th June 2005, 16:24
I have a few points to make:

1) ESA is only really in place to test how good other ME methods are against the effective upper limit and should really not be used generally. It's just too damned slow and stupid. UMHex is very good and so is hex so use one of those.

2) The b-frame decision is adaptive so allowing more consecutive b-frames doesn't necessarily have a quality hit on your encode as more b-frames are only used when it's appropriate. I found through testing that --bframe 16 was perfectly acceptable and there is actually a PSNR increase as you allow more b-frames although I think the most I ever saw used in the stats logs was about 7.

3) I've been playing around trying to make the first pass as fast as possible and comparing to the quality hit, I have found that there is little to no hit using the following settings for a high profile result:

x264 -r 1 -b 3 -f -4:-4 -B 750 -p 1 -A none --direct temporal -w --me dia -m 1 -o output.mp4 input.avs
x264 -r 5 -b 3 -f -4:-4 -B 750 -p 3 -A all --direct temporal -w --me umh -m 5 --8x8dct -o output.mp4 input.avs

Using filter levels of 0 usually gives better psnr but I prefer the look of ~-2 to -5.

If anyone wishes to see my results data for testing that fast first pass then just ask and I may spam it in another thread. Basically you can easily run two passes with a very fast first pass (~3x the speed) with no quality deficit.

Sergejack
9th June 2005, 17:09
I'm running on a AMD XP 2000+; win xp; why does my computer keep shutting down when using the cli 255 version ? (it's the first one I try, using Extendex Search)

Sharktooth
9th June 2005, 17:14
If it shuts down there are 3 possible causes: high temperatures, overclock or faulty hardware.

Sergejack
9th June 2005, 19:25
If it shuts down there are 3 possible causes: high temperatures, overclock or faulty hardware.

no overclock, never got temperature problem before with any software.

anyway, I tried "umh" and my computer didn't shut down, the second pass just crashed. (I don't know when, I was away).
BTW : How not to override the first pass log, pls ?

Sharktooth
9th June 2005, 19:29
Do a hardware check-up (as adviced in the Hardware & software forum):
http://forum.doom9.org/showthread.php?t=54130

Sergejack
9th June 2005, 23:42
Are there some more definition avaliable for those settings ?

I'm mostly interested in understanding :
--b-bias
--ratetol
--qcomp
--qpstep

and quite interested in understanding the following :
--cplxblur
--qblur

BTW : --no-psnr improves speed :)

plonk420
10th June 2005, 01:40
BTW : --no-psnr improves speed :)

by how much? .1 fps? 1fps? more? and what's the resolution of the video?

Sergejack
10th June 2005, 01:49
by how much? .1 fps? 1fps? more? and what's the resolution of the video?

1-2 fps; amd 2000xp+ (underclocked~1800+); 384*288. all enable.

x264 --no-psnr --qpstep 4 --pass 1 --qpmin 1 --qcomp 0.60 --direct "spatial" --bitrate 162 --keyint 1000 --min-keyint 250 --bframe 7 --b-pyramid --pbratio 1.30 --ref 31 --analyse all --8x8dct --weightb --progress --me "umh" --merange 16 -o NUL CPR03.avs

x264 --no-psnr --qpstep 4 --pass 2 --qpmin 1 --qcomp 0.60 --direct "spatial" --bitrate 162 --keyint 1000 --min-keyint 250 --bframe 7 --b-pyramid --pbratio 1.30 --ref 31 --analyse all --8x8dct --weightb --progress --me "umh" --merange 16 -o output.mp4 CPR03.avs

EDIT : God damn it... ^^' : '--direct "spatial" ' I was actually encoding using that :(

bond
10th June 2005, 11:56
EDIT : God damn it... ^^' : '--direct "spatial" ' I was actually encoding using that :(
well why did you set it? :D

you dont have to set every option, x264 also has defaults ;)

Sergejack
10th June 2005, 14:40
well why did you set it? :D

you dont have to set every option, x264 also has defaults ;)

For testing purpose.
That also why even default option are set because I reusesed those param with differents settings.

Sergejack
10th June 2005, 22:14
sry to insist, but :

Are there some more definition avaliable for those settings ?

I'm mostly interested in understanding :
--b-bias
--ratetol
--qcomp
--qpstep

and quite interested in understanding the following :
--cplxblur
--qblur

bond
10th June 2005, 22:20
read the mencoder manual on x264:
http://mplayerhq.hu/DOCS/man/en/mplayer.1.html

redfordxx
20th November 2005, 16:13
Is not any priority setting parameter in command line?

bond
21st November 2005, 00:10
Is not any priority setting parameter in command line?use thw windows cmdl priority switch