[FFmpeg-cvslog] vaapi_encode: Support more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:54 
2019 +| [f4d7bd6cdbcf9027a36a73531baf7e3885644ee6] | committer: Mark 
Thompson

vaapi_encode: Support more RC modes

Allow setting the mode explicitly, and try to make a sensible choice
given the available parameters if not.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f4d7bd6cdbcf9027a36a73531baf7e3885644ee6
---

 doc/encoders.texi |  24 +++
 libavcodec/vaapi_encode.c | 382 --
 libavcodec/vaapi_encode.h |  65 
 3 files changed, 358 insertions(+), 113 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e86ae69cc5..29625ba07c 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2824,6 +2824,30 @@ Set the B-frame reference depth.  When set to one (the 
default), all B-frames
 will refer only to P- or I-frames.  When set to greater values multiple layers
 of B-frames will be present, frames in each layer only referring to frames in
 higher layers.
+
+@item rc_mode
+Set the rate control mode to use.  A given driver may only support a subset of
+modes.
+
+Possible modes:
+@table @option
+@item auto
+Choose the mode automatically based on driver support and the other options.
+This is the default.
+@item CQP
+Constant-quality.
+@item CBR
+Constant-bitrate.
+@item VBR
+Variable-bitrate.
+@item ICQ
+Intelligent constant-quality.
+@item QVBR
+Quality-defined variable-bitrate.
+@item AVBR
+Average variable bitrate.
+@end table
+
 @end table
 
 Each encoder also has its own specific options:
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index b4e9fadaee..2dda451882 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1283,17 +1283,42 @@ fail:
 return err;
 }
 
+static const VAAPIEncodeRCMode vaapi_encode_rc_modes[] = {
+//  Bitrate   Quality
+// | Maxrate | HRD/VBV
+{ 0 }, //  ||||
+{ RC_MODE_CQP,  "CQP",  1, VA_RC_CQP,  0,   0,   1,   0 },
+{ RC_MODE_CBR,  "CBR",  1, VA_RC_CBR,  1,   0,   0,   1 },
+{ RC_MODE_VBR,  "VBR",  1, VA_RC_VBR,  1,   1,   0,   1 },
+#if VA_CHECK_VERSION(1, 1, 0)
+{ RC_MODE_ICQ,  "ICQ",  1, VA_RC_ICQ,  0,   0,   1,   0 },
+#else
+{ RC_MODE_ICQ,  "ICQ",  0 },
+#endif
+#if VA_CHECK_VERSION(1, 3, 0)
+{ RC_MODE_QVBR, "QVBR", 1, VA_RC_QVBR, 1,   1,   1,   1 },
+{ RC_MODE_AVBR, "AVBR", 0, VA_RC_AVBR, 1,   0,   0,   0 },
+#else
+{ RC_MODE_QVBR, "QVBR", 0 },
+{ RC_MODE_AVBR, "AVBR", 0 },
+#endif
+};
+
 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
+uint32_t supported_va_rc_modes;
+const VAAPIEncodeRCMode *rc_mode;
 int64_t rc_bits_per_second;
 int rc_target_percentage;
 int rc_window_size;
+int rc_quality;
 int64_t hrd_buffer_size;
 int64_t hrd_initial_buffer_fullness;
 int fr_num, fr_den;
 VAConfigAttrib rc_attr = { VAConfigAttribRateControl };
 VAStatus vas;
+char supported_rc_modes_string[64];
 
 vas = vaGetConfigAttributes(ctx->hwctx->display,
 ctx->va_profile, ctx->va_entrypoint,
@@ -1303,119 +1328,213 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
"config attribute: %d (%s).\n", vas, vaErrorStr(vas));
 return AVERROR_EXTERNAL;
 }
-
 if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
 av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any "
-   "supported rate control modes: assuming constant-quality.\n");
-ctx->va_rc_mode = VA_RC_CQP;
-return 0;
-}
-if (ctx->codec->flags & FLAG_CONSTANT_QUALITY_ONLY ||
-avctx->flags & AV_CODEC_FLAG_QSCALE ||
-avctx->bit_rate <= 0) {
-if (rc_attr.value & VA_RC_CQP) {
-av_log(avctx, AV_LOG_VERBOSE, "Using constant-quality mode.\n");
-ctx->va_rc_mode = VA_RC_CQP;
-if (avctx->bit_rate > 0 || avctx->rc_max_rate > 0) {
-av_log(avctx, AV_LOG_WARNING, "Bitrate target parameters "
-   "ignored in constant-quality mode.\n");
+   "supported rate control modes: assuming CQP only.\n");
+supported_va_rc_modes = VA_RC_CQP;
+strcpy(supported_rc_modes_string, "unknown");
+} else {
+char *str = supported_rc_modes_string;
+size_t len = sizeof(supported_rc_modes_string);
+int i, first = 1, res;
+
+supported_va_rc_modes = rc_attr.value;
+for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
+rc_mode = _encode_rc_modes[i];
+if (supported_va_rc_modes & rc_mode->va_mode) {
+res = snprintf(str, len, "%s%s",
+   first ? "" : ", ", rc_mode->name);
+first = 0;
+if (res < 0) {

[FFmpeg-cvslog] vaapi_encode_mpeg2: Enable support for more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:57 
2019 +| [1e0fac76639e31eea48aa315cbca89aeb4761fde] | committer: Mark 
Thompson

vaapi_encode_mpeg2: Enable support for more RC modes

Fixes #7650.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e0fac76639e31eea48aa315cbca89aeb4761fde
---

 libavcodec/vaapi_encode_mpeg2.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index ccea251f87..ef8af664c2 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -521,19 +521,17 @@ static av_cold int 
vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
 return err;
 
 if (ctx->va_rc_mode == VA_RC_CQP) {
-priv->quant_p = av_clip(avctx->global_quality, 1, 31);
+priv->quant_p = av_clip(ctx->rc_quality, 1, 31);
 if (avctx->i_quant_factor > 0.0)
-priv->quant_i = av_clip((avctx->global_quality *
- avctx->i_quant_factor +
- avctx->i_quant_offset) + 0.5,
-1, 31);
+priv->quant_i =
+av_clip((avctx->i_quant_factor * priv->quant_p +
+ avctx->i_quant_offset) + 0.5, 1, 31);
 else
 priv->quant_i = priv->quant_p;
 if (avctx->b_quant_factor > 0.0)
-priv->quant_b = av_clip((avctx->global_quality *
- avctx->b_quant_factor +
- avctx->b_quant_offset) + 0.5,
-1, 31);
+priv->quant_b =
+av_clip((avctx->b_quant_factor * priv->quant_p +
+ avctx->b_quant_offset) + 0.5, 1, 31);
 else
 priv->quant_b = priv->quant_p;
 
@@ -542,7 +540,9 @@ static av_cold int 
vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
priv->quant_i, priv->quant_p, priv->quant_b);
 
 } else {
-av_assert0(0 && "Invalid RC mode.");
+priv->quant_i = 16;
+priv->quant_p = 16;
+priv->quant_b = 16;
 }
 
 ctx->slice_block_rows = FFALIGN(avctx->height, 16) / 16;
@@ -567,6 +567,8 @@ static const VAAPIEncodeType vaapi_encode_type_mpeg2 = {
 
 .configure = _encode_mpeg2_configure,
 
+.default_quality   = 10,
+
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferMPEG2),
 .init_sequence_params  = _encode_mpeg2_init_sequence_params,
 
@@ -638,6 +640,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext 
*avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_mpeg2_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
+VAAPI_ENCODE_RC_OPTIONS,
 
 { "profile", "Set profile (in profile_and_level_indication)",
   OFFSET(profile), AV_OPT_TYPE_INT,
@@ -672,7 +675,6 @@ static const AVCodecDefault vaapi_encode_mpeg2_defaults[] = 
{
 { "i_qoffset",  "0"   },
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
-{ "global_quality", "10"  },
 { "qmin",   "-1"  },
 { "qmax",   "-1"  },
 { NULL },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_h265: Enable support for more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:56 
2019 +| [d237b6b549f88657487f1439418732b549ea5f6a] | committer: Mark 
Thompson

vaapi_encode_h265: Enable support for more RC modes

Also fixes QP going out of range when modified by the quant factor/offset
values, and clarifies the QP behaviour for >8-bit modes.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d237b6b549f88657487f1439418732b549ea5f6a
---

 libavcodec/vaapi_encode_h265.c | 32 
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index d37100c52d..758bd40a37 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1073,15 +1073,21 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
 return err;
 
 if (ctx->va_rc_mode == VA_RC_CQP) {
-priv->fixed_qp_p = priv->qp;
+// Note that VAAPI only supports positive QP values - the range is
+// therefore always bounded below by 1, even in 10-bit mode where
+// it should go down to -12.
+
+priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
 if (avctx->i_quant_factor > 0.0)
-priv->fixed_qp_idr = (int)((priv->fixed_qp_p * 
avctx->i_quant_factor +
-avctx->i_quant_offset) + 0.5);
+priv->fixed_qp_idr =
+av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
+ avctx->i_quant_offset) + 0.5, 1, 51);
 else
 priv->fixed_qp_idr = priv->fixed_qp_p;
 if (avctx->b_quant_factor > 0.0)
-priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor 
+
-  avctx->b_quant_offset) + 0.5);
+priv->fixed_qp_b =
+av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
+ avctx->b_quant_offset) + 0.5, 1, 51);
 else
 priv->fixed_qp_b = priv->fixed_qp_p;
 
@@ -1089,15 +1095,11 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
"%d / %d / %d for IDR- / P- / B-frames.\n",
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
 
-} else if (ctx->va_rc_mode == VA_RC_CBR ||
-   ctx->va_rc_mode == VA_RC_VBR) {
-// These still need to be  set for pic_init_qp/slice_qp_delta.
+} else {
+// These still need to be set for init_qp/slice_qp_delta.
 priv->fixed_qp_idr = 30;
 priv->fixed_qp_p   = 30;
 priv->fixed_qp_b   = 30;
-
-} else {
-av_assert0(0 && "Invalid RC mode.");
 }
 
 return 0;
@@ -1121,6 +1123,8 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = {
  FLAG_B_PICTURE_REFERENCES |
  FLAG_NON_IDR_KEY_PICTURES,
 
+.default_quality   = 25,
+
 .configure = _encode_h265_configure,
 
 .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
@@ -1172,6 +1176,9 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext 
*avctx)
 // CTU size is currently hard-coded to 32.
 ctx->slice_block_width = ctx->slice_block_height = 32;
 
+if (priv->qp > 0)
+ctx->explicit_qp = priv->qp;
+
 return ff_vaapi_encode_init(avctx);
 }
 
@@ -1189,9 +1196,10 @@ static av_cold int 
vaapi_encode_h265_close(AVCodecContext *avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h265_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
+VAAPI_ENCODE_RC_OPTIONS,
 
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
-  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
+  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
 
 { "aud", "Include AUD",
   OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_vp8: Enable support for more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:58 
2019 +| [2efd63a3158d62e7922427a19cbc9fe4b79399fa] | committer: Mark 
Thompson

vaapi_encode_vp8: Enable support for more RC modes

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2efd63a3158d62e7922427a19cbc9fe4b79399fa
---

 libavcodec/vaapi_encode_vp8.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index 166636cd84..ddbe4c9075 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -161,14 +161,15 @@ static int 
vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp8_configure(AVCodecContext *avctx)
 {
+VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodeVP8Context *priv = avctx->priv_data;
 
-priv->q_index_p = av_clip(avctx->global_quality, 0, VP8_MAX_QUANT);
+priv->q_index_p = av_clip(ctx->rc_quality, 0, VP8_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
-priv->q_index_i = av_clip((avctx->global_quality *
-   avctx->i_quant_factor +
-   avctx->i_quant_offset) + 0.5,
-  0, VP8_MAX_QUANT);
+priv->q_index_i =
+av_clip((avctx->i_quant_factor * priv->q_index_p  +
+ avctx->i_quant_offset) + 0.5,
+0, VP8_MAX_QUANT);
 else
 priv->q_index_i = priv->q_index_p;
 
@@ -185,6 +186,8 @@ static const VAAPIEncodeType vaapi_encode_type_vp8 = {
 
 .configure = _encode_vp8_configure,
 
+.default_quality   = 40,
+
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferVP8),
 .init_sequence_params  = _encode_vp8_init_sequence_params,
 
@@ -215,6 +218,8 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext 
*avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp8_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
+VAAPI_ENCODE_RC_OPTIONS,
+
 { "loop_filter_level", "Loop filter level",
   OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS 
},
 { "loop_filter_sharpness", "Loop filter sharpness",
@@ -226,7 +231,6 @@ static const AVCodecDefault vaapi_encode_vp8_defaults[] = {
 { "b",  "0"   },
 { "bf", "0"   },
 { "g",  "120" },
-{ "global_quality", "40"  },
 { "qmin",   "-1"  },
 { "qmax",   "-1"  },
 { NULL },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_h264: Enable support for more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:55 
2019 +| [f5eb08937e31f0927e8344d5161ed7217cd53779] | committer: Mark 
Thompson

vaapi_encode_h264: Enable support for more RC modes

Also fixes QP going out of range when modified by the quant factor/offset
values.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f5eb08937e31f0927e8344d5161ed7217cd53779
---

 libavcodec/vaapi_encode_h264.c | 31 +++
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 0be29d5b05..91be33f99f 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1065,33 +1065,34 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
 priv->mb_height = FFALIGN(avctx->height, 16) / 16;
 
 if (ctx->va_rc_mode == VA_RC_CQP) {
-priv->fixed_qp_p = priv->qp;
+priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
 if (avctx->i_quant_factor > 0.0)
-priv->fixed_qp_idr = (int)((priv->fixed_qp_p * 
avctx->i_quant_factor +
-avctx->i_quant_offset) + 0.5);
+priv->fixed_qp_idr =
+av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
+ avctx->i_quant_offset) + 0.5, 1, 51);
 else
 priv->fixed_qp_idr = priv->fixed_qp_p;
 if (avctx->b_quant_factor > 0.0)
-priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor 
+
-  avctx->b_quant_offset) + 0.5);
+priv->fixed_qp_b =
+av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
+ avctx->b_quant_offset) + 0.5, 1, 51);
 else
 priv->fixed_qp_b = priv->fixed_qp_p;
 
-priv->sei &= ~SEI_TIMING;
-
 av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
"%d / %d / %d for IDR- / P- / B-frames.\n",
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
 
-} else if (ctx->va_rc_mode == VA_RC_CBR ||
-   ctx->va_rc_mode == VA_RC_VBR) {
+} else {
 // These still need to be  set for pic_init_qp/slice_qp_delta.
 priv->fixed_qp_idr = 26;
 priv->fixed_qp_p   = 26;
 priv->fixed_qp_b   = 26;
+}
 
-} else {
-av_assert0(0 && "Invalid RC mode.");
+if (!ctx->rc_mode->hrd) {
+// Timing SEI requires a mode respecting HRD parameters.
+priv->sei &= ~SEI_TIMING;
 }
 
 if (priv->sei & SEI_IDENTIFIER) {
@@ -1141,6 +1142,8 @@ static const VAAPIEncodeType vaapi_encode_type_h264 = {
  FLAG_B_PICTURE_REFERENCES |
  FLAG_NON_IDR_KEY_PICTURES,
 
+.default_quality   = 20,
+
 .configure = _encode_h264_configure,
 
 .picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
@@ -1220,6 +1223,9 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 
 ctx->slice_block_height = ctx->slice_block_width = 16;
 
+if (priv->qp > 0)
+ctx->explicit_qp = priv->qp;
+
 return ff_vaapi_encode_init(avctx);
 }
 
@@ -1238,9 +1244,10 @@ static av_cold int 
vaapi_encode_h264_close(AVCodecContext *avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h264_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
+VAAPI_ENCODE_RC_OPTIONS,
 
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
-  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
+  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
 { "quality", "Set encode quality (trades off against speed, higher is 
faster)",
   OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
 { "coder", "Entropy coder type",

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_vp9: Fix whitespace after previous patch

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:47:00 
2019 +| [c4c2c4df76e15cf3e4c7a0b7500d3c0f8dade271] | committer: Mark 
Thompson

vaapi_encode_vp9: Fix whitespace after previous patch

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c4c2c4df76e15cf3e4c7a0b7500d3c0f8dade271
---

 libavcodec/vaapi_encode_vp9.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 8fb399f115..f89fd0d07a 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -182,21 +182,21 @@ static av_cold int 
vaapi_encode_vp9_configure(AVCodecContext *avctx)
 VAAPIEncodeVP9Context *priv = avctx->priv_data;
 
 if (ctx->rc_mode->quality) {
-priv->q_idx_p = av_clip(ctx->rc_quality, 0, VP9_MAX_QUANT);
-if (avctx->i_quant_factor > 0.0)
-priv->q_idx_idr = av_clip((priv->q_idx_p *
-   avctx->i_quant_factor +
-   avctx->i_quant_offset) + 0.5,
-  0, VP9_MAX_QUANT);
-else
-priv->q_idx_idr = priv->q_idx_p;
-if (avctx->b_quant_factor > 0.0)
-priv->q_idx_b = av_clip((priv->q_idx_p *
- avctx->b_quant_factor +
- avctx->b_quant_offset) + 0.5,
-0, VP9_MAX_QUANT);
-else
-priv->q_idx_b = priv->q_idx_p;
+priv->q_idx_p = av_clip(ctx->rc_quality, 0, VP9_MAX_QUANT);
+if (avctx->i_quant_factor > 0.0)
+priv->q_idx_idr =
+av_clip((avctx->i_quant_factor * priv->q_idx_p  +
+ avctx->i_quant_offset) + 0.5,
+0, VP9_MAX_QUANT);
+else
+priv->q_idx_idr = priv->q_idx_p;
+if (avctx->b_quant_factor > 0.0)
+priv->q_idx_b =
+av_clip((avctx->b_quant_factor * priv->q_idx_p  +
+ avctx->b_quant_offset) + 0.5,
+0, VP9_MAX_QUANT);
+else
+priv->q_idx_b = priv->q_idx_p;
 } else {
 // Arbitrary value.
 priv->q_idx_idr = priv->q_idx_p = priv->q_idx_b = 100;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_mjpeg: Use common quality option

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:47:01 
2019 +| [fda6dcd0b0a32a05e459b62ff5f40bbe56cd3290] | committer: Mark 
Thompson

vaapi_encode_mjpeg: Use common quality option

Doesn't change anything, but makes the behaviour better match that of the
other codecs (the CONSTANT_QUALITY_ONLY flag already ensures that CQP is
the only RC mode selectable for MJPEG).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fda6dcd0b0a32a05e459b62ff5f40bbe56cd3290
---

 libavcodec/vaapi_encode_mjpeg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 72e794604a..4dcdc3d16b 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -438,7 +438,7 @@ static av_cold int 
vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 int err;
 
-priv->quality = avctx->global_quality;
+priv->quality = ctx->rc_quality;
 if (priv->quality < 1 || priv->quality > 100) {
 av_log(avctx, AV_LOG_ERROR, "Invalid quality value %d "
"(must be 1-100).\n", priv->quality);
@@ -483,6 +483,8 @@ static const VAAPIEncodeType vaapi_encode_type_mjpeg = {
 
 .configure = _encode_mjpeg_configure,
 
+.default_quality   = 80,
+
 .picture_params_size   = sizeof(VAEncPictureParameterBufferJPEG),
 .init_picture_params   = _encode_mjpeg_init_picture_params,
 
@@ -537,7 +539,6 @@ static const AVOption vaapi_encode_mjpeg_options[] = {
 };
 
 static const AVCodecDefault vaapi_encode_mjpeg_defaults[] = {
-{ "global_quality", "80" },
 { "b",  "0"  },
 { NULL },
 };

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_mpeg2: Add missing marker bit in time_code

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:47:02 
2019 +| [f948082e5fc24b00c5b7dbf4493906f1e540a743] | committer: Mark 
Thompson

vaapi_encode_mpeg2: Add missing marker bit in time_code

We don't have anything useful to put in this field, but there is still
meant to be a marker bit in the middle of it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f948082e5fc24b00c5b7dbf4493906f1e540a743
---

 libavcodec/vaapi_encode_mpeg2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index ef8af664c2..fb1ef71fdc 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -313,7 +313,8 @@ static int 
vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
 
 goph->group_start_code = MPEG2_START_GROUP;
 
-goph->time_code   = 0;
+// Marker bit in the middle of time_code.
+goph->time_code   = 1 << 12;
 goph->closed_gop  = 1;
 goph->broken_link = 0;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode_vp9: Enable support for more RC modes

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sun Feb 10 19:46:59 
2019 +| [28e619e268ccd992848404600c45c12c5227acde] | committer: Mark 
Thompson

vaapi_encode_vp9: Enable support for more RC modes

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=28e619e268ccd992848404600c45c12c5227acde
---

 libavcodec/vaapi_encode_vp9.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 97142dcc49..8fb399f115 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -178,23 +178,29 @@ static int 
vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
 {
+VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodeVP9Context *priv = avctx->priv_data;
 
-priv->q_idx_p = av_clip(avctx->global_quality, 0, VP9_MAX_QUANT);
+if (ctx->rc_mode->quality) {
+priv->q_idx_p = av_clip(ctx->rc_quality, 0, VP9_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
-priv->q_idx_idr = av_clip((avctx->global_quality *
+priv->q_idx_idr = av_clip((priv->q_idx_p *
avctx->i_quant_factor +
avctx->i_quant_offset) + 0.5,
   0, VP9_MAX_QUANT);
 else
 priv->q_idx_idr = priv->q_idx_p;
 if (avctx->b_quant_factor > 0.0)
-priv->q_idx_b = av_clip((avctx->global_quality *
+priv->q_idx_b = av_clip((priv->q_idx_p *
  avctx->b_quant_factor +
  avctx->b_quant_offset) + 0.5,
 0, VP9_MAX_QUANT);
 else
 priv->q_idx_b = priv->q_idx_p;
+} else {
+// Arbitrary value.
+priv->q_idx_idr = priv->q_idx_p = priv->q_idx_b = 100;
+}
 
 return 0;
 }
@@ -211,6 +217,8 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = {
 .flags = FLAG_B_PICTURES |
  FLAG_B_PICTURE_REFERENCES,
 
+.default_quality   = 100,
+
 .picture_priv_data_size = sizeof(VAAPIEncodeVP9Picture),
 
 .configure = _encode_vp9_configure,
@@ -244,6 +252,8 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext 
*avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp9_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
+VAAPI_ENCODE_RC_OPTIONS,
+
 { "loop_filter_level", "Loop filter level",
   OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS 
},
 { "loop_filter_sharpness", "Loop filter sharpness",
@@ -255,7 +265,6 @@ static const AVCodecDefault vaapi_encode_vp9_defaults[] = {
 { "b",  "0"   },
 { "bf", "0"   },
 { "g",  "250" },
-{ "global_quality", "100" },
 { "qmin",   "-1"  },
 { "qmax",   "-1"  },
 { NULL },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] vaapi_encode: Do not zero access unit structures

2019-02-25 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Feb 25 23:24:23 
2019 +| [9d5ca71ec2efddfa0d30ae88db66fd0bd3f1f33b] | committer: Mark 
Thompson

vaapi_encode: Do not zero access unit structures

Following b8c45bbcbc207293f955e838ea66106f4b65b1ac they contain allocated
unit arrays which will get leaked.  These operations were inconsistently
applied and never actually needed (the old uninit left them in the correct
state), so just drop them entirely.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9d5ca71ec2efddfa0d30ae88db66fd0bd3f1f33b
---

 libavcodec/vaapi_encode_h264.c | 6 --
 libavcodec/vaapi_encode_h265.c | 3 ---
 2 files changed, 9 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 9f984ec60d..0be29d5b05 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -299,9 +299,6 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
 VAEncPictureParameterBufferH264  *vpic = ctx->codec_picture_params;
 
-memset(>current_access_unit, 0,
-   sizeof(priv->current_access_unit));
-
 memset(sps, 0, sizeof(*sps));
 memset(pps, 0, sizeof(*pps));
 
@@ -624,9 +621,6 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
 int i;
 
-memset(>current_access_unit, 0,
-   sizeof(priv->current_access_unit));
-
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
 
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 9e32cd285b..d37100c52d 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -270,9 +270,6 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 int chroma_format, bit_depth;
 int i;
 
-memset(>current_access_unit, 0,
-   sizeof(priv->current_access_unit));
-
 memset(vps, 0, sizeof(*vps));
 memset(sps, 0, sizeof(*sps));
 memset(pps, 0, sizeof(*pps));

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] libavcodec/cbs: Stop needlessly reallocating the units array

2019-02-25 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt 
 | Mon Feb 11 23:47:43 2019 +0100| 
[b8c45bbcbc207293f955e838ea66106f4b65b1ac] | committer: Mark Thompson

libavcodec/cbs: Stop needlessly reallocating the units array

Currently, a fragment's unit array is constantly reallocated during
splitting of a packet. This commit changes this: One can keep the units
array by distinguishing between the number of allocated and the number
of valid units in the units array.

The more units a packet is split into, the bigger the benefit.
So MPEG-2 benefits the most; for a video coming from an NTSC-DVD
(usually 32 units per frame) the average cost of cbs_insert_unit (for a
single unit) went down from 6717 decicycles to 450 decicycles (based
upon 10 runs with 4194304 runs each); if each packet consists of only
one unit, it went down from 2425 to 448; for a H.264 video where most
packets contain nine units, it went from 4431 to 450.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b8c45bbcbc207293f955e838ea66106f4b65b1ac
---

 libavcodec/av1_metadata_bsf.c   |  6 ++--
 libavcodec/av1_parser.c |  5 +--
 libavcodec/cbs.c| 62 +
 libavcodec/cbs.h| 33 +---
 libavcodec/filter_units_bsf.c   |  7 +++--
 libavcodec/h264_metadata_bsf.c  |  6 ++--
 libavcodec/h264_redundant_pps_bsf.c |  6 ++--
 libavcodec/h265_metadata_bsf.c  |  6 ++--
 libavcodec/mpeg2_metadata_bsf.c |  6 ++--
 libavcodec/trace_headers_bsf.c  |  5 +--
 libavcodec/vaapi_encode_h264.c  |  9 +++---
 libavcodec/vaapi_encode_h265.c  |  9 +++---
 libavcodec/vaapi_encode_mjpeg.c |  3 +-
 libavcodec/vaapi_encode_mpeg2.c |  5 +--
 libavcodec/vp9_metadata_bsf.c   |  4 ++-
 15 files changed, 113 insertions(+), 59 deletions(-)

diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
index 52d383661f..2b74b697e4 100644
--- a/libavcodec/av1_metadata_bsf.c
+++ b/libavcodec/av1_metadata_bsf.c
@@ -170,7 +170,7 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket 
*out)
 
 err = 0;
 fail:
-ff_cbs_fragment_uninit(ctx->cbc, frag);
+ff_cbs_fragment_reset(ctx->cbc, frag);
 
 if (err < 0)
 av_packet_unref(out);
@@ -215,13 +215,15 @@ static int av1_metadata_init(AVBSFContext *bsf)
 
 err = 0;
 fail:
-ff_cbs_fragment_uninit(ctx->cbc, frag);
+ff_cbs_fragment_reset(ctx->cbc, frag);
 return err;
 }
 
 static void av1_metadata_close(AVBSFContext *bsf)
 {
 AV1MetadataContext *ctx = bsf->priv_data;
+
+ff_cbs_fragment_free(ctx->cbc, >access_unit);
 ff_cbs_close(>cbc);
 }
 
diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index 8df66498f4..bb8737a393 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -72,7 +72,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
 goto end;
 }
 
-ff_cbs_fragment_uninit(s->cbc, td);
+ff_cbs_fragment_reset(s->cbc, td);
 }
 
 ret = ff_cbs_read(s->cbc, td, data, size);
@@ -159,7 +159,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
 }
 
 end:
-ff_cbs_fragment_uninit(s->cbc, td);
+ff_cbs_fragment_reset(s->cbc, td);
 
 s->cbc->log_ctx = NULL;
 
@@ -193,6 +193,7 @@ static void av1_parser_close(AVCodecParserContext *ctx)
 {
 AV1ParseContext *s = ctx->priv_data;
 
+ff_cbs_fragment_free(s->cbc, >temporal_unit);
 ff_cbs_close(>cbc);
 }
 
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index ecbf57c293..c388be896b 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -136,14 +136,13 @@ static void cbs_unit_uninit(CodedBitstreamContext *ctx,
 unit->data_bit_padding = 0;
 }
 
-void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
-CodedBitstreamFragment *frag)
+void ff_cbs_fragment_reset(CodedBitstreamContext *ctx,
+   CodedBitstreamFragment *frag)
 {
 int i;
 
 for (i = 0; i < frag->nb_units; i++)
 cbs_unit_uninit(ctx, >units[i]);
-av_freep(>units);
 frag->nb_units = 0;
 
 av_buffer_unref(>data_ref);
@@ -152,6 +151,15 @@ void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
 frag->data_bit_padding = 0;
 }
 
+void ff_cbs_fragment_free(CodedBitstreamContext *ctx,
+  CodedBitstreamFragment *frag)
+{
+ff_cbs_fragment_reset(ctx, frag);
+
+av_freep(>units);
+frag->nb_units_allocated = 0;
+}
+
 static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
  CodedBitstreamFragment *frag)
 {
@@ -216,8 +224,6 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
 {
 int err;
 
-memset(frag, 0, sizeof(*frag));
-
 err = cbs_fill_fragment_data(ctx, frag, par->extradata,
  par->extradata_size);
 if (err < 0)
@@ -236,8 +242,6 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx,
 {
 

[FFmpeg-cvslog] filter_units, trace_headers: Always use fragment from context

2019-02-25 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt 
 | Mon Feb 11 23:47:42 2019 +0100| 
[c5b452ed2f16a0d7bf01d7d84097337f8756987b] | committer: Mark Thompson

filter_units, trace_headers: Always use fragment from context

This is in preparation for another patch that will stop needless
reallocations of the unit array.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5b452ed2f16a0d7bf01d7d84097337f8756987b
---

 libavcodec/filter_units_bsf.c  |  8 
 libavcodec/trace_headers_bsf.c | 13 +++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
index 1ee0afdf2b..0500dea6b2 100644
--- a/libavcodec/filter_units_bsf.c
+++ b/libavcodec/filter_units_bsf.c
@@ -199,18 +199,18 @@ static int filter_units_init(AVBSFContext *bsf)
 ctx->cbc->nb_decompose_unit_types = 0;
 
 if (bsf->par_in->extradata) {
-CodedBitstreamFragment ps;
+CodedBitstreamFragment *frag = >fragment;
 
-err = ff_cbs_read_extradata(ctx->cbc, , bsf->par_in);
+err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
 if (err < 0) {
 av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
 } else {
-err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, );
+err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag);
 if (err < 0)
 av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
 }
 
-ff_cbs_fragment_uninit(ctx->cbc, );
+ff_cbs_fragment_uninit(ctx->cbc, frag);
 }
 
 return err;
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
index 839d4c..61284e615e 100644
--- a/libavcodec/trace_headers_bsf.c
+++ b/libavcodec/trace_headers_bsf.c
@@ -28,6 +28,7 @@
 
 typedef struct TraceHeadersContext {
 CodedBitstreamContext *cbc;
+CodedBitstreamFragment fragment;
 } TraceHeadersContext;
 
 
@@ -44,13 +45,13 @@ static int trace_headers_init(AVBSFContext *bsf)
 ctx->cbc->trace_level  = AV_LOG_INFO;
 
 if (bsf->par_in->extradata) {
-CodedBitstreamFragment ps;
+CodedBitstreamFragment *frag = >fragment;
 
 av_log(bsf, AV_LOG_INFO, "Extradata\n");
 
-err = ff_cbs_read_extradata(ctx->cbc, , bsf->par_in);
+err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
 
-ff_cbs_fragment_uninit(ctx->cbc, );
+ff_cbs_fragment_uninit(ctx->cbc, frag);
 }
 
 return err;
@@ -66,7 +67,7 @@ static void trace_headers_close(AVBSFContext *bsf)
 static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
 {
 TraceHeadersContext *ctx = bsf->priv_data;
-CodedBitstreamFragment au;
+CodedBitstreamFragment *frag = >fragment;
 char tmp[256] = { 0 };
 int err;
 
@@ -92,9 +93,9 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
 
 av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
 
-err = ff_cbs_read_packet(ctx->cbc, , pkt);
+err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
 
-ff_cbs_fragment_uninit(ctx->cbc, );
+ff_cbs_fragment_uninit(ctx->cbc, frag);
 
 if (err < 0)
 av_packet_unref(pkt);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/wcmv: Copy/Init frame later

2019-02-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Feb 19 19:02:07 2019 +0100| [286a33e42944919774c7386137ae0f546985c260] | 
committer: Michael Niedermayer

avcodec/wcmv: Copy/Init frame later

Speeds up error cases
Fixes: 
13132/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664190616829952

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=286a33e42944919774c7386137ae0f546985c260
---

 libavcodec/wcmv.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/wcmv.c b/libavcodec/wcmv.c
index ebd5ef66f4..f03761b343 100644
--- a/libavcodec/wcmv.c
+++ b/libavcodec/wcmv.c
@@ -60,16 +60,6 @@ static int decode_frame(AVCodecContext *avctx,
 if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
 return ret;
 
-if (s->prev_frame->data[0]) {
-ret = av_frame_copy(frame, s->prev_frame);
-if (ret < 0)
-return ret;
-} else {
-ptrdiff_t linesize[4] = { frame->linesize[0], 0, 0, 0 };
-av_image_fill_black(frame->data, linesize, avctx->pix_fmt, 0,
-avctx->width, avctx->height);
-}
-
 blocks = bytestream2_get_le16();
 if (blocks > 5) {
 GetByteContext bgb;
@@ -162,6 +152,16 @@ static int decode_frame(AVCodecContext *avctx,
 bytestream2_seek(, 2, SEEK_SET);
 }
 
+if (s->prev_frame->data[0]) {
+ret = av_frame_copy(frame, s->prev_frame);
+if (ret < 0)
+return ret;
+} else {
+ptrdiff_t linesize[4] = { frame->linesize[0], 0, 0, 0 };
+av_image_fill_black(frame->data, linesize, avctx->pix_fmt, 0,
+avctx->width, avctx->height);
+}
+
 for (int block = 0; block < blocks; block++) {
 int x, y, w, h;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/mjpegdec: Fix stereo3d memleak

2019-02-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Feb 17 20:43:28 2019 +0100| [32d022d26db44cf153ab953360bc995976cc695b] | 
committer: Michael Niedermayer

avcodec/mjpegdec: Fix stereo3d memleak

Fixes: 
12937/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5714945346371584

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=32d022d26db44cf153ab953360bc995976cc695b
---

 libavcodec/mjpegdec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 902b8eb7cb..e82c185433 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1903,6 +1903,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
 type   = get_bits(>gb, 8);
 len -= 4;
 
+av_freep(>stereo3d);
 s->stereo3d = av_stereo3d_alloc();
 if (!s->stereo3d) {
 goto out;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/wcmv: Avoid copying frames if they are unchanged

2019-02-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Feb 19 19:05:10 2019 +0100| [976dae8b32f48d17cccfd6b19d2beb01770dfa7c] | 
committer: Michael Niedermayer

avcodec/wcmv: Avoid copying frames if they are unchanged

Improves speed of the testcase by about a factor of 10

Fixes: Timeout
Fixes: 
13132/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664190616829952

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=976dae8b32f48d17cccfd6b19d2beb01770dfa7c
---

 libavcodec/wcmv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/wcmv.c b/libavcodec/wcmv.c
index f03761b343..2988c15b23 100644
--- a/libavcodec/wcmv.c
+++ b/libavcodec/wcmv.c
@@ -56,11 +56,13 @@ static int decode_frame(AVCodecContext *avctx,
 }
 
 bytestream2_init(, avpkt->data, avpkt->size);
+blocks = bytestream2_get_le16();
+if (!blocks)
+return avpkt->size;
 
 if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
 return ret;
 
-blocks = bytestream2_get_le16();
 if (blocks > 5) {
 GetByteContext bgb;
 int x = 0, size;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/error_resilience: Use a symmetric check for skipping MV estimation

2019-02-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Feb 19 18:41:42 2019 +0100| [e4289cb253e29e4d62dc46759eb1a45d8f6d82df] | 
committer: Michael Niedermayer

avcodec/error_resilience: Use a symmetric check for skipping MV estimation

This speeds up the testcase by a factor of 4

Fixes: Timeout
Fixes: 
13100/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMV2_fuzzer-5767533905313792

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e4289cb253e29e4d62dc46759eb1a45d8f6d82df
---

 libavcodec/error_resilience.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 1abae53f41..35d0c609e5 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -437,7 +437,7 @@ static void guess_mv(ERContext *s)
 }
 
 if ((!(s->avctx->error_concealment_EC_GUESS_MVS)) ||
-num_avail <= mb_width / 2) {
+num_avail <= FFMAX(mb_width, mb_height) / 2) {
 for (mb_y = 0; mb_y < mb_height; mb_y++) {
 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
 const int mb_xy = mb_x + mb_y * s->mb_stride;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/arbc: Check nb_tiles against dimensions

2019-02-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Feb 17 22:40:34 2019 +0100| [160851bceed719c45459c64ab62b8e5bc130e2ee] | 
committer: Michael Niedermayer

avcodec/arbc: Check nb_tiles against dimensions

Fixes: Timeout
Fixes: 
12967/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ARBC_fuzzer-5639021454163968

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=160851bceed719c45459c64ab62b8e5bc130e2ee
---

 libavcodec/arbc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/arbc.c b/libavcodec/arbc.c
index 4558304f12..841a9f10ac 100644
--- a/libavcodec/arbc.c
+++ b/libavcodec/arbc.c
@@ -45,6 +45,9 @@ static void fill_tile4(AVCodecContext *avctx, uint8_t *color, 
AVFrame *frame)
 int nb_tiles = bytestream2_get_le16(gb);
 int h = avctx->height - 1;
 
+if ((avctx->width / 4 + 1) * (avctx->height / 4 + 1) < nb_tiles)
+return;
+
 for (int i = 0; i < nb_tiles; i++) {
 int y = bytestream2_get_byte(gb);
 int x = bytestream2_get_byte(gb);
@@ -79,6 +82,9 @@ static void fill_tileX(AVCodecContext *avctx, int tile_width, 
int tile_height,
 int nb_tiles = bytestream2_get_le16(gb);
 int h = avctx->height - 1;
 
+if ((avctx->width / tile_width + 1) * (avctx->height / tile_height + 1) < 
nb_tiles)
+return;
+
 for (int i = 0; i < nb_tiles; i++) {
 int y = bytestream2_get_byte(gb);
 int x = bytestream2_get_byte(gb);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] doc: -report defaults to loglevel debug

2019-02-25 Thread Gyan Doshi
ffmpeg | branch: master | Gyan Doshi  | Mon Feb 25 21:59:14 
2019 +0530| [cdf17cf92b0f9c02951b7ea25d6a15282bdf] | committer: Gyan Doshi

doc: -report defaults to loglevel debug

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cdf17cf92b0f9c02951b7ea25d6a15282bdf
---

 doc/fftools-common-opts.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index f4820fd293..e75bec4354 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -239,7 +239,7 @@ Dump full command line and console output to a file named
 @code{@var{program}-@var{MMDD}-@var{HHMMSS}.log} in the current
 directory.
 This file can be useful for bug reports.
-It also implies @code{-loglevel verbose}.
+It also implies @code{-loglevel debug}.
 
 Setting the environment variable @env{FFREPORT} to any value has the
 same effect. If the value is a ':'-separated key=value sequence, these

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog