w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
975 stars 137 forks source link

WebCodec using VP9 codec, SVC and variable bitrate mode, does not adhere to given desired bitrate. #584

Closed kalradivyanshu closed 1 year ago

kalradivyanshu commented 1 year ago

Chrome Version : 106.0.5249.119 (Official Build) (64-bit) (cohort: Stable Installs & Version Pins) URLs (if applicable) : https://codepen.io/kalradivyanshu/pen/OJZqKve Other browsers tested: 107.0.5304.36 (Official Build) beta (64-bit) (cohort: Beta) FAIL 109.0.5362.0 (Official Build) canary (64-bit) (cohort: Clang-64) FAIL

have tested this issue: Edge: 106.0.1370.47 (Official build) (64-bit) FAIL

What steps will reproduce the problem?

(1) Start a video encoder with SVC setting L1T3, codec: vp09.00.10.08, bitrateMode: variable and bitrate: 2500000, then encode a 1080p30fps video. (2) Calculate the bitrate of the encoded video by using the encodedChunk's byteLength property

What is the expected result?

The bitrate should be within reasonable limit of 2.5mbps

What happens instead?

The bitrate is consistantly above 19mbps (for this video: https://www.youtube.com/watch?v=hmE9f-TEutc, shared via getDisplayMedia) and gets to as high as 55mbps+.

Please provide any additional information below. Attach a screenshot if possible.

This issue only happens for vp9 (both profile 0 and profile 2) + variable bitrateMode + SVC (L1T2 or L1T3 both).

If we set the bitrateMode to constant, it adheres to the bitrate recommendation, if we turn off SVC mode, it works even with variable bitrateMode.

For VP8, it works for all SVC modes, and all bitrate mode, the problem is specifically for VP9.

We were able to get this error on chrome stable, beta, canary, and edge stable.

Here is the reproducable codepen: https://codepen.io/kalradivyanshu/pen/OJZqKve . Click on any of the button, and give permission to access your screen, and it should start working. We made the attached tables by sharing the tab playing this youtube video: https://www.youtube.com/watch?v=hmE9f-TEutc.

It was reproducable in other youtube videos also, as long as there is motion on screen, since those have a higher bitrate.

The stats shown are the average bitrate of the last 2 seconds of video, the deltaframe size and keyframe size are average size since the begining of the video.

VP8 constant bitrate SVC

vp8_const_svc

VP8 variable bitrate SVC

vp8_variable_svc

VP9 constant bitrate SVC

vp9_const_svc

VP9 variable bitrate SVC

vp9_variable_svc

kalradivyanshu commented 1 year ago

I also opened this bug in chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1375111 since it seems to be an implementation issue, I just wanted to confirm once that this is not supposed to happen and the configuration is correct.

This is the configuration that is causing the bitrate to jump all over the place:

{
          height: 1080,
          width: 1920,
          codec: "vp09.00.10.08",
          scalabilityMode: "L1T3",
          bitrate: 2_500_000,
          framerate: 30,
          bitrateMode: "variable",
          latencyMode: "realtime"
}

Thanks!

aboba commented 1 year ago

@kalradivyanshu I have seen something similar, with VP9 producing encoded chunks the size of keyframes, even when a delta frame was requested. It happens regardless of the latencyMode ("quality" or "realtime"). I see this even when preferring software, so it is not the effect of errant hw acceleration.

Below is the frame size distribution I am seeing, with 1 Mbps target rate, 30 fps, VP9, "no preference" and L1T3. This is on Windows 10 (Surface Pro 7). VP-bug

kalradivyanshu commented 1 year ago

Yeah, but if i set the bitrate mode to constant, it goes away. With VP8 it works on all configurations. For me the bitrate increased to as high as 60mbps.

dalecurtis commented 1 year ago

The chromium bug tracker looks like the right place for this.