[webRTC VP8 encode function parameters] Target Bitrate and output bitrate is not matching

895 views
Skip to first unread message

Youngmok Jung

unread,
May 15, 2019, 2:30:52 AM5/15/19
to WebM Discussion
Hi everyone,

I am wondering if my setting is correct in VP8 codec and encode function

Currently I am getting a wrong output bitrate value from the encode function.

At start up time with webrtc the target bitrate slowly rises from 200Kbps to +2.5Mbps. And the expected behavior of VP8 encoder is to encode video matching the target bitrate.

But when target bitrate is set to 0.7Mbps the output bitrate is around 1.4Mbps
And when target bitrate is set to 1.5Mbps the output bitrate is fluctuating between 0.5Mbps~ 1.3Mbps


1. I am not sure what parameters are correct for encoder, correct my if wrong please.
 I used parameters like below for my VP8 Codec. 

[Parameters for Codec]
##################################
g_timebase.num = 1
g_timebase.den = 90000  
g_lag_in_frames = 0
rc_end_usage = lib.VPX_CBR
g_pass= 0 #lib.VPX_RC_ONE_PASS
rc_resize_allowed = 0
rc_min_quantizer = 2
rc_max_quantizer = 56 
rc_undershoot_pct = 100
rc_overshoot_pct = 15
rc_buf_initial_sz = 500
rc_buf_optimal_sz = 600
rc_buf_sz = 1000
kf_mode = lib.VPX_KF_AUTO
kf_max_dist = 3000
g_w = frame.width
g_h = frame.height
g_threads = number_of_threads(frame.width * frame.height,multiprocessing.cpu_count())
rc_target_bitrate = self.__target_bitrate // 1000
##################################

[Parameters for Encode Function]
##################################
 _vpx_assert(lib.vpx_codec_encode(
            self.codec, self.image, frame.pts, 
            self.timestamp_increment,
            flags, lib.VPX_DL_REALTIME))
##################################

{ frame.pts: timestamp   self.timestamp_increment is 90000 / 30 , I fixed the clockrate to 90000 and fps to 30 even if I use a 24 fps video, I tried 30fps video too but doensn't seems to work}


2.Also, Is there a parameters which should be considered for each video? I am using below parameters regardless of videos and target bitrate.

Thank you all for reading!

Jerome Jiang

unread,
May 16, 2019, 12:42:59 PM5/16/19
to webm-d...@webmproject.org
Hi Youngmok,

We have an example encoder for RTC case here:

It has all WebRTC type settings built in. You can take a look and try settings there.

Also could you please share your video clip with us so we can try on our side?

Thanks!

Best,

--
You received this message because you are subscribed to the Google Groups "WebM Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webm-discuss...@webmproject.org.
To view this discussion on the web visit https://groups.google.com/a/webmproject.org/d/msgid/webm-discuss/0e788254-6b2c-4684-a867-ffa8bfa18a20%40webmproject.org.

Youngmok Jung

unread,
May 16, 2019, 1:19:56 PM5/16/19
to WebM Discussion
Hi Jerome,

Thank you for your help and advice.

First, I used Bigbuckbunny from youtube. I share my mp4 file with google drive. url: https://drive.google.com/file/d/1FYAQ49ScGJ6MH_yPZZQWwFak0XZnW7xH/view?usp=sharing

I checked the example on the URL you gave, and found out example is using below parameter for real time encoding


[Example Parameters for Codec]
##################################
cfg.rc_dropframe_thresh = (unsigned int)strtoul(argv[9], NULL, 0);
cfg.rc_end_usage = VPX_CBR;
cfg.rc_min_quantizer = 2;
cfg.rc_max_quantizer = 56;
if (strncmp(encoder->name, "vp9", 3) == 0) cfg.rc_max_quantizer = 52;
cfg.rc_undershoot_pct = 50;
cfg.rc_overshoot_pct = 50;
cfg.rc_buf_initial_sz = 600;
cfg.rc_buf_optimal_sz = 600;
cfg.rc_buf_sz = 1000;
##################################

I confirmed that I am using the same parameter as given in example except for overshoot_pct. 

By the way, I had some progress in debugging

1. Encoded result was wrong like below image

Default:
Left one is frame index 305 image, and the next one is 317 index frame. It should contain similar scene.

frame_Index_305.jpgframe_Index_317.jpg


Modification:
I was able to resolve the issue by reducing the key frame max distance from 3000 to 120
And I guess it was because of Key Frame missing. 

Issue & Question remaining:
But shouldn't the VP8 auto keyframe mode should take care of this kind of problem?

2. My main issue, target bitrate differing with output bitrate is still on progress. 

 
Default:
In the webRTC native code and the example you gave, the min quantization value was 2 and max was 56 or 53.
When target bitrate is set to 0.7Mbps the output bitrate is around 1.4Mbps
And when target bitrate is set to 1.5Mbps the output bitrate is fluctuating between 0.5Mbps~ 1.3Mbps

Modification:
This issue was related with rate control quantization value. I read this quantization value is related to bitrate and encoded frame quality.
I changed the minimum quantization value from 2 to 0 and max from 56  to 63, I found out the target bitrate and output bitrate matched in most case and the fluctuation in output bitrate was not big.

Issue & Question remaining:
I am not sure how to control this value, should I check the output for every encode result of video I use?
After I changed minimum quantization value smaller, this time when the target bitrate is small at startup time the output bitrate was bigger like {Average Kbps:  919 Target Bitrate Kbps: 200}

Again Thank you very much!

With Regards 






2019년 5월 17일 금요일 오전 1시 42분 59초 UTC+9, Jerome Jiang 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to webm-d...@webmproject.org.

Jerome Jiang

unread,
May 16, 2019, 2:00:50 PM5/16/19
to webm-d...@webmproject.org
Thanks for sharing the clip.

Another question: what speed setting are you using ( passed to codec control VP8E_SET_CPUUSED)?

To unsubscribe from this group and stop receiving emails from it, send an email to webm-discuss...@webmproject.org.
To post to this group, send email to webm-d...@webmproject.org.
Visit this group at https://groups.google.com/a/webmproject.org/group/webm-discuss/.
To view this discussion on the web visit https://groups.google.com/a/webmproject.org/d/msgid/webm-discuss/c2a75f66-a5d9-4f63-9fb9-f694cdf0666f%40webmproject.org.
For more options, visit https://groups.google.com/a/webmproject.org/d/optout.
Message has been deleted

Youngmok Jung

unread,
May 16, 2019, 10:50:52 PM5/16/19
to WebM Discussion
Hi,

I used VP8E_SET_CPUUSED -6 and 8 threads for codec g_threads!

Thank you

With regards

Reply all
Reply to author
Forward
0 new messages