encoder constant bitrate

31 views
Skip to first unread message

Peter Gusev

unread,
Apr 2, 2019, 7:16:36 PM4/2/19
to codec...@webmproject.org
Hi,

Wanted to check in with the community on the expected encoder behavior.
I have a 1280x720 video which I encode at 30fps, GOP 30, 3000 bitrate. (see attached source code for the full encoder setup). 
I then collect 1000 individual encoded frame sizes in bytes and plot them (alongside GOP number to see when new Key frame was generated).
From the data I collect, calculated bitrate is about 1000.
And the plot (see attached) shows occasional spikes in frame sizes (I'd expect Key frames be these spikes, but surprisingly, this is not the case).

I'm not a video encoder expert, thus I would like to check in with more experienced folks on the following:
-- should the resulted bitrate (~1K) be of a concern? why encoder does not target for specified (3K) bitrate?
-- is there any way to force encoder not to generate "spikes", i.e. keep frame sizes relatively the same? from the encoder setup source file you can see I use rc_undershoot_pct and rc_overshoot_pct, but it doesn't seem to be helping.
-- is there any way to predict when encoder is about to generate a "spike"?

Thanks,
chart (1).png

--
Peter Gusev

+1 213 587-27-48

Research Scholar @ REMAP UCLA
Video streaming/ICN networks/Creative Coding/Interactive Media
encoder-setup.cpp

James Zern

unread,
Apr 2, 2019, 7:53:12 PM4/2/19
to codec...@webmproject.org
Hi,

On Tue, Apr 2, 2019 at 4:16 PM Peter Gusev <gpee...@gmail.com> wrote:
>
> Hi,
>
> Wanted to check in with the community on the expected encoder behavior.
> I have a 1280x720 video which I encode at 30fps, GOP 30, 3000 bitrate. (see attached source code for the full encoder setup).
> I then collect 1000 individual encoded frame sizes in bytes and plot them (alongside GOP number to see when new Key frame was generated).
> From the data I collect, calculated bitrate is about 1000.
> And the plot (see attached) shows occasional spikes in frame sizes (I'd expect Key frames be these spikes, but surprisingly, this is not the case).
>

Can you include the command line you used to generate the content?

> I'm not a video encoder expert, thus I would like to check in with more experienced folks on the following:
> -- should the resulted bitrate (~1K) be of a concern? why encoder does not target for specified (3K) bitrate?
>

That can depend on the content and the encoder settings used. The
encoder may undershoot on easier material or if the chosen bitrate is
overly high for the resolution.

> -- is there any way to force encoder not to generate "spikes", i.e. keep frame sizes relatively the same? from the encoder setup source file you can see I use rc_undershoot_pct and rc_overshoot_pct, but it doesn't seem to be helping.
>

You can further control key frame sizes with the max-intra-rate [1]
option for vp8/9, vp9 also allows tuning on inter [2].

> -- is there any way to predict when encoder is about to generate a "spike"?
>

In general the encoder will spend more bits on key frames, golden
frames and alternate reference frames (controlled by --lag-in-frames,
but it's a range rather than a forced distance).

[1] https://chromium.googlesource.com/webm/libvpx/+/refs/heads/master/vpx/vp8cx.h#241
[2] https://chromium.googlesource.com/webm/libvpx/+/refs/heads/master/vpx/vp8cx.h#262

> Thanks,
>
>
> --
> Peter Gusev
> gpee...@gmail.com
>
> +1 213 587-27-48
>
> Research Scholar @ REMAP UCLA
> Video streaming/ICN networks/Creative Coding/Interactive Media
>
> --
> You received this message because you are subscribed to the Google Groups "Codec Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to codec-devel...@webmproject.org.
> To post to this group, send email to codec...@webmproject.org.
> Visit this group at https://groups.google.com/a/webmproject.org/group/codec-devel/.
> For more options, visit https://groups.google.com/a/webmproject.org/d/optout.

Peter Gusev

unread,
Apr 2, 2019, 8:22:55 PM4/2/19
to codec...@webmproject.org
Hi James,

Thanks for the feedback, I'll take a look at these parameters and re-run my experiments.
This file is 240 frames long, so I looped it until I get 1000 frames encoded. It is also interesting, that I don't immediately see the pattern (though, on a second look, there might be a pattern...).
I used my own code (not vpxenc) to run the experiments.

> That can depend on the content and the encoder settings used. The
> encoder may undershoot on easier material or if the chosen bitrate is
> overly high for the resolution.

How one would empirically determine the reasonable bitrate based on content? 
My first thought is: to start small and watch for dropped frames, increase target bitrate until encoder stops dropping frames -- will this work?

Thanks,

Peter Gusev

unread,
Apr 2, 2019, 8:39:07 PM4/2/19
to codec...@webmproject.org
I already use VP8E_SET_MAX_INTRA_BITRATE_PCT in my code set to 130.
When trying to use VP9E_SET_MAX_INTER_BITRATE_PCT I get this compile error:

src/video-codec.cpp:289:11: error: use of undeclared identifier 'vpx_codec_control_VP9E_SET_MAX_INTER_BITRATE_PCT'; did you mean 'vpx_codec_control_VP8E_SET_MAX_INTER_BITRATE_PCT'?
    res = vpx_codec_control(&vpxCodec_, VP9E_SET_MAX_INTER_BITRATE_PCT, 450);   // TODO: tune like in WebRTC?
          ^
/usr/local/include/vpx/./vpx_codec.h:402:3: note: expanded from macro 'vpx_codec_control'
  vpx_codec_control_##id(ctx, id, data) /**<\hideinitializer*/
  ^
<scratch space>:23:1: note: expanded from here
vpx_codec_control_VP9E_SET_MAX_INTER_BITRATE_PCT
^
/usr/local/include/vpx/vp8cx.h:936:1: note: 'vpx_codec_control_VP8E_SET_MAX_INTER_BITRATE_PCT' declared here
VPX_CTRL_USE_TYPE(VP8E_SET_MAX_INTER_BITRATE_PCT, unsigned int)
^
/usr/local/include/vpx/./vpx_codec.h:419:26: note: expanded from macro 'VPX_CTRL_USE_TYPE'
  static vpx_codec_err_t vpx_codec_control_##id(vpx_codec_ctx_t *ctx,        \
                         ^
<scratch space>:30:1: note: expanded from here
vpx_codec_control_VP8E_SET_MAX_INTER_BITRATE_PCT
^
1 error generated.
make: *** [src/libndnrtc_la-video-codec.lo] Error 1

Seems like there's VP8E_SET_MAX_INTER_BITRATE_PCT but it's not exposed in the library?
Thanks,

James Zern

unread,
Apr 3, 2019, 9:07:25 PM4/3/19
to codec...@webmproject.org
On Tue, Apr 2, 2019 at 5:39 PM Peter Gusev <gpee...@gmail.com> wrote:
>
> I already use VP8E_SET_MAX_INTRA_BITRATE_PCT in my code set to 130.
> When trying to use VP9E_SET_MAX_INTER_BITRATE_PCT I get this compile error:
>
> src/video-codec.cpp:289:11: error: use of undeclared identifier 'vpx_codec_control_VP9E_SET_MAX_INTER_BITRATE_PCT'; did you mean 'vpx_codec_control_VP8E_SET_MAX_INTER_BITRATE_PCT'?
> res = vpx_codec_control(&vpxCodec_, VP9E_SET_MAX_INTER_BITRATE_PCT, 450); // TODO: tune like in WebRTC?
> ^

Thanks for trying it out, looks like a really old typo [1]. As a
workaround until a fix is in place you can use 'vpx_codec_control_'
(not the trailing '_') to avoid the type check.

[1] https://chromium-review.googlesource.com/c/webm/libvpx/+/74073

Peter Gusev

unread,
Apr 4, 2019, 3:32:38 PM4/4/19
to codec...@webmproject.org
Thanks! I tried playing with both parameters VP8E_SET_MAX_INTRA_BITRATE_PCT and VP9E_SET_MAX_INTER_BITRATE_PCT and ran codec on the test video, but they seem to have no effect whatsoever on the "spikes" issue. 
Do you have an idea what else I might try?

Thanks,

--
You received this message because you are subscribed to the Google Groups "Codec Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codec-devel...@webmproject.org.
To post to this group, send email to codec...@webmproject.org.
Visit this group at https://groups.google.com/a/webmproject.org/group/codec-devel/.
For more options, visit https://groups.google.com/a/webmproject.org/d/optout.

James Zern

unread,
Apr 8, 2019, 8:39:57 PM4/8/19
to codec...@webmproject.org
On Thu, Apr 4, 2019 at 12:32 PM Peter Gusev <gpee...@gmail.com> wrote:
>
> Thanks! I tried playing with both parameters VP8E_SET_MAX_INTRA_BITRATE_PCT and VP9E_SET_MAX_INTER_BITRATE_PCT and ran codec on the test video, but they seem to have no effect whatsoever on the "spikes" issue.
> Do you have an idea what else I might try?
>

Are you trying 2 pass or 1 pass encodes? You can try modifying the
rc_buf_* configuration variables or try the other rate control modes
that I suggested, CBR isn't as actively maintained.

Marco Paniconi

unread,
Apr 9, 2019, 12:43:31 PM4/9/19
to codec...@webmproject.org
On Mon, Apr 8, 2019 at 5:39 PM 'James Zern' via Codec Developers <codec...@webmproject.org> wrote:
On Thu, Apr 4, 2019 at 12:32 PM Peter Gusev <gpee...@gmail.com> wrote:
>
> Thanks! I tried playing with both parameters VP8E_SET_MAX_INTRA_BITRATE_PCT and VP9E_SET_MAX_INTER_BITRATE_PCT and ran codec on the test video, but they seem to have no effect whatsoever on the "spikes" issue.
> Do you have an idea what else I might try?
>

For 1 pass you can try running with this sample encoder, which contains the webrtc type settings: 
examples/vpx_temporal_svc_encoder input.1280_720.yuv out vp9 1280 720 1 30 7 0 0 1 0 3000

You'll need to set cfg.kf_max_dist (=30 for your case) in examples/vpx_temporal_svc_encoder.c,  and use something like max_intra_size_pct = 100 and rc_max_quantizer = 56 (or higher).
Reply all
Reply to author
Forward
0 new messages