[FFmpeg-devel] Live streaming of VP8

James Zern jzern at google.com
Sat Jun 9 23:50:33 CEST 2012


On Sat, Jun 9, 2012 at 8:14 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sat, Jun 09, 2012 at 04:51:23PM +0200, Andy Bell wrote:
>> Hi All,
>>
>> I am streaming a VP8 stream over network and using the following code to
>> encode:
>>
>> _bitRate = 500 * 1000;
>> _codecContext->bit_rate = _bitRate; // --target-bitrate=500
>> _codecContext->rc_min_rate = _codecContext->rc_max_rate =
>> _codecContext->bit_rate; // --end-usage=cbr

Pairing vbr with realtime (quality=realtime/deadline=1) is probably a
better choice for live encoding.

>>
>> _codecContext->thread_count = 4;
>> _codecContext->qmin = 4;
>> _codecContext->qmax = 56;
>> _codecContext->width = 800;
>> _codecContext->height = 600;
>> _codecContext->rc_buffer_aggressivity = 0.95;  // --undershoot-pct=95
>> _codecContext->rc_buffer_size = _bitRate * 6; // --buz-sz=6000 ms
>> _codecContext->rc_initial_buffer_occupancy = _bitRate * 4; //
>> --buf-initial-sz=4000 ms
>> _codecContext->profile = 3;

You probably don't want to set this. It impacts decode complexity at
the cost of encode quality.

>> _codecContext->time_base.num = 1;
>> _codecContext->time_base.den = 25;
>> _codecContext->gop_size = 999999; // --kf-max-dist
>>
>> This works fine but when there is a huge scene change the codec generates a
>> key frame which I am having trouble transmitting in realtime over the
>> network due to the sudden jump in bitrate.
>
> rc_buffer_size indicates a wanted max latency of 6 seconds
> if you want it to be less you can use a smaller value
>

This will help overall bitrate spikes and as I mentioned on
webm-discuss you might be looking for the max-intra-rate option. I've
attached a patch to add this option.
-------------- next part --------------
From c93b99e6b9e1afccb5ca687ffe891386b3c449e5 Mon Sep 17 00:00:00 2001
From: James Zern <jzern at google.com>
Date: Sat, 9 Jun 2012 14:40:51 -0700
Subject: [PATCH] libvpxenc: add VP8E_SET_MAX_INTRA_BITRATE_PCT mapping

defines 'max-intra-rate' in line with vpxenc param
---
 configure              |    4 ++--
 libavcodec/libvpxenc.c |    5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 7a60f29..673645f 100755
--- a/configure
+++ b/configure
@@ -3229,8 +3229,8 @@ enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lv
 enabled libvpx     && {
     enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
                                 die "ERROR: libvpx decoder version must be >=0.9.1"; }
-    enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
-                                die "ERROR: libvpx encoder version must be >=0.9.6"; } }
+    enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VP8E_SET_MAX_INTRA_BITRATE_PCT" -lvpx ||
+                                die "ERROR: libvpx encoder version must be >=0.9.7"; } }
 enabled libx264    && require  libx264 x264.h x264_encoder_encode -lx264 &&
                       { check_cpp_condition x264.h "X264_BUILD >= 118" ||
                         die "ERROR: libx264 version must be >= 0.118."; }
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 58a44ec..b3ec17d 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -74,6 +74,7 @@ typedef struct VP8EncoderContext {
     int lag_in_frames;
     int error_resilient;
     int crf;
+    int max_intra_rate;
 } VP8Context;
 
 /** String mappings for enum vp8e_enc_control_id */
@@ -95,6 +96,7 @@ static const char *const ctlidstr[] = {
     [VP8E_SET_ARNR_STRENGTH]     = "VP8E_SET_ARNR_STRENGTH",
     [VP8E_SET_ARNR_TYPE]         = "VP8E_SET_ARNR_TYPE",
     [VP8E_SET_CQ_LEVEL]          = "VP8E_SET_CQ_LEVEL",
+    [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -353,6 +355,8 @@ static av_cold int vp8_init(AVCodecContext *avctx)
     codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS,  av_log2(avctx->slices));
     codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD,  avctx->mb_threshold);
     codecctl_int(avctx, VP8E_SET_CQ_LEVEL,          ctx->crf);
+    if (ctx->max_intra_rate >= 0)
+        codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, ctx->max_intra_rate);
 
     av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
 
@@ -556,6 +560,7 @@ static const AVOption options[] = {
     { "good",            NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"},
     { "realtime",        NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_REALTIME},     0, 0, VE, "quality"},
     { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, VE, "er"},
+    { "max-intra-rate",  "Maximum I-frame bitrate (pct) 0=unlimited",  OFFSET(max_intra_rate),  AV_OPT_TYPE_INT,  {-1}, -1,      INT_MAX, VE},
 #ifdef VPX_ERROR_RESILIENT_DEFAULT
     { "default",         "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
     { "partitions",      "The frame partitions are independently decodable "
-- 
1.7.7.3


More information about the ffmpeg-devel mailing list