]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/libvpxenc: add a way to explicitly set temporal layer id
authorWonkap Jang <wonkap-at-google.com@ffmpeg.org>
Mon, 10 Feb 2020 18:30:09 +0000 (10:30 -0800)
committerJames Zern <jzern@google.com>
Tue, 11 Feb 2020 19:55:36 +0000 (11:55 -0800)
In order for rate control to correctly allocate bitrate to each temporal
layer, correct temporal layer id has to be set to each frame. This
commit provides the ability to set correct temporal layer id for each
frame.

Signed-off-by: James Zern <jzern@google.com>
doc/encoders.texi
libavcodec/libvpxenc.c
libavcodec/version.h

index 7bae39435e227b77395888371e32e1149126b2e0..e23b6b32fe38807687fccc80be55a8646ed12fa1 100644 (file)
@@ -1918,7 +1918,17 @@ Currently supports the following options.
 @table @option
 @item 0
 No temporal layering flags are provided internally,
-relies on flags being passed in using metadata in AVFrame.
+relies on flags being passed in using @code{metadata} field in @code{AVFrame}
+with following keys.
+@table @option
+@item vp8-flags
+Sets the flags passed into the encoder to indicate the referencing scheme for
+the current frame.
+Refer to function @code{vpx_codec_encode} in @code{vpx/vpx_encoder.h} for more
+details.
+@item temporal_id
+Explicitly sets the temporal id of the current frame to encode.
+@end table
 @item 2
 Two temporal layers. 0-1...
 @item 3
index d522c43928316a22582ae969aac1b55f17835361..60a858853dbb1ea8cea16e44ef0c0cbc8dc44ffc 100644 (file)
@@ -1519,11 +1519,22 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
 #endif
         if (frame->pict_type == AV_PICTURE_TYPE_I)
             flags |= VPX_EFLAG_FORCE_KF;
-        if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8 && frame->metadata) {
+        if (frame->metadata) {
             AVDictionaryEntry* en = av_dict_get(frame->metadata, "vp8-flags", NULL, 0);
             if (en) {
                 flags |= strtoul(en->value, NULL, 10);
             }
+
+            memset(&layer_id, 0, sizeof(layer_id));
+
+            en = av_dict_get(frame->metadata, "temporal_id", NULL, 0);
+            if (en) {
+                layer_id.temporal_layer_id = strtoul(en->value, NULL, 10);
+#ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
+                layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
+#endif
+                layer_id_valid = 1;
+            }
         }
 
         if (sd) {
index bc6630ea42b7483266204f48144eb28cdc77e4ed..6bf2a0514520412c39e51bb65a33e0a3d91b2bc0 100644 (file)
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  68
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \