[FFmpeg-devel] [PATCH] libvpx: alt reference frame / lag
James Zern
jzern
Fri Jul 2 22:03:13 CEST 2010
On Fri, Jul 2, 2010 at 15:26, John Koleszar <jkoleszar at google.com> wrote:
>
> For the question about what to do with the pts, the closest thing to
> the current implementation would be to create a pts between frames if
> the user's time base supports it, and disable the feature otherwise.
> So if the user passes in a timebase on the command line, the time is
> calculated in that base either based on a frame rate from the command
> line or the time in the originating container, and ARFs are enabled
> (presuming the user's time base is precise enough). Otherwise (and by
> default, since the default timebase is 1/fr) ARFs are disabled.
>
Minus the new flag/warning suggestion, taking the timebase from the
command line and enabling ARF might look like this.
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 23960)
+++ ffmpeg.c (working copy)
@@ -3404,6 +3404,10 @@ static void new_video_stream(AVFormatCon
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
+ else if (av_cmp_q(avcodec_opts[AVMEDIA_TYPE_VIDEO]->time_base, (AVRational){0, 1})) {
+ fps.num = avcodec_opts[AVMEDIA_TYPE_VIDEO]->time_base.den;
+ fps.den = avcodec_opts[AVMEDIA_TYPE_VIDEO]->time_base.num;
+ }
video_enc->time_base.den = fps.num;
video_enc->time_base.num = fps.den;
Index: libavcodec/options.c
===================================================================
--- libavcodec/options.c (revision 23960)
+++ 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 23960)
+++ libavcodec/avcodec.h (working copy)
@@ -30,8 +30,8 @@
#include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 78
-#define LIBAVCODEC_VERSION_MICRO 1
+#define LIBAVCODEC_VERSION_MINOR 79
+#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 23960)
+++ libavcodec/libvpxenc.c (working copy)
@@ -223,6 +223,7 @@ static av_cold int vp8_init(AVCodecConte
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 +291,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