View Full Version : Regarding x264 project
I need help regarding bitrate variations in x264.
I am changing the bitrate for x264 on the fly in my system for CBR ratecontrol.
This i am doing by pausing my x264 system and updating new bitrate value and playing back the sytem.
Here i am making vbv mode to 0, but i am not getting good results.
But if i change CRF constant value on the fly for CRF ratecontrol in the same way as described above its working fine.
Can anybody help in changing the bitrate on the fly for CBR ratecontrol of x264?
Dark Shikari
4th March 2010, 09:01
I don't understand what you are talking about. "Making VBV mode to zero"?
By saying vbv mode 0 i mean i am not setting vbv buffersize externally.
i am setting just the bitrate from input interface.
Dark Shikari
4th March 2010, 09:19
That will not get you anywhere.
If you want CBR, set CBR. x264's interface only allows you to change the bitrate on the fly in CBR mode, not in ABR mode.
Can u tell me how to set CBR mode in x264.
I am just setting bitrate by this command --bitrate 2048
any other extra setting is required for making it to run in CBR mode?
Dark Shikari
4th March 2010, 09:32
Can u tell me how to set CBR mode in x264.
I am just setting bitrate by this command --bitrate 2048
any other extra setting is required for making it to run in CBR mode?--vbv-maxrate 2048 --vbv-bufsize X, where X is your buffer size. bufsize / maxrate is equal to the number of seconds that the client must be set to buffer before displaying video.
I have set in the same way.
But i observed that if i set bitrate 2mbps i reaches just 1.2 mbps and quality is not good. How to sort this out ?
One more observation is:
If i choose CRF ratecontrol and set rf_constant on the fly ( this is done by pausing the system, changing rf_constant and setting system back to playing mode) the quality is good. So what i did was varied the rf_constant from 20 to 30 and saw bitrate at each vaue.
Made this as lookup table and giving to system to change rf constant value on the fly as the bandwidth changes.For this quality is good.
What do suggest am i on right track? Can i do this?
Dark Shikari
4th March 2010, 09:51
I have set in the same way.
But i observed that if i set bitrate 2mbps i reaches just 1.2 mbps and quality is not good. How to sort this out ?I can't do anything without a sample of your output and your exact settings.
One more observation is:
If i choose CRF ratecontrol and set rf_constant on the fly ( this is done by pausing the system, changing rf_constant and setting system back to playing mode)Erm, why not use encoder_reconfig?
I can send u the output, let me know ur email id pls.
Regarding x264_encoder_reconfig i ve already tried this method by
calling it in x264_ratecontrol_start this function.
But it didnot work as the param structure was not present here.
How can i make it work here?
Dark Shikari
4th March 2010, 10:12
x264_ratecontrol_start is not a public API function. As such, you should not be calling it.
You should not be calling any function that is not in x264.h.
If you want to upload a sample, use mediafire.
I will try all the options u ve mentioned and upload the results by tomo.
Thanks a lot for the guidance.
I tried doing encoder_reconfig, its not working out.
Let me explain indetail:
The system setup i am using is capturing video thro a camera and then sending it to x264 encoder and then decoding using ffmpeg decoder and this pipeline is established thro gstreamer and the farsight.
So on the fly 'm changing the rf_constant thro set_property option in gstreamer.
But the changed value is not reflecting.
Can u tel me what is going wrong?
Dark Shikari
5th March 2010, 10:39
I tried doing encoder_reconfig, its not working out.
Let me explain indetail:
The system setup i am using is capturing video thro a camera and then sending it to x264 encoder and then decoding using ffmpeg decoder and this pipeline is established thro gstreamer and the farsight.
So on the fly 'm changing the rf_constant thro set_property option in gstreamer.
But the changed value is not reflecting.
Can u tel me what is going wrong?gstreamer's x264enc interface is completely broken. Do not use it for any reason.
It does not use encoder_reconfig, its defaults are broken, and it doesn't expose most options.
Can u suggest me any way of establishing a similar interface as gstreamer.
Or let me put my question directly can u tel me any method of changing the bitrate on the fly for CBR so that i can manage my bandwidth.
Dark Shikari
5th March 2010, 11:04
Can u suggest me any way of establishing a similar interface as gstreamer.Use the libx264 interface directly via the functions provided in x264.h.Or let me put my question directly can u tel me any method of changing the bitrate on the fly for CBR so that i can manage my bandwidth.Call x264_encoder_reconfig after changing bitrate, vbv-bufsize, and vbv-maxrate.
It is not clear for me.
Can u pls explain in detail.With this how can i change bitrate on the fly.
Thing is when badwidth drops i ve to change the bitrate accordingly so how can i change it using libx264?
Dark Shikari
5th March 2010, 11:30
It is not clear for me.
Can u pls explain in detail.With this how can i change bitrate on the fly.
Thing is when badwidth drops i ve to change the bitrate accordingly so how can i change it using libx264?Read the documentation in x264.h.
If you still can't figure it out from the information you've been given, I'm not sure what to say...
k..thank u for the clarifying things about gstreamers' interface problem.
I will workout now libx264 and get back u.
I have tried out few options based on ur suggestion for on the fly CRF and CBR methods.
1. For CRF:
As u suggested i'm calling reconfig in x264-encoder_encode and setting the new value to "rc.f_rf_constant" . This works like a charm.
One thing i noticed here is that after i reach rf_constant to 22 or 21 the video is delayed. This is making it unsuitable for real time streaming. Can u suggest anything here?
2. For CBR
In the same way as above i modified the reconfig for bitrate by setting the new value to "rc.i_bitrate" .But this is not reflecting.It still works in the previous bitrate value. Am I missing something else?
The following are the x264 parameters which v r using to manage these methods of ratecontrol:
i_rc_method 5(CRF) 0(CBR)
i_qp_constant 23 23
i_qp_min 10 10
i_qp_max 51 51
i_qp_step 4 4
i_bitrate 0 2048
f_rf_constant 23 23
f_rate_tolerance 1 1
i_vbv_max_bitrate 0 2048
i_vbv_buffer_size 0 2048
Note: Others params defaulted.
Dark Shikari
9th March 2010, 06:12
I have tried out few options based on ur suggestion for on the fly CRF and CBR methods.
1. For CRF:
As u suggested i'm calling reconfig in x264-encoder_encode and setting the new value to "rc.f_rf_constant" . This works like a charm.
One thing i noticed here is that after i reach rf_constant to 22 or 21 the video is delayed. This is making it unsuitable for real time streaming. Can u suggest anything here?What do you mean you're calling it "in x264_encoder_encode"? You should call it from your own application, not from within x264.
The video is delayed because x264 has an internal lookahead of about 40-50 frames. If you want to reduce this, look at --tune zerolatency.2. For CBR
In the same way as above i modified the reconfig for bitrate by setting the new value to "rc.i_bitrate" .But this is not reflecting.It still works in the previous bitrate value. Am I missing something else?
The following are the x264 parameters which v r using to manage these methods of ratecontrol:You need to change bitrate, VBV maxrate, and VBV buffer size.
What do you mean you're calling it "in x264_encoder_encode"? You should call it from your own application, not from within x264.
In my application whenever I need a change in rf_constant I call reconfig and then encoder_encode. In the reconfig I have copied the "rc.f_rf_constant" and then I do a "x264_ratecontrol_new". If I don't call "x264_ratecontrol_new" the new rf_constant value does not reflect (i.e. the image quality remains the same). With these changes the CRF on the fly is working fine.
The video is delayed because x264 has an internal lookahead of about 40-50 frames. If you want to reduce this, look at --tune zerolatency.
I have already set the "rc.i_lookahead" and "i_sync_lookahead" to 0. Looking at zerolatency, I will try setting the other 2 params (i_bframe, b_sliced_threads) as well and revert back.
You need to change bitrate, VBV maxrate, and VBV buffer size.
Will try this as well and let you know, the updates.
Thanks a lot for your time in guiding me :)
Dark Shikari
9th March 2010, 08:01
In my application whenever I need a change in rf_constant I call reconfig and then encoder_encode. In the reconfig I have copied the "rc.f_rf_constant" and then I do a "x264_ratecontrol_new". If I don't call "x264_ratecontrol_new" the new rf_constant value does not reflect (i.e. the image quality remains the same). With these changes the CRF on the fly is working fine.Don't call ratecontrol_new! If the new rf_constant doesn't take effect, your x264 is too old; the reconfiguration support you are using was implemented extremely recently (http://git.videolan.org/?p=x264.git;a=commit;h=f555cf3758f46f3c4f7a2f05094b16f8f3c25a27).
Do remember you have to do the following process:
x264_param_t param;
x264_encoder_parameters( h, ¶m );
<set your new options here>
x264_encoder_reconfig( h, ¶m);
Again, do not call any function not defined in x264.h, ever! In fact, just don't include anything other than x264.h.
It is working with the latest encoder code ie 8th March 2010.
I saw the commit of 29th Jan, last month and started using code of 31st Jan and it didn't have the changes also looked at Feb 4th code. So we started working with 31 Jan code...
But now when i see yest's code...it has all the changes.. working :0
Thanks a lot :D
GEFORCEXTREME
11th March 2010, 06:45
Hi, I'm a newbie to Linux and x264 but I'm thinking of doing something similar to n_j.
x264_param_t p;
x264_encoder_parameters( handle, &p );
p.rc.i_vbv_buffer_size /= 2;
p.rc.i_vbv_max_bitrate /= 2;
x264_encoder_reconfig( handle, &p );
With reference to http://x264dev.multimedia.cx/?p=286, how do we use the function x264_encoder_reconfig? How do I write a program, who would take various types of multimedia input files (maybe with the help of ffmpeg's libavformat library), and then transcode it to H.264 format for streaming? Similar to n_j, I would like the option of being able to change encoder parameters on the fly at a fixed time interval, which I *think* is by changing some parameters related to the encoder and then calling x264_encoder_reconfig?
Does this mean in the x264 application (that we run by ./x264), we would not be able to do the above task? So the function x264_encoder_reconfig can only be used in our written application that uses x264's libraries?
I've learnt a little about programing a video player using ffmpeg's libavcodec & libavformat libraries. How do I write a program that would do H.264 encoding using x264's libraries? Any starting guides? Tips?
Please help, and thank you in advance.
Dark Shikari
11th March 2010, 06:53
x264.c is a very good example of how to write a program that uses x264's libraries ;)
You can of course use it as a base and modify as necessary if you want.
n_j
17th March 2010, 04:51
Hey i wanted to know whether u ve any plans of supporting SVC in x264 in near future?
Dark Shikari
17th March 2010, 05:00
Hey i wanted to know whether u ve any plans of supporting SVC in x264 in near future?No .
n_j
18th March 2010, 06:27
Can i use x264 code as base code to extend to SVC or is it not extendable?
Dark Shikari
18th March 2010, 06:34
Can i use x264 code as base code to extend to SVC or is it not extendable?Sure, you could, but it would be a lot of work.
Nothing to do with x264, of course, it's just a lot of work.
n_j
18th March 2010, 06:48
Sure, you could, but it would be a lot of work.
Nothing to do with x264, of course, it's just a lot of work.
k let me figure out the complexity in doing this.
thanku...
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.