Log in

View Full Version : About X264 parameters


rhbc73
26th May 2013, 09:59
Hi friends,

I'm writing an application to convert videos to formats that are supported by different devices (iPhone5/4s/4/3GS..etc). So definitely I know what profiles and levels I want to encode into with x264.

I've found that there's an API x264_param_apply_profile to set profile, but couldn't find how to set level programmatically. Is i_level_idc the one that maps to H.264 level?

Another question is, since different profile/level has restrictions on max resolution, do I need to check input resolution first before
sending data to x264 encoder? If input resolution exceeds max resolution, will encoding fail directly?

The last question is about max bit-rate. If I can set level and profile, I think I still need to set the max-bitrate (I'll use crf for rate control, but I guess max bit-rate is still needed to guarantee that ouput stream comply with profile/level, is that correct?). So is it enough to set level, profile, vbv-max-bitrate and vbv-buf-size to get the desired profile/level I want?

And also as for the max bitrate, for example if I have a video with 2Mbps and want to convert into a profile/level with max bitrate of 50M, if I set 50M to vbv-max-bitrate, will the x264 encoder tries to match the output to that bit-rate, or encoder encodes as normal and only guarantees that output won't exceed that max value, so that the final output bitrate is still comparable with the input.

Great thanks!!!

sneaker_ger
26th May 2013, 17:14
Another question is, since different profile/level has restrictions on max resolution, do I need to check input resolution first before
sending data to x264 encoder? If input resolution exceeds max resolution, will encoding fail directly?

The last question is about max bit-rate. If I can set level and profile, I think I still need to set the max-bitrate (I'll use crf for rate control, but I guess max bit-rate is still needed to guarantee that ouput stream comply with profile/level, is that correct?). So is it enough to set level, profile, vbv-max-bitrate and vbv-buf-size to get the desired profile/level I want?

Wait for the answers of the devs, but I think you have to check other parameters like resolution and number of ref frames yourself, too, if you use libx264. When not using High Profile you might have to check for even more parameters.

And also as for the max bitrate, for example if I have a video with 2Mbps and want to convert into a profile/level with max bitrate of 50M, if I set 50M to vbv-max-bitrate, will the x264 encoder tries to match the output to that bit-rate, or encoder encodes as normal and only guarantees that output won't exceed that max value, so that the final output bitrate is still comparable with the input.

The encoder does not know that your input is only 2 Mbit/s, because it must be fed with the decompressed video data. It will neither try to hit 50 Mbit/s vbv-maxrate nor the 2 Mbit/s input, but will encode the decompressed data according to bitrate/crf. vbv-maxrate is just an upper limit according to vbv model.

rhbc73
27th May 2013, 03:04
Wait for the answers of the devs, but I think you have to check other parameters like resolution and number of ref frames yourself, too, if you use libx264. When not using High Profile you might have to check for even more parameters.

Yes, I guess I need to check them, because I saw handbrake also checks these values


The encoder does not know that your input is only 2 Mbit/s, because it must be fed with the decompressed video data. It will neither try to hit 50 Mbit/s vbv-maxrate nor the 2 Mbit/s input, but will encode the decompressed data according to bitrate/crf. vbv-maxrate is just an upper limit according to vbv model.

Thanks, then I still need to use crf for rate control.

Another question is, I want to know the difference of using profile+level+max-bitrate+vbv-buffer-size+crf vs just profie+crf on input videos that have far below level-specified max bitrate. I guess the output is pretty much the same quality, supplying level, max-bitrate+vbv-buffersize may just guarantee the output will comply to the spec (I mean if the input apparently can't produce output exceeding specified level, supplying those arguments won't improve the output quality), is it correct?

rhbc73
27th May 2013, 06:51
Hi guys, could anyone confirm with me that X264 will do nothing (image resize/limit fps) if frame_size * fps of my input video exceed the max decoding speed of specified level.

If X264 encoder does nothing, then I have to check resolution, fps etc myself.

Thanks

LoRd_MuldeR
27th May 2013, 10:57
H.264 Levels do not limit "decoding speed", but macroblocks per second (besides other things).

In case your input video exceeds the "macroblocks per second" limit of the selected Level, there is not much x264 can do about that, except for printing out a warning.

BTW: The "resize" filter is a feature of the CLI front-end, not the x264 encoder library. It won't be invoked, unless you explicit specify that...

rhbc73
28th May 2013, 04:27
H.264 Levels do not limit "decoding speed", but macroblocks per second (besides other things).

In case your input video exceeds the "macroblocks per second" limit of the selected Level, there is not much x264 can do about that, except for printing out a warning.

BTW: The "resize" filter is a feature of the CLI front-end, not the x264 encoder library. It won't be invoked, unless you explicit specify that...

Thanks friend. I know macroblocks per frame can be calculated by width*height/256, does that mean I only need to guarantee width*height/256 <= macroblocks per frame and width*height*fps/256 <= macroblocks per second?

:thanks:

benwaggoner
30th May 2013, 00:26
Thanks friend. I know macroblocks per frame can be calculated by width*height/256, does that mean I only need to guarantee width*height/256 <= macroblocks per frame and width*height*fps/256 <= macroblocks per second?
To figure out total macroblocks, the height and width need to be mod16 or rounded up to the next mod16 size.

rhbc73
30th May 2013, 02:54
To figure out total macroblocks, the height and width need to be mod16 or rounded up to the next mod16 size.

Thanks mate. Yes I got that!

Asmodian
30th May 2013, 21:08
Another question is, I want to know the difference of using profile+level+max-bitrate+vbv-buffer-size+crf vs just profie+crf on input videos that have far below level-specified max bitrate. I guess the output is pretty much the same quality, supplying level, max-bitrate+vbv-buffersize may just guarantee the output will comply to the spec (I mean if the input apparently can't produce output exceeding specified level, supplying those arguments won't improve the output quality), is it correct?

This is correct, safety first but it won't do anything unless it needs to.

That said, I have noticed very slight decreases in average bitrate when doing vbv constrained crf encodes even when the average bitrate is less than 1/10th the --vbv-maxrate. I am not sure if there were actually a few frames that needed to be reduced in size or if vbv changes something when it didn't need to. This effect was so minor I do not worry about it and I use vbv when targeting anything besides a desktop PC even when I don't expect it to kick in.