diff mbox

[FFmpeg-devel] avcodec/libvpxenc: add VP8/9 sharpness config option

Message ID 20181219215244.167030-1-rclaus@google.com
State Accepted
Headers show

Commit Message

Rene Claus Dec. 19, 2018, 9:52 p.m. UTC
This commit adds configuration options to libvpxenc.c that can be used to
tune the sharpness parameter for VP8 and VP9.

Signed-off-by: Rene Claus <rclaus@google.com>
---
 doc/encoders.texi      | 4 ++++
 libavcodec/libvpxenc.c | 6 ++++++
 2 files changed, 10 insertions(+)

Comments

James Almer Dec. 19, 2018, 10:03 p.m. UTC | #1
On 12/19/2018 6:52 PM, Rene Claus wrote:
> This commit adds configuration options to libvpxenc.c that can be used to
> tune the sharpness parameter for VP8 and VP9.
> 
> Signed-off-by: Rene Claus <rclaus@google.com>
> ---
>  doc/encoders.texi      | 4 ++++
>  libavcodec/libvpxenc.c | 6 ++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index ca3892d682..3dd2989526 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1767,6 +1767,10 @@ Set number of frames to look ahead for frametype and ratecontrol.
>  @item error-resilient
>  Enable error resiliency features.
>  
> +@item sharpness @var{integer}
> +Set sharpness.
> +The valid range is [0, 7]. Default: 0

I assume 0 means disabled and it would be the same as not setting this
control id at all, right?

Also, if you're going to update the documentation, you should take the
chance to mention this valid range in vp8cx.h

> +
>  @item VP8-specific options
>  @table @option
>  @item ts-parameters
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 39af586790..f9b19a8975 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -76,6 +76,7 @@ typedef struct VPxEncoderContext {
>      struct FrameListData *coded_frame_list;
>  
>      int cpu_used;
> +    int sharpness;
>      /**
>       * VP8 specific flags, see VP8F_* below.
>       */
> @@ -130,6 +131,7 @@ static const char *const ctlidstr[] = {
>      [VP8E_SET_TUNING]            = "VP8E_SET_TUNING",
>      [VP8E_SET_CQ_LEVEL]          = "VP8E_SET_CQ_LEVEL",
>      [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
> +    [VP8E_SET_SHARPNESS]               = "VP8E_SET_SHARPNESS",
>  #if CONFIG_LIBVPX_VP9_ENCODER
>      [VP9E_SET_LOSSLESS]                = "VP9E_SET_LOSSLESS",
>      [VP9E_SET_TILE_COLUMNS]            = "VP9E_SET_TILE_COLUMNS",
> @@ -751,6 +753,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          return AVERROR(EINVAL);
>      }
>  
> +    if (ctx->sharpness)
> +        codecctl_int(avctx, VP8E_SET_SHARPNESS, ctx->sharpness);
> +
>      if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8) {
>  #if FF_API_PRIVATE_OPT
>  FF_DISABLE_DEPRECATION_WARNINGS
> @@ -1193,6 +1198,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
>      {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
>      {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
>      {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VPxContext, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
> +    { "sharpness", "Sharpness", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 7, VE},
>  
>  #if CONFIG_LIBVPX_VP8_ENCODER
>  static const AVOption vp8_options[] = {
>
Rene Claus Dec. 19, 2018, 10:41 p.m. UTC | #2
Yes, setting it to zero is the same as not setting it at all.
I'll look into updating vp8cx.h

On Wed, Dec 19, 2018 at 2:03 PM James Almer <jamrial@gmail.com> wrote:

> On 12/19/2018 6:52 PM, Rene Claus wrote:
> > This commit adds configuration options to libvpxenc.c that can be used to
> > tune the sharpness parameter for VP8 and VP9.
> >
> > Signed-off-by: Rene Claus <rclaus@google.com>
> > ---
> >  doc/encoders.texi      | 4 ++++
> >  libavcodec/libvpxenc.c | 6 ++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index ca3892d682..3dd2989526 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1767,6 +1767,10 @@ Set number of frames to look ahead for frametype
> and ratecontrol.
> >  @item error-resilient
> >  Enable error resiliency features.
> >
> > +@item sharpness @var{integer}
> > +Set sharpness.
> > +The valid range is [0, 7]. Default: 0
>
> I assume 0 means disabled and it would be the same as not setting this
> control id at all, right?
>
> Also, if you're going to update the documentation, you should take the
> chance to mention this valid range in vp8cx.h
>
> > +
> >  @item VP8-specific options
> >  @table @option
> >  @item ts-parameters
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 39af586790..f9b19a8975 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -76,6 +76,7 @@ typedef struct VPxEncoderContext {
> >      struct FrameListData *coded_frame_list;
> >
> >      int cpu_used;
> > +    int sharpness;
> >      /**
> >       * VP8 specific flags, see VP8F_* below.
> >       */
> > @@ -130,6 +131,7 @@ static const char *const ctlidstr[] = {
> >      [VP8E_SET_TUNING]            = "VP8E_SET_TUNING",
> >      [VP8E_SET_CQ_LEVEL]          = "VP8E_SET_CQ_LEVEL",
> >      [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
> > +    [VP8E_SET_SHARPNESS]               = "VP8E_SET_SHARPNESS",
> >  #if CONFIG_LIBVPX_VP9_ENCODER
> >      [VP9E_SET_LOSSLESS]                = "VP9E_SET_LOSSLESS",
> >      [VP9E_SET_TILE_COLUMNS]            = "VP9E_SET_TILE_COLUMNS",
> > @@ -751,6 +753,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >          return AVERROR(EINVAL);
> >      }
> >
> > +    if (ctx->sharpness)
> > +        codecctl_int(avctx, VP8E_SET_SHARPNESS, ctx->sharpness);
> > +
> >      if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id ==
> AV_CODEC_ID_VP8) {
> >  #if FF_API_PRIVATE_OPT
> >  FF_DISABLE_DEPRECATION_WARNINGS
> > @@ -1193,6 +1198,7 @@ static int vpx_encode(AVCodecContext *avctx,
> AVPacket *pkt,
> >      {"arnr_strength", "altref noise reduction filter strength",
> offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6,
> VE}, \
> >      {"arnr_type", "altref noise reduction filter type",
> offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
> >      {"rc_lookahead", "Number of frames to look ahead for alternate
> reference frame selection", offsetof(VPxContext, lag_in_frames),
> AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
> > +    { "sharpness", "Sharpness", offsetof(VPxContext, sharpness),
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, 7, VE},
> >
> >  #if CONFIG_LIBVPX_VP8_ENCODER
> >  static const AVOption vp8_options[] = {
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
James Zern Dec. 19, 2018, 11:07 p.m. UTC | #3
On Wed, Dec 19, 2018 at 2:03 PM James Almer <jamrial@gmail.com> wrote:
>
> On 12/19/2018 6:52 PM, Rene Claus wrote:
> > This commit adds configuration options to libvpxenc.c that can be used to
> > tune the sharpness parameter for VP8 and VP9.
> >
> > Signed-off-by: Rene Claus <rclaus@google.com>
> > ---
> >  doc/encoders.texi      | 4 ++++
> >  libavcodec/libvpxenc.c | 6 ++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index ca3892d682..3dd2989526 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1767,6 +1767,10 @@ Set number of frames to look ahead for frametype and ratecontrol.
> >  @item error-resilient
> >  Enable error resiliency features.
> >
> > +@item sharpness @var{integer}
> > +Set sharpness.
> > +The valid range is [0, 7]. Default: 0
>
> I assume 0 means disabled and it would be the same as not setting this
> control id at all, right?
>
> Also, if you're going to update the documentation, you should take the
> chance to mention this valid range in vp8cx.h
>

https://chromium-review.googlesource.com/c/webm/libvpx/+/1384812
diff mbox

Patch

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ca3892d682..3dd2989526 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1767,6 +1767,10 @@  Set number of frames to look ahead for frametype and ratecontrol.
 @item error-resilient
 Enable error resiliency features.
 
+@item sharpness @var{integer}
+Set sharpness.
+The valid range is [0, 7]. Default: 0
+
 @item VP8-specific options
 @table @option
 @item ts-parameters
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 39af586790..f9b19a8975 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -76,6 +76,7 @@  typedef struct VPxEncoderContext {
     struct FrameListData *coded_frame_list;
 
     int cpu_used;
+    int sharpness;
     /**
      * VP8 specific flags, see VP8F_* below.
      */
@@ -130,6 +131,7 @@  static const char *const ctlidstr[] = {
     [VP8E_SET_TUNING]            = "VP8E_SET_TUNING",
     [VP8E_SET_CQ_LEVEL]          = "VP8E_SET_CQ_LEVEL",
     [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
+    [VP8E_SET_SHARPNESS]               = "VP8E_SET_SHARPNESS",
 #if CONFIG_LIBVPX_VP9_ENCODER
     [VP9E_SET_LOSSLESS]                = "VP9E_SET_LOSSLESS",
     [VP9E_SET_TILE_COLUMNS]            = "VP9E_SET_TILE_COLUMNS",
@@ -751,6 +753,9 @@  FF_ENABLE_DEPRECATION_WARNINGS
         return AVERROR(EINVAL);
     }
 
+    if (ctx->sharpness)
+        codecctl_int(avctx, VP8E_SET_SHARPNESS, ctx->sharpness);
+
     if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8) {
 #if FF_API_PRIVATE_OPT
 FF_DISABLE_DEPRECATION_WARNINGS
@@ -1193,6 +1198,7 @@  static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
     {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
     {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
     {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VPxContext, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
+    { "sharpness", "Sharpness", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 7, VE},
 
 #if CONFIG_LIBVPX_VP8_ENCODER
 static const AVOption vp8_options[] = {