* [FFmpeg-devel] [PATCH] libavcodec: add tune_content option also for VP8.
@ 2024-01-25 17:12 Dariusz Marcinkiewicz via ffmpeg-devel
2024-01-29 10:31 ` Dariusz Marcinkiewicz via ffmpeg-devel
0 siblings, 1 reply; 2+ messages in thread
From: Dariusz Marcinkiewicz via ffmpeg-devel @ 2024-01-25 17:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dariusz Marcinkiewicz, sprang
This exposes VP8E_SET_SCREEN_CONTENT_MODE option from libvpx.
Change authored by Erik Språng <sprang@webrtc.org>
Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
---
doc/encoders.texi | 7 +++++--
libavcodec/libvpxenc.c | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index c9fe6d6143..2a9b38f62a 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2186,6 +2186,11 @@ Enable error resiliency features.
Increase sharpness at the expense of lower PSNR.
The valid range is [0, 7].
+@item tune-content
+Set content type.
+For VP8: default (0), screen (1), screen with aggressive rate control (2).
+For VP9: default (0), screen (1), film (2).
+
@item ts-parameters
Sets the temporal scalability configuration using a :-separated list of
key=value pairs. For example, to specify temporal scalability parameters
@@ -2268,8 +2273,6 @@ colorspaces:
@end table
@item row-mt @var{boolean}
Enable row based multi-threading.
-@item tune-content
-Set content type: default (0), screen (1), film (2).
@item corpus-complexity
Corpus VBR mode is a variant of standard VBR where the complexity distribution
midpoint is passed in rather than calculated for a specific clip or chunk.
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 80988a2608..c28cca40a2 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -164,6 +164,7 @@ static const char *const ctlidstr[] = {
[VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
[VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS",
[VP8E_SET_TEMPORAL_LAYER_ID] = "VP8E_SET_TEMPORAL_LAYER_ID",
+ [VP8E_SET_SCREEN_CONTENT_MODE] = "VP8E_SET_SCREEN_CONTENT_MODE",
#if CONFIG_LIBVPX_VP9_ENCODER
[VP9E_SET_LOSSLESS] = "VP9E_SET_LOSSLESS",
[VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS",
@@ -1249,8 +1250,19 @@ static av_cold int vpx_init(AVCodecContext *avctx,
codecctl_int(avctx, VP9E_SET_ROW_MT, ctx->row_mt);
#endif
#ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
- if (ctx->tune_content >= 0)
+ if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP9) {
codecctl_int(avctx, VP9E_SET_TUNE_CONTENT, ctx->tune_content);
+ }
+#endif
+#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE
+ if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP8) {
+ if (ctx->tune_content == 2 && ctx->is_alpha) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Transparency encoding with screen mode with aggressive rate control not supported\n");
+ return AVERROR(EINVAL);
+ }
+ codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE, ctx->tune_content);
+ }
#endif
#ifdef VPX_CTRL_VP9E_SET_TPL
if (ctx->tpl_model >= 0)
@@ -1857,6 +1869,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
coded_size = queue_frames(avctx, &ctx->encoder, &ctx->coded_frame_list, pkt);
+ if (avctx->codec_id == AV_CODEC_ID_VP8 && coded_size == 0 && ctx->tune_content == 2) {
+ // VP8 tuned for screen content with aggresive rate control - returned
+ // OK status code but produced no output, this indicates frame was
+ // rolled back due to bitrate overshoot - try to encode it again.
+ av_log(avctx, AV_LOG_VERBOSE,
+ "Attempting to reencode dropped VP8 screencast frame.");
+ res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
+ avctx->ticks_per_frame, flags, ctx->deadline);
+ if (res != VPX_CODEC_OK) {
+ log_encoder_error(avctx, "Error encoding frame");
+ return AVERROR_INVALIDDATA;
+ }
+ coded_size = queue_frames(avctx, &ctx->encoder, &ctx->coded_frame_list, pkt);
+ }
+
if (ctx->is_alpha) {
queue_frames(avctx, &ctx->encoder_alpha, &ctx->alpha_coded_frame_list, NULL);
@@ -1946,6 +1973,12 @@ static const AVOption vp8_options[] = {
{ "auto-alt-ref", "Enable use of alternate reference "
"frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
{ "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE},
+ { "tune-content", "Tune content type", OFFSET(tune_content), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE, "tune_content"},
+#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE
+ { "default", "Regular video content", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune_content"},
+ { "screen", "Screen content mode on", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune_content"},
+ { "screen-rate-control", "Screen content mode with aggressive rate control", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "tune_content"},
+#endif
LEGACY_OPTIONS
{ NULL }
};
--
2.43.0.429.g432eaa2c6b-goog
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavcodec: add tune_content option also for VP8.
2024-01-25 17:12 [FFmpeg-devel] [PATCH] libavcodec: add tune_content option also for VP8 Dariusz Marcinkiewicz via ffmpeg-devel
@ 2024-01-29 10:31 ` Dariusz Marcinkiewicz via ffmpeg-devel
0 siblings, 0 replies; 2+ messages in thread
From: Dariusz Marcinkiewicz via ffmpeg-devel @ 2024-01-29 10:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dariusz Marcinkiewicz, sprang
Please ignore this version of the patch. I'll send out v2 soon. Apologies
for the noise.
On Thu, Jan 25, 2024 at 6:13 PM Dariusz Marcinkiewicz <darekm@google.com>
wrote:
> This exposes VP8E_SET_SCREEN_CONTENT_MODE option from libvpx.
>
> Change authored by Erik Språng <sprang@webrtc.org>
>
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> ---
> doc/encoders.texi | 7 +++++--
> libavcodec/libvpxenc.c | 35 ++++++++++++++++++++++++++++++++++-
> 2 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c9fe6d6143..2a9b38f62a 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2186,6 +2186,11 @@ Enable error resiliency features.
> Increase sharpness at the expense of lower PSNR.
> The valid range is [0, 7].
>
> +@item tune-content
> +Set content type.
> +For VP8: default (0), screen (1), screen with aggressive rate control (2).
> +For VP9: default (0), screen (1), film (2).
> +
> @item ts-parameters
> Sets the temporal scalability configuration using a :-separated list of
> key=value pairs. For example, to specify temporal scalability parameters
> @@ -2268,8 +2273,6 @@ colorspaces:
> @end table
> @item row-mt @var{boolean}
> Enable row based multi-threading.
> -@item tune-content
> -Set content type: default (0), screen (1), film (2).
> @item corpus-complexity
> Corpus VBR mode is a variant of standard VBR where the complexity
> distribution
> midpoint is passed in rather than calculated for a specific clip or chunk.
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 80988a2608..c28cca40a2 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -164,6 +164,7 @@ static const char *const ctlidstr[] = {
> [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
> [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS",
> [VP8E_SET_TEMPORAL_LAYER_ID] = "VP8E_SET_TEMPORAL_LAYER_ID",
> + [VP8E_SET_SCREEN_CONTENT_MODE] = "VP8E_SET_SCREEN_CONTENT_MODE",
> #if CONFIG_LIBVPX_VP9_ENCODER
> [VP9E_SET_LOSSLESS] = "VP9E_SET_LOSSLESS",
> [VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS",
> @@ -1249,8 +1250,19 @@ static av_cold int vpx_init(AVCodecContext *avctx,
> codecctl_int(avctx, VP9E_SET_ROW_MT, ctx->row_mt);
> #endif
> #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
> - if (ctx->tune_content >= 0)
> + if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP9)
> {
> codecctl_int(avctx, VP9E_SET_TUNE_CONTENT, ctx->tune_content);
> + }
> +#endif
> +#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE
> + if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP8)
> {
> + if (ctx->tune_content == 2 && ctx->is_alpha) {
> + av_log(avctx, AV_LOG_ERROR,
> + "Transparency encoding with screen mode with
> aggressive rate control not supported\n");
> + return AVERROR(EINVAL);
> + }
> + codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE,
> ctx->tune_content);
> + }
> #endif
> #ifdef VPX_CTRL_VP9E_SET_TPL
> if (ctx->tpl_model >= 0)
> @@ -1857,6 +1869,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
> }
>
> coded_size = queue_frames(avctx, &ctx->encoder,
> &ctx->coded_frame_list, pkt);
> + if (avctx->codec_id == AV_CODEC_ID_VP8 && coded_size == 0 &&
> ctx->tune_content == 2) {
> + // VP8 tuned for screen content with aggresive rate control -
> returned
> + // OK status code but produced no output, this indicates frame was
> + // rolled back due to bitrate overshoot - try to encode it again.
> + av_log(avctx, AV_LOG_VERBOSE,
> + "Attempting to reencode dropped VP8 screencast frame.");
> + res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
> + avctx->ticks_per_frame, flags,
> ctx->deadline);
> + if (res != VPX_CODEC_OK) {
> + log_encoder_error(avctx, "Error encoding frame");
> + return AVERROR_INVALIDDATA;
> + }
> + coded_size = queue_frames(avctx, &ctx->encoder,
> &ctx->coded_frame_list, pkt);
> + }
> +
> if (ctx->is_alpha) {
> queue_frames(avctx, &ctx->encoder_alpha,
> &ctx->alpha_coded_frame_list, NULL);
>
> @@ -1946,6 +1973,12 @@ static const AVOption vp8_options[] = {
> { "auto-alt-ref", "Enable use of alternate reference "
> "frames (2-pass only)",
> OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
> { "cpu-used", "Quality/Speed ratio modifier",
> OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE},
> + { "tune-content", "Tune content type",
> OFFSET(tune_content), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE,
> "tune_content"},
> +#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE
> + { "default", "Regular video content",
> 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE,
> "tune_content"},
> + { "screen", "Screen content mode on",
> 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE,
> "tune_content"},
> + { "screen-rate-control", "Screen content mode with aggressive rate
> control", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE,
> "tune_content"},
> +#endif
> LEGACY_OPTIONS
> { NULL }
> };
> --
> 2.43.0.429.g432eaa2c6b-goog
>
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-29 10:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-25 17:12 [FFmpeg-devel] [PATCH] libavcodec: add tune_content option also for VP8 Dariusz Marcinkiewicz via ffmpeg-devel
2024-01-29 10:31 ` Dariusz Marcinkiewicz via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git