[FFmpeg-devel] [PATCH] libvpx: rc buffer support

James Zern jzern
Mon Jun 14 22:06:51 CEST 2010


The attached maps libvpx rc_buf* and rc_undershoot_pct.
rc_overshoot_pct is unused by VP8 so it is left untouched.
There didn't seem to be a direct mapping for rc_optimal_buf_sz so
instead of introducing a new parameter this sets it in line with the
recommended settings and library defaults (5/6 of the buffer_size).
The use of rc_buffer_aggressivity for rc_undershoot_pct may be
questionable, so if there's something more correct that I missed
please let me know. It does also alter the library default from 95 to
100, but again this is more along the line of the recommended values
for VBR.

Parameter descriptions:
 * This value, expressed as a percentage of the target bitrate, describes
 * the target bitrate for easier frames, allowing bits to be saved for
 * harder frames. Set to zero to use the codec default.
rc_undershoot_pct;

 * This value indicates the amount of data that may be buffered by the
 * decoding application. Note that this value is expressed in units of
 * time (milliseconds). For example, a value of 5000 indicates that the
 * client will buffer (at least) 5000ms worth of encoded data. Use the
 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
 * necessary.
rc_buf_sz;

 * This value indicates the amount of data that will be buffered by the
 * decoding application prior to beginning playback. This value is
 * expressed in units of time (milliseconds). Use the target bitrate
 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
rc_buf_initial_sz;

 * This value indicates the amount of data that the encoder should try
 * to maintain in the decoder's buffer. This value is expressed in units
 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
 * to convert to bits/bytes, if necessary.
rc_buf_optimal_sz;
-------------- next part --------------
Index: libavcodec/libvpxenc.c
===================================================================
--- libavcodec/libvpxenc.c	(revision 23607)
+++ libavcodec/libvpxenc.c	(working copy)
@@ -242,6 +242,15 @@ static av_cold int vp8_init(AVCodecConte
     enccfg.rc_max_quantizer = ((avctx->qmax * 5 + 1) >> 2) - 1;
     enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold;
 
+    if (avctx->rc_buffer_size)
+        enccfg.rc_buf_sz         =
+            avctx->rc_buffer_size * 1000 / avctx->bit_rate;
+    if (avctx->rc_initial_buffer_occupancy)
+        enccfg.rc_buf_initial_sz =
+            avctx->rc_initial_buffer_occupancy * 1000 / avctx->bit_rate;
+    enccfg.rc_buf_optimal_sz     = enccfg.rc_buf_sz * 5 / 6;
+    enccfg.rc_undershoot_pct     = round(avctx->rc_buffer_aggressivity * 100);
+
     //_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO
     if (avctx->keyint_min == avctx->gop_size)
         enccfg.kf_min_dist = avctx->keyint_min;



More information about the ffmpeg-devel mailing list