Skip to content

Commit f3bb592

Browse files
Wonkap Jangjzern
authored andcommitted
avcodec/libvpxenc: add a way to explicitly set temporal layer id
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 <[email protected]>
1 parent cf92f42 commit f3bb592

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

doc/encoders.texi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,17 @@ Currently supports the following options.
19181918
@table @option
19191919
@item 0
19201920
No temporal layering flags are provided internally,
1921-
relies on flags being passed in using metadata in AVFrame.
1921+
relies on flags being passed in using @code{metadata} field in @code{AVFrame}
1922+
with following keys.
1923+
@table @option
1924+
@item vp8-flags
1925+
Sets the flags passed into the encoder to indicate the referencing scheme for
1926+
the current frame.
1927+
Refer to function @code{vpx_codec_encode} in @code{vpx/vpx_encoder.h} for more
1928+
details.
1929+
@item temporal_id
1930+
Explicitly sets the temporal id of the current frame to encode.
1931+
@end table
19221932
@item 2
19231933
Two temporal layers. 0-1...
19241934
@item 3

libavcodec/libvpxenc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,11 +1519,22 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
15191519
#endif
15201520
if (frame->pict_type == AV_PICTURE_TYPE_I)
15211521
flags |= VPX_EFLAG_FORCE_KF;
1522-
if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8 && frame->metadata) {
1522+
if (frame->metadata) {
15231523
AVDictionaryEntry* en = av_dict_get(frame->metadata, "vp8-flags", NULL, 0);
15241524
if (en) {
15251525
flags |= strtoul(en->value, NULL, 10);
15261526
}
1527+
1528+
memset(&layer_id, 0, sizeof(layer_id));
1529+
1530+
en = av_dict_get(frame->metadata, "temporal_id", NULL, 0);
1531+
if (en) {
1532+
layer_id.temporal_layer_id = strtoul(en->value, NULL, 10);
1533+
#ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1534+
layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1535+
#endif
1536+
layer_id_valid = 1;
1537+
}
15271538
}
15281539

15291540
if (sd) {

libavcodec/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#define LIBAVCODEC_VERSION_MAJOR 58
3131
#define LIBAVCODEC_VERSION_MINOR 68
32-
#define LIBAVCODEC_VERSION_MICRO 101
32+
#define LIBAVCODEC_VERSION_MICRO 102
3333

3434
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3535
LIBAVCODEC_VERSION_MINOR, \

0 commit comments

Comments
 (0)