diff mbox series

[FFmpeg-devel,v6] avcodec/libvpxenc: add a way to explicitly set temporal layer id

Message ID 20200207183651.177513-1-wonkap@google.com
State Superseded
Headers show
Series [FFmpeg-devel,v6] avcodec/libvpxenc: add a way to explicitly set temporal layer id
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Wonkap Jang Feb. 7, 2020, 6:36 p.m. UTC
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.
---
 doc/encoders.texi      |  8 +++++++-
 libavcodec/libvpxenc.c | 13 ++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

Comments

Wonkap Jang Feb. 7, 2020, 6:38 p.m. UTC | #1
Hi James,

On Fri, Feb 7, 2020 at 10:36 AM Wonkap Jang <wonkap@google.com> wrote:

> 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.
> ---
>  doc/encoders.texi      |  8 +++++++-
>  libavcodec/libvpxenc.c | 13 ++++++++++++-
>  2 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 7bae39435e..b1c4740fe9 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1918,7 +1918,13 @@ 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 metadata in 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.
> +@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
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index d522c43928..60a858853d 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -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) {
> --
> 2.25.0.341.g760bfbb309-goog
>
>
Please take a look. Suggestions are welcome on the text.

Thank you,

Wonkap
James Zern Feb. 8, 2020, 1:20 a.m. UTC | #2
On Fri, Feb 7, 2020 at 10:44 AM Wonkap Jang
<wonkap-at-google.com@ffmpeg.org> wrote:
>
> Hi James,
>
> On Fri, Feb 7, 2020 at 10:36 AM Wonkap Jang <wonkap@google.com> wrote:
>
> > 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.
> > ---
> >  doc/encoders.texi      |  8 +++++++-
> >  libavcodec/libvpxenc.c | 13 ++++++++++++-
> >  2 files changed, 19 insertions(+), 2 deletions(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 7bae39435e..b1c4740fe9 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1918,7 +1918,13 @@ 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 metadata in AVFrame with following
> > keys.

you can use @code{AVFrame}.

> > +@table @option
> > +@item vp8-flags
> > +Sets the flags passed into the encoder to indicate the referencing scheme
> > for the current frame.

it would be good to add a reference to the related vpx header like is
done earlier in this section with:
refer to @code{struct vpx_codec_enc_cfg} in @code{vpx/vpx_encoder.h} for more
diff mbox series

Patch

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7bae39435e..b1c4740fe9 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1918,7 +1918,13 @@  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 metadata in 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.
+@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
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index d522c43928..60a858853d 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -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) {