[FFmpeg-devel] [PATCH] libvpx: alt reference frame / lag
James Zern
jzern
Wed Jun 9 00:44:42 CEST 2010
The attached adds altref to flags2 and uses rc_lookahead for
g_lag_in_frames mapping.
Alternate reference frames are currently only produced in 2-pass.
Further description outside of the API docs [1]. I'm ignoring the alt.
ref. noise reduction settings for this pass.
[1]: http://www.webmproject.org/tools/encoder-parameters/#5_the_alternate_or_constructed_reference_frame
-------------- next part --------------
Index: libavcodec/options.c
===================================================================
--- libavcodec/options.c (revision 23540)
+++ libavcodec/options.c (working copy)
@@ -414,6 +414,7 @@ static const AVOption options[]={
{"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_REFRESH, INT_MIN, INT_MAX, V|E, "flags2"},
{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX },
+{"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_ALT_REF, INT_MIN, INT_MAX, V|E, "flags2"},
{NULL},
};
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h (revision 23540)
+++ libavcodec/avcodec.h (working copy)
@@ -30,8 +30,8 @@
#include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 75
-#define LIBAVCODEC_VERSION_MICRO 1
+#define LIBAVCODEC_VERSION_MINOR 76
+#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
@@ -600,6 +600,7 @@ typedef struct RcOverride{
#define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations.
#define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined.
#define CODEC_FLAG2_INTRA_REFRESH 0x00200000 ///< Use periodic insertion of intra blocks instead of keyframes.
+#define CODEC_FLAG2_ALT_REF 0x00400000 ///< Allow encoder to insert alternate reference frames (VP8 only)
/* Unsupported options :
* Syntax Arithmetic coding (SAC)
Index: libavcodec/libvpxenc.c
===================================================================
--- libavcodec/libvpxenc.c (revision 23540)
+++ libavcodec/libvpxenc.c (working copy)
@@ -218,11 +218,21 @@ static av_cold int vp8_init(AVCodecConte
}
dump_enc_cfg(avctx, &enccfg);
+ /* With altref set an additional frame at the same pts may be produced.
+ Increasing the time_base gives the library a window to place these frames
+ ensuring strictly increasing timestamps. */
+ if (avctx->flags2 & CODEC_FLAG2_ALT_REF) {
+ avctx->ticks_per_frame = 2;
+ avctx->time_base = av_mul_q(avctx->time_base,
+ (AVRational){1, avctx->ticks_per_frame});
+ }
+
enccfg.g_w = avctx->width;
enccfg.g_h = avctx->height;
enccfg.g_timebase.num = avctx->time_base.num;
enccfg.g_timebase.den = avctx->time_base.den;
enccfg.g_threads = avctx->thread_count;
+ enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25); //0-25, avoids init failure
if (avctx->flags & CODEC_FLAG_PASS1)
enccfg.g_pass = VPX_RC_FIRST_PASS;
@@ -290,6 +300,7 @@ static av_cold int vp8_init(AVCodecConte
av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused);
codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction);
+ codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, !!(avctx->flags2 & CODEC_FLAG2_ALT_REF));
//provide dummy value to initialize wrapper, values will be updated each _encode()
vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
More information about the ffmpeg-devel
mailing list