History

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.

Wonkap Jang committed 6 years ago

Commit f3bb5921 parent cf92f423 files · +24 −3Browse files

Unified · Split

3 files
  1. doc/encoders.texi +11 −1
  2. libavcodec/libvpxenc.c +12 −1
  3. libavcodec/version.h +1 −1
doc/encoders.texi+11−1
@@ -1918,7 +1918,17 @@ Currently supports the following options. · 1917 unmodified lines
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+12−1
@@ -1519,11 +1519,22 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, · 1518 unmodified lines
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+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
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, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t