diff mbox series

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

Message ID 20200203180202.19669-2-wonkap@google.com
State Accepted
Headers show
Series [FFmpeg-devel,v5,1/2] avcodec/libvpxenc: add VP9 temporal scalability encoding option
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. 3, 2020, 6:02 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.
---
 libavcodec/libvpxenc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

James Zern Feb. 3, 2020, 8:44 p.m. UTC | #1
On Mon, Feb 3, 2020 at 10:02 AM Wonkap Jang
<wonkap-at-google.com@ffmpeg.org> 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.
> ---
>  libavcodec/libvpxenc.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 6fca05e6b1..2093aa8bca 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);

I think you'll want to check the codec being used for this one still.
Wonkap Jang Feb. 4, 2020, 1:14 a.m. UTC | #2
Hi

On Mon, Feb 3, 2020 at 12:45 PM James Zern <jzern-at-google.com@ffmpeg.org>
wrote:

> On Mon, Feb 3, 2020 at 10:02 AM Wonkap Jang
> <wonkap-at-google.com@ffmpeg.org> 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.
> > ---
> >  libavcodec/libvpxenc.c | 13 ++++++++++++-
> >  1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 6fca05e6b1..2093aa8bca 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);
>
> I think you'll want to check the codec being used for this one still.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".


You want me to check whether it is vp8 or vp9? because... the flags will
work for both, right?

If the flags work for both vp8 and vp9, the codec type doesn't have to be
checked, no?

Thanks,

Wonkap
James Zern Feb. 6, 2020, 1:23 a.m. UTC | #3
On Mon, Feb 3, 2020 at 5:45 PM Wonkap Jang
<wonkap-at-google.com@ffmpeg.org> wrote:
>
> Hi
>
> On Mon, Feb 3, 2020 at 12:45 PM James Zern <jzern-at-google.com@ffmpeg.org>
> wrote:
>
> > On Mon, Feb 3, 2020 at 10:02 AM Wonkap Jang
> > <wonkap-at-google.com@ffmpeg.org> 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.
> > > ---
> > >  libavcodec/libvpxenc.c | 13 ++++++++++++-
> > >  1 file changed, 12 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > > index 6fca05e6b1..2093aa8bca 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);
> >
> > I think you'll want to check the codec being used for this one still.
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
>
> You want me to check whether it is vp8 or vp9? because... the flags will
> work for both, right?
>

I meant specifically the field called 'vp8-flags', but looking again
that looks mostly like it was misnamed. I think there's a mention in
doc/encoders.texi about metadata, should that be updated to make
explicit reference to this field?

> If the flags work for both vp8 and vp9, the codec type doesn't have to be
> checked, no?
>
> Thanks,
>
> Wonkap
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Wonkap Jang Feb. 6, 2020, 4:35 p.m. UTC | #4
Hi James,

On Wed, Feb 5, 2020 at 5:29 PM James Zern <jzern-at-google.com@ffmpeg.org>
wrote:

> On Mon, Feb 3, 2020 at 5:45 PM Wonkap Jang
> <wonkap-at-google.com@ffmpeg.org> wrote:
> >
> > Hi
> >
> > On Mon, Feb 3, 2020 at 12:45 PM James Zern <
> jzern-at-google.com@ffmpeg.org>
> > wrote:
> >
> > > On Mon, Feb 3, 2020 at 10:02 AM Wonkap Jang
> > > <wonkap-at-google.com@ffmpeg.org> 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.
> > > > ---
> > > >  libavcodec/libvpxenc.c | 13 ++++++++++++-
> > > >  1 file changed, 12 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > > > index 6fca05e6b1..2093aa8bca 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);
> > >
> > > I think you'll want to check the codec being used for this one still.
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >
> >
> > You want me to check whether it is vp8 or vp9? because... the flags will
> > work for both, right?
> >
>
> I meant specifically the field called 'vp8-flags', but looking again
> that looks mostly like it was misnamed. I think there's a mention in
> doc/encoders.texi about metadata, should that be updated to make
> explicit reference to this field?
>
> > If the flags work for both vp8 and vp9, the codec type doesn't have to be
> > checked, no?
> >
> > Thanks,
> >
> > Wonkap
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".


So.. what is your suggestion?
just mention in the doc that the vp8-flags is used for both vp8 and vp9 and
how it is used?

Wonkap
James Zern Feb. 7, 2020, 4:40 a.m. UTC | #5
On Thu, Feb 6, 2020 at 8:58 AM Wonkap Jang
<wonkap-at-google.com@ffmpeg.org> wrote:
>
> Hi James,
>
> On Wed, Feb 5, 2020 at 5:29 PM James Zern <jzern-at-google.com@ffmpeg.org>
> wrote:
>
> > On Mon, Feb 3, 2020 at 5:45 PM Wonkap Jang
> > <wonkap-at-google.com@ffmpeg.org> wrote:
> > >
> > > Hi
> > >
> > > On Mon, Feb 3, 2020 at 12:45 PM James Zern <
> > jzern-at-google.com@ffmpeg.org>
> > > wrote:
> > >
> > > > On Mon, Feb 3, 2020 at 10:02 AM Wonkap Jang
> > > > <wonkap-at-google.com@ffmpeg.org> 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.
> > > > > ---
> > > > >  libavcodec/libvpxenc.c | 13 ++++++++++++-
> > > > >  1 file changed, 12 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > > > > index 6fca05e6b1..2093aa8bca 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);
> > > >
> > > > I think you'll want to check the codec being used for this one still.
> > > > _______________________________________________
> > > > ffmpeg-devel mailing list
> > > > ffmpeg-devel@ffmpeg.org
> > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > >
> > > > To unsubscribe, visit link above, or email
> > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > >
> > >
> > > You want me to check whether it is vp8 or vp9? because... the flags will
> > > work for both, right?
> > >
> >
> > I meant specifically the field called 'vp8-flags', but looking again
> > that looks mostly like it was misnamed. I think there's a mention in
> > doc/encoders.texi about metadata, should that be updated to make
> > explicit reference to this field?
> >
> > [...]
> So.. what is your suggestion?
> just mention in the doc that the vp8-flags is used for both vp8 and vp9 and
> how it is used?
>

Sorry if it wasn't clear, in this case I was referring to the mention
of metadata related to temporal_id:
"No temporal layering flags are provided internally,
relies on flags being passed in using metadata in AVFrame."

The addition of vp8-flags could be a follow up.
diff mbox series

Patch

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 6fca05e6b1..2093aa8bca 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) {