[FFmpeg-devel] [PATCH v3 4/4] swscale/output: add rgbaf32 output support

2022-11-02 Thread mindmark
From: Mark Reid 

---
 libswscale/output.c  | 92 
 libswscale/swscale_unscaled.c|  4 +-
 libswscale/tests/floatimg_cmp.c  |  4 +-
 libswscale/utils.c   | 16 +++--
 libswscale/yuv2rgb.c |  2 +
 tests/ref/fate/filter-pixdesc-rgbaf32be  |  1 +
 tests/ref/fate/filter-pixdesc-rgbaf32le  |  1 +
 tests/ref/fate/filter-pixdesc-rgbf32be   |  1 +
 tests/ref/fate/filter-pixdesc-rgbf32le   |  1 +
 tests/ref/fate/filter-pixfmts-copy   |  4 ++
 tests/ref/fate/filter-pixfmts-crop   |  4 ++
 tests/ref/fate/filter-pixfmts-field  |  4 ++
 tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
 tests/ref/fate/filter-pixfmts-hflip  |  4 ++
 tests/ref/fate/filter-pixfmts-il |  4 ++
 tests/ref/fate/filter-pixfmts-null   |  4 ++
 tests/ref/fate/filter-pixfmts-scale  |  4 ++
 tests/ref/fate/filter-pixfmts-transpose  |  4 ++
 tests/ref/fate/filter-pixfmts-vflip  |  4 ++
 tests/ref/fate/sws-floatimg-cmp  | 16 +
 20 files changed, 170 insertions(+), 8 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le

diff --git a/libswscale/output.c b/libswscale/output.c
index 5c85bff971..1d86a244f9 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2471,6 +2471,92 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 }
 }
 
+static void
+yuv2rgbaf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
+const int16_t **lumSrcx, int lumFilterSize,
+const int16_t *chrFilter, const int16_t **chrUSrcx,
+const int16_t **chrVSrcx, int chrFilterSize,
+const int16_t **alpSrcx, uint8_t *dest,
+int dstW, int y)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
+int i;
+int alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
+int hasAlpha = alpha && alpSrcx;
+int pixelStep = alpha ? 4 : 3;
+uint32_t *dest32 = (uint32_t*)dest;
+const int32_t **lumSrc  = (const int32_t**)lumSrcx;
+const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
+const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
+const int32_t **alpSrc  = (const int32_t**)alpSrcx;
+static const float float_mult = 1.0f / 65535.0f;
+uint32_t a = av_float2int(1.0f);
+
+for (i = 0; i < dstW; i++) {
+int j;
+int Y = -0x4000;
+int U = -(128 << 23);
+int V = -(128 << 23);
+int R, G, B, A;
+
+for (j = 0; j < lumFilterSize; j++)
+Y += lumSrc[j][i] * (unsigned)lumFilter[j];
+
+for (j = 0; j < chrFilterSize; j++) {
+U += chrUSrc[j][i] * (unsigned)chrFilter[j];
+V += chrVSrc[j][i] * (unsigned)chrFilter[j];
+}
+
+Y >>= 14;
+Y += 0x1;
+U >>= 14;
+V >>= 14;
+
+if (hasAlpha) {
+A = -0x4000;
+
+for (j = 0; j < lumFilterSize; j++)
+A += alpSrc[j][i] * (unsigned)lumFilter[j];
+
+A >>= 1;
+A += 0x20002000;
+a = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 
14));
+}
+
+Y -= c->yuv2rgb_y_offset;
+Y *= c->yuv2rgb_y_coeff;
+Y += (1 << 13) - (1 << 29);
+R = V * c->yuv2rgb_v2r_coeff;
+G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
+B =U * c->yuv2rgb_u2b_coeff;
+
+R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
+G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
+B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
+
+dest32[0] = av_float2int(float_mult * (float)R);
+dest32[1] = av_float2int(float_mult * (float)G);
+dest32[2] = av_float2int(float_mult * (float)B);
+if (alpha)
+dest32[3] = a;
+
+dest32 += pixelStep;
+}
+if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
+dest32 = (uint32_t*)dest;
+for (i = 0; i < dstW; i++) {
+dest32[0] = av_bswap32(dest32[0]);
+dest32[1] = av_bswap32(dest32[1]);
+dest32[2] = av_bswap32(dest32[2]);
+if (alpha)
+dest32[3] = av_bswap32(dest32[3]);
+
+dest32 += pixelStep;
+}
+}
+
+}
+
 static void
 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
 const int16_t *ubuf[2], const int16_t *vbuf[2],
@@ -2983,6 +3069,12 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
 }
 break;
 
+case AV_PIX_FMT_RGBF32LE:
+case AV_PIX_FMT_RGBF32BE:
+case AV_PIX_FMT_RGBAF32LE:
+case AV_PIX_FMT_RGBAF32BE:
+*yuv2packedX = yuv2rgbaf32_full_X_c;
+break;
 case AV_PIX_FMT_RGB24:
  

[FFmpeg-devel] [PATCH v3 3/4] avfilter/vf_transpose: add support for packed rgb float formats

2022-11-02 Thread mindmark
From: Mark Reid 

---
 libavfilter/vf_transpose.c | 44 ++
 1 file changed, 44 insertions(+)

diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index 469e66729f..1023d6fe82 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -174,6 +174,46 @@ static void transpose_8x8_64_c(uint8_t *src, ptrdiff_t 
src_linesize,
 transpose_block_64_c(src, src_linesize, dst, dst_linesize, 8, 8);
 }
 
+static inline void transpose_block_96_c(uint8_t *src, ptrdiff_t src_linesize,
+uint8_t *dst, ptrdiff_t dst_linesize,
+int w, int h)
+{
+int x, y;
+for (y = 0; y < h; y++, dst += dst_linesize, src += 12) {
+for (x = 0; x < w; x++) {
+*((uint32_t *)(dst+0 + 12*x)) = *((uint32_t *)(src+0 + 
x*src_linesize));
+*((uint32_t *)(dst+4 + 12*x)) = *((uint32_t *)(src+4 + 
x*src_linesize));
+*((uint32_t *)(dst+8 + 12*x)) = *((uint32_t *)(src+8 + 
x*src_linesize));
+}
+}
+}
+
+static void transpose_8x8_96_c(uint8_t *src, ptrdiff_t src_linesize,
+   uint8_t *dst, ptrdiff_t dst_linesize)
+{
+transpose_block_96_c(src, src_linesize, dst, dst_linesize, 8, 8);
+}
+
+
+static inline void transpose_block_128_c(uint8_t *src, ptrdiff_t src_linesize,
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ int w, int h)
+{
+int x, y;
+for (y = 0; y < h; y++, dst += dst_linesize, src += 16) {
+for (x = 0; x < w; x++) {
+*((uint64_t *)(dst+0 + 16*x)) = *((uint64_t *)(src+0 + 
x*src_linesize));
+*((uint64_t *)(dst+8 + 16*x)) = *((uint64_t *)(src+8 + 
x*src_linesize));
+}
+}
+}
+
+static void transpose_8x8_128_c(uint8_t *src, ptrdiff_t src_linesize,
+uint8_t *dst, ptrdiff_t dst_linesize)
+{
+transpose_block_128_c(src, src_linesize, dst, dst_linesize, 8, 8);
+}
+
 static int config_props_output(AVFilterLink *outlink)
 {
 AVFilterContext *ctx = outlink->src;
@@ -232,6 +272,10 @@ static int config_props_output(AVFilterLink *outlink)
 v->transpose_8x8   = transpose_8x8_48_c; break;
 case 8: v->transpose_block = transpose_block_64_c;
 v->transpose_8x8   = transpose_8x8_64_c; break;
+case 12: v->transpose_block = transpose_block_96_c;
+ v->transpose_8x8   = transpose_8x8_96_c; break;
+case 16: v->transpose_block = transpose_block_128_c;
+ v->transpose_8x8   = transpose_8x8_128_c; break;
 }
 }
 
-- 
2.31.1.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/4] avfilter/vf_hflip: add support for packed rgb float formats

2022-11-02 Thread mindmark
From: Mark Reid 

---
 libavfilter/vf_hflip_init.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavfilter/vf_hflip_init.h b/libavfilter/vf_hflip_init.h
index d0319f463d..31173f73fc 100644
--- a/libavfilter/vf_hflip_init.h
+++ b/libavfilter/vf_hflip_init.h
@@ -86,6 +86,29 @@ static void hflip_qword_c(const uint8_t *ssrc, uint8_t 
*ddst, int w)
 dst[j] = src[-j];
 }
 
+static void hflip_b96_c(const uint8_t *ssrc, uint8_t *ddst, int w)
+{
+const uint32_t *in = (const uint32_t *)ssrc;
+uint32_t *out = (uint32_t *)ddst;
+
+for (int j = 0; j < w; j++, out += 3, in -= 3) {
+out[0] = in[0];
+out[1] = in[1];
+out[2] = in[2];
+}
+}
+
+static void hflip_b128_c(const uint8_t *ssrc, uint8_t *ddst, int w)
+{
+const uint64_t *in = (const uint64_t *)ssrc;
+uint64_t *out = (uint64_t *)ddst;
+
+for (int j = 0; j < w; j++, out += 2, in -= 2) {
+out[0] = in[0];
+out[1] = in[1];
+}
+}
+
 static av_unused int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
 {
 for (int i = 0; i < nb_planes; i++) {
@@ -97,6 +120,8 @@ static av_unused int ff_hflip_init(FlipContext *s, int 
step[4], int nb_planes)
 case 4: s->flip_line[i] = hflip_dword_c; break;
 case 6: s->flip_line[i] = hflip_b48_c;   break;
 case 8: s->flip_line[i] = hflip_qword_c; break;
+case 12: s->flip_line[i] = hflip_b96_c; break;
+case 16: s->flip_line[i] = hflip_b128_c; break;
 default:
 return AVERROR_BUG;
 }
-- 
2.31.1.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/4] swscale/input: add rgbaf32 input support

2022-11-02 Thread mindmark
From: Mark Reid 

---
 libswscale/input.c | 172 +
 libswscale/utils.c |   4 ++
 2 files changed, 176 insertions(+)

diff --git a/libswscale/input.c b/libswscale/input.c
index 7ff7bfaa01..4683284b0b 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -1284,6 +1284,136 @@ static void rgbaf16##endian_name##ToA_c(uint8_t *_dst, 
const uint8_t *_src, cons
 rgbaf16_funcs_endian(le, 0)
 rgbaf16_funcs_endian(be, 1)
 
+#define rdpx(src) (is_be ? av_int2float(AV_RB32(&src)): 
av_int2float(AV_RL32(&src)))
+
+static av_always_inline void rgbaf32ToUV_half_endian(uint16_t *dstU, uint16_t 
*dstV, int is_be,
+ const float *src, int 
width,
+ int32_t *rgb2yuv, int 
comp)
+{
+int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+int i;
+for (i = 0; i < width; i++) {
+int r = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+0]), 0.0f, 
65535.0f)) +
+ lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+4]), 0.0f, 
65535.0f))) >> 1;
+int g = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+1]), 0.0f, 
65535.0f)) +
+ lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+5]), 0.0f, 
65535.0f))) >> 1;
+int b = (lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+2]), 0.0f, 
65535.0f)) +
+ lrintf(av_clipf(65535.0f * rdpx(src[i*(comp*2)+6]), 0.0f, 
65535.0f))) >> 1;
+
+dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+}
+}
+
+static av_always_inline void rgbaf32ToUV_endian(uint16_t *dstU, uint16_t 
*dstV, int is_be,
+const float *src, int width,
+int32_t *rgb2yuv, int comp)
+{
+int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+int i;
+for (i = 0; i < width; i++) {
+int r = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+0]), 0.0f, 
65535.0f));
+int g = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+1]), 0.0f, 
65535.0f));
+int b = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+2]), 0.0f, 
65535.0f));
+
+dstU[i] = (ru*r + gu*g + bu*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+dstV[i] = (rv*r + gv*g + bv*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+}
+}
+
+static av_always_inline void rgbaf32ToY_endian(uint16_t *dst, const float 
*src, int is_be,
+   int width, int32_t *rgb2yuv, 
int comp)
+{
+int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
+int i;
+for (i = 0; i < width; i++) {
+int r = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+0]), 0.0f, 
65535.0f));
+int g = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+1]), 0.0f, 
65535.0f));
+int b = lrintf(av_clipf(65535.0f * rdpx(src[i*comp+2]), 0.0f, 
65535.0f));
+
+dst[i] = (ry*r + gy*g + by*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+}
+}
+
+static av_always_inline void rgbaf32ToA_endian(uint16_t *dst, const float 
*src, int is_be,
+   int width, void *opq)
+{
+int i;
+for (i=0; isrcFormat;
@@ -1570,6 +1700,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
 case AV_PIX_FMT_RGBAF16LE:
 c->chrToYV12 = rgbaf16leToUV_half_c;
 break;
+case AV_PIX_FMT_RGBF32BE:
+c->chrToYV12 = rgbf32beToUV_half_c;
+break;
+case AV_PIX_FMT_RGBAF32BE:
+c->chrToYV12 = rgbaf32beToUV_half_c;
+break;
+case AV_PIX_FMT_RGBF32LE:
+c->chrToYV12 = rgbf32leToUV_half_c;
+break;
+case AV_PIX_FMT_RGBAF32LE:
+c->chrToYV12 = rgbaf32leToUV_half_c;
+break;
 }
 } else {
 switch (srcFormat) {
@@ -1663,6 +1805,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
 case AV_PIX_FMT_RGBAF16LE:
 c->chrToYV12 = rgbaf16leToUV_c;
 break;
+case AV_PIX_FMT_RGBF32BE:
+c->chrToYV12 = rgbf32beToUV_c;
+break;
+case AV_PIX_FMT_RGBAF32BE:
+c->chrToYV12 = rgbaf32beToUV_c;
+break;
+case AV_PIX_FMT_RGBF32LE:
+c->chrToYV12 = rgbf32leToUV_c;
+break;
+case AV_PIX_FMT_RGBAF32LE:
+c->chrToYV12 = rgbaf32leToUV_c;
+break;
 }
 }
 
@@ -1973,6 +2127,18 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
 case AV_PIX_FMT_RGBAF16LE:
 c->lumToYV12 = rgbaf16leToY_c;
 break;
+case AV_PIX_FMT_RGBF32BE:
+ 

[FFmpeg-devel] [PATCH v3 0/4] swscale rgbaf32 input/output support

2022-11-02 Thread mindmark
From: Mark Reid 

This patch series adds swscale input/output support for the packed rgb float 
formats.
A few of the filters also needed support the larger 96/128 bit packed pixel 
sizes.

I also plan to eventually add lossless unscaled conversions between the planer 
and packed formats.

changes since v2
* add bias to rgbaf32 output to improve non overflowing range
changes since v1
* output correct alpha if src doesn't have alpha

Mark Reid (4):
  swscale/input: add rgbaf32 input support
  avfilter/vf_hflip: add support for packed rgb float formats
  avfilter/vf_transpose: add support for packed rgb float formats
  swscale/output: add rgbaf32 output support

 libavfilter/vf_hflip_init.h  |  25 
 libavfilter/vf_transpose.c   |  44 ++
 libswscale/input.c   | 172 +++
 libswscale/output.c  |  92 
 libswscale/swscale_unscaled.c|   4 +-
 libswscale/tests/floatimg_cmp.c  |   4 +-
 libswscale/utils.c   |  12 +-
 libswscale/yuv2rgb.c |   2 +
 tests/ref/fate/filter-pixdesc-rgbaf32be  |   1 +
 tests/ref/fate/filter-pixdesc-rgbaf32le  |   1 +
 tests/ref/fate/filter-pixdesc-rgbf32be   |   1 +
 tests/ref/fate/filter-pixdesc-rgbf32le   |   1 +
 tests/ref/fate/filter-pixfmts-copy   |   4 +
 tests/ref/fate/filter-pixfmts-crop   |   4 +
 tests/ref/fate/filter-pixfmts-field  |   4 +
 tests/ref/fate/filter-pixfmts-fieldorder |   4 +
 tests/ref/fate/filter-pixfmts-hflip  |   4 +
 tests/ref/fate/filter-pixfmts-il |   4 +
 tests/ref/fate/filter-pixfmts-null   |   4 +
 tests/ref/fate/filter-pixfmts-scale  |   4 +
 tests/ref/fate/filter-pixfmts-transpose  |   4 +
 tests/ref/fate/filter-pixfmts-vflip  |   4 +
 tests/ref/fate/sws-floatimg-cmp  |  16 +++
 23 files changed, 411 insertions(+), 4 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le

--
2.31.1.windows.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/libaribb24: add default_profile option

2022-11-02 Thread rcombs
This allows decoding of streams that don't have a profile tagged
(e.g. ones that were remuxed improperly).
---
 libavcodec/libaribb24.c | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c
index f40517e22e..8ccf3c4b5d 100644
--- a/libavcodec/libaribb24.c
+++ b/libavcodec/libaribb24.c
@@ -40,10 +40,18 @@ typedef struct Libaribb24Context {
 
 char*aribb24_base_path;
 unsigned int aribb24_skip_ruby;
+
+int default_profile;
 } Libaribb24Context;
 
-static unsigned int get_profile_font_size(int profile)
+static unsigned int get_profile_font_size(AVCodecContext *avctx)
 {
+Libaribb24Context *b24 = avctx->priv_data;
+int profile = avctx->profile;
+
+if (profile == FF_PROFILE_UNKNOWN)
+profile = b24->default_profile;
+
 switch (profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
 return 36;
@@ -61,26 +69,31 @@ static void libaribb24_log(void *p, const char *msg)
 
 static int libaribb24_generate_ass_header(AVCodecContext *avctx)
 {
+Libaribb24Context *b24 = avctx->priv_data;
 unsigned int plane_width = 0;
 unsigned int plane_height = 0;
 unsigned int font_size = 0;
+int profile = avctx->profile;
 
-switch (avctx->profile) {
+if (profile == FF_PROFILE_UNKNOWN)
+profile = b24->default_profile;
+
+switch (profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
 plane_width = 960;
 plane_height = 540;
-font_size = get_profile_font_size(avctx->profile);
 break;
 case FF_PROFILE_ARIB_PROFILE_C:
 plane_width = 320;
 plane_height = 180;
-font_size = get_profile_font_size(avctx->profile);
 break;
 default:
 av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n");
 return AVERROR(EINVAL);
 }
 
+font_size = get_profile_font_size(avctx);
+
 avctx->subtitle_header = av_asprintf(
  "[Script Info]\r\n"
  "; Script generated by FFmpeg/Lavc%s\r\n"
@@ -135,6 +148,7 @@ static int libaribb24_init(AVCodecContext *avctx)
 Libaribb24Context *b24 = avctx->priv_data;
 void(* arib_dec_init)(arib_decoder_t* decoder) = NULL;
 int ret_code = AVERROR_EXTERNAL;
+int profile = avctx->profile;
 
 if (!(b24->lib_instance = arib_instance_new(avctx))) {
 av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n");
@@ -158,7 +172,10 @@ static int libaribb24_init(AVCodecContext *avctx)
 goto init_fail;
 }
 
-switch (avctx->profile) {
+if (profile == FF_PROFILE_UNKNOWN)
+profile = b24->default_profile;
+
+switch (profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
 arib_dec_init = arib_initialize_decoder_a_profile;
 break;
@@ -209,7 +226,7 @@ static int libaribb24_handle_regions(AVCodecContext *avctx, 
AVSubtitle *sub)
 {
 Libaribb24Context *b24 = avctx->priv_data;
 const arib_buf_region_t *region = arib_decoder_get_regions(b24->decoder);
-unsigned int profile_font_size = get_profile_font_size(avctx->profile);
+unsigned int profile_font_size = get_profile_font_size(avctx);
 AVBPrint buf = { 0 };
 int ret = 0;
 
@@ -371,6 +388,10 @@ static const AVOption options[] = {
   OFFSET(aribb24_base_path), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SD 
},
 { "aribb24-skip-ruby-text", "skip ruby text blocks during decoding",
   OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD },
+{ "default_profile", "default profile to use if not specified in the 
stream parameters",
+  OFFSET(default_profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, 
FF_PROFILE_UNKNOWN, FF_PROFILE_ARIB_PROFILE_C, SD, "profile" },
+{"a", "Profile A", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_PROFILE_ARIB_PROFILE_A}, INT_MIN, INT_MAX, SD, "profile"},
+{"c", "Profile C", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_PROFILE_ARIB_PROFILE_C}, INT_MIN, INT_MAX, SD, "profile"},
 { NULL }
 };
 
-- 
2.38.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 24/24] avcodec/motion_est: Remove unused field

2022-11-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/motion_est.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index b20cda..f6a563b08c 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -52,7 +52,6 @@ typedef struct MotionEstContext {
 uint8_t *scratchpad;/**< data area for the ME algo, so that
  * the ME does not need to malloc/free. */
 uint8_t *temp;
-int best_bits;
 uint32_t *map;  ///< map to avoid duplicate evaluations
 uint32_t *score_map;///< map to store the scores
 unsigned map_generation;
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 23/24] avcodec/mpegvideo_enc: Move initializing QpelDSPCtx to mpeg4videoenc.c

2022-11-02 Thread Andreas Rheinhardt
It is the only encoder supporting quarter samples.
This also allows to remove the qpeldsp dependency from
mpegvideo_enc.

Signed-off-by: Andreas Rheinhardt 
---
 configure  | 4 ++--
 libavcodec/mpeg4videoenc.c | 1 +
 libavcodec/mpegvideo_enc.c | 1 -
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index a59e9a898d..1127f49a62 100755
--- a/configure
+++ b/configure
@@ -2756,7 +2756,7 @@ mpegaudio_select="mpegaudiodsp mpegaudioheader"
 mpegaudiodsp_select="dct"
 mpegvideo_select="blockdsp hpeldsp idctdsp videodsp"
 mpegvideodec_select="h264chroma mpegvideo mpeg_er"
-mpegvideoenc_select="aandcttables fdctdsp me_cmp mpegvideo pixblockdsp qpeldsp"
+mpegvideoenc_select="aandcttables fdctdsp me_cmp mpegvideo pixblockdsp"
 msmpeg4dec_select="h263_decoder"
 msmpeg4enc_select="h263_encoder"
 vc1dsp_select="h264chroma qpeldsp startcode"
@@ -2903,7 +2903,7 @@ mpeg1video_encoder_select="mpegvideoenc"
 mpeg2video_decoder_select="mpegvideodec"
 mpeg2video_encoder_select="mpegvideoenc"
 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
-mpeg4_encoder_select="h263_encoder"
+mpeg4_encoder_select="h263_encoder qpeldsp"
 msa1_decoder_select="mss34dsp"
 mscc_decoder_select="inflate_wrapper"
 msmpeg4v1_decoder_select="msmpeg4dec"
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 77f960a262..a2a14afbd0 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1287,6 +1287,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
+ff_qpeldsp_init(&s->qdsp);
 if ((ret = ff_mpv_encode_init(avctx)) < 0)
 return ret;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1bcc849782..9b11c5c05a 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -807,7 +807,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 ff_me_cmp_init(&s->mecc, avctx);
 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
 ff_pixblockdsp_init(&s->pdsp, avctx);
-ff_qpeldsp_init(&s->qdsp);
 
 if (!(avctx->stats_out = av_mallocz(256))   ||
 !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix,  32) ||
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 22/24] avcodec/h263dec: Move initializing qpel DSP context to mpeg4videodec.c

2022-11-02 Thread Andreas Rheinhardt
The MPEG-4 decoder is the only decoder based upon H.263 that
supports quarterpel motion vectors.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h263dec.c   | 2 --
 libavcodec/mpeg4videodec.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index da3c9899e3..71b846ba74 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -51,7 +51,6 @@
 #include "mpegvideo.h"
 #include "mpegvideodec.h"
 #include "msmpeg4dec.h"
-#include "qpeldsp.h"
 #include "thread.h"
 #include "wmv2dec.h"
 
@@ -140,7 +139,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
 }
 
 ff_h263dsp_init(&s->h263dsp);
-ff_qpeldsp_init(&s->qdsp);
 ff_h263_decode_init_vlc();
 
 return 0;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 4ab558b46f..f91d2753f9 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -43,6 +43,7 @@
 #include "h263data.h"
 #include "h263dec.h"
 #include "profiles.h"
+#include "qpeldsp.h"
 #include "threadframe.h"
 #include "xvididct.h"
 #include "unary.h"
@@ -3824,6 +3825,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
 
+ff_qpeldsp_init(&s->qdsp);
 ff_mpeg4videodsp_init(&ctx->mdsp);
 
 ff_thread_once(&init_static_once, mpeg4_init_static);
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 21/24] avcodec/vc1dec: Remove VC-1 decoders->H.263 decoder dependency

2022-11-02 Thread Andreas Rheinhardt
The only thing from the H.263 decoder that is reachable
by the VC-1 decoder is ff_h263_decode_init(); but it does
not even use all of it; e.g. h263dsp is unused and so are
the VLCs initialized in ff_h263_decode_init() (they amount
to about 77KB which are now no longer touched).

Notice that one could also call ff_idctdsp_init()
directly instead of ff_mpv_idct_init(); one could even
do so in ff_vc1_init_common().

Signed-off-by: Andreas Rheinhardt 
---
 configure|  2 +-
 libavcodec/h263dec.c | 12 
 libavcodec/vc1dec.c  | 32 ++--
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/configure b/configure
index 0822498efe..a59e9a898d 100755
--- a/configure
+++ b/configure
@@ -2981,7 +2981,7 @@ utvideo_encoder_select="bswapdsp huffman llvidencdsp"
 vble_decoder_select="llviddsp"
 vbn_decoder_select="texturedsp"
 vbn_encoder_select="texturedspenc"
-vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideodec vc1dsp"
+vc1_decoder_select="blockdsp h264qpel intrax8 mpegvideodec qpeldsp vc1dsp"
 vc1image_decoder_select="vc1_decoder"
 vorbis_decoder_select="mdct"
 vorbis_encoder_select="audio_frame_queue mdct"
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 5f5ecfdddc..da3c9899e3 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -63,9 +63,6 @@ static enum AVPixelFormat h263_get_format(AVCodecContext 
*avctx)
 return avctx->pix_fmt;
 }
 
-if (avctx->codec->id == AV_CODEC_ID_MSS2)
-return AV_PIX_FMT_YUV420P;
-
 if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
 if (avctx->color_range == AVCOL_RANGE_UNSPECIFIED)
 avctx->color_range = AVCOL_RANGE_MPEG;
@@ -117,15 +114,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
 s->h263_pred   = 1;
 s->msmpeg4_version = 5;
 break;
-case AV_CODEC_ID_VC1:
-case AV_CODEC_ID_WMV3:
-case AV_CODEC_ID_VC1IMAGE:
-case AV_CODEC_ID_WMV3IMAGE:
-case AV_CODEC_ID_MSS2:
-s->h263_pred   = 1;
-s->msmpeg4_version = 6;
-avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
-break;
 case AV_CODEC_ID_H263I:
 break;
 case AV_CODEC_ID_FLV1:
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index e7ad540d84..5cb4c544c9 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -405,6 +405,20 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context 
*v)
 return 0;
 }
 
+static enum AVPixelFormat vc1_get_format(AVCodecContext *avctx)
+{
+if (avctx->codec_id == AV_CODEC_ID_MSS2)
+return AV_PIX_FMT_YUV420P;
+
+if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
+if (avctx->color_range == AVCOL_RANGE_UNSPECIFIED)
+avctx->color_range = AVCOL_RANGE_MPEG;
+return AV_PIX_FMT_GRAY8;
+}
+
+return ff_get_format(avctx, avctx->codec->pix_fmts);
+}
+
 av_cold int ff_vc1_decode_init(AVCodecContext *avctx)
 {
 VC1Context *const v = avctx->priv_data;
@@ -415,7 +429,12 @@ av_cold int ff_vc1_decode_init(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 
-ret = ff_h263_decode_init(avctx);
+ff_mpv_decode_init(s, avctx);
+ff_mpv_idct_init(s);
+
+avctx->pix_fmt = vc1_get_format(avctx);
+
+ret = ff_mpv_common_init(s);
 if (ret < 0)
 return ret;
 
@@ -578,13 +597,23 @@ static av_cold void vc1_init_static(void)
 av_cold void ff_vc1_init_common(VC1Context *v)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
+MpegEncContext *const s = &v->s;
 
 /* defaults */
 v->pq  = -1;
 v->mvrange = 0; /* 7.1.1.18, p80 */
 
+s->avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
+s->out_format  = FMT_H263;
+
+s->h263_pred   = 1;
+s->msmpeg4_version = 6;
+
 ff_vc1dsp_init(&v->vc1dsp);
 
+/* For error resilience */
+ff_qpeldsp_init(&s->qdsp);
+
 /* VLC tables */
 ff_thread_once(&init_static_once, vc1_init_static);
 }
@@ -702,7 +731,6 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx)
 
 ff_blockdsp_init(&s->bdsp);
 ff_h264chroma_init(&v->h264chroma, 8);
-ff_qpeldsp_init(&s->qdsp);
 
 avctx->has_b_frames = !!avctx->max_b_frames;
 
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 20/24] avcodec/mpegvideo_dec: Don't use MotionEstContext as scratch space

2022-11-02 Thread Andreas Rheinhardt
Decoders that might use quarter pixel motion estimation
(namely MPEG-4 as well as the VC-1 family) currently
use MpegEncContext.me.qpel_(put|avg) as scratch space
for pointers to arrays of function pointers.
(MotionEstContext contains such pointers as it supports
quarter pixel motion estimation.) The MotionEstContext
is unused apart from this for the decoding part of
mpegvideo.

Using the context at all is for decoding is actually
unnecessary and easily avoided: All codecs with
quarter pixels set me.qpel_avg to qdsp.avg_qpel_pixels_tab,
so one can just unconditionally use this in ff_mpv_reconstruct_mb().
MPEG-4 sets qpel_put to qdsp.put_qpel_pixels_tab
or to qdsp.put_no_rnd_qpel_pixels_tab based upon
whether the current frame is a b-frame with no_rounding
or not, while the VC-1-based decoders set it to
qdsp.put_qpel_pixels_tab unconditionally. Given
that no_rounding is always zero for VC-1, using
the same check for VC-1 as well as for MPEG-4 would work.
Since ff_mpv_reconstruct_mb() already has exactly
the right check (for hpeldsp), it can simply be reused.

(This change will result in ff_mpv_motion() receiving
a pointer to an array of NULL function pointers instead
of a NULL pointer for codecs without qpeldsp (like MPEG-1/2).
It doesn't matter.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h263dec.c | 8 
 libavcodec/mpv_reconstruct_mb_template.c | 6 --
 libavcodec/mss2.c| 4 
 libavcodec/vc1dec.c  | 3 ---
 4 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 90dd32bd3a..5f5ecfdddc 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -597,14 +597,6 @@ retry:
 avctx->skip_frame >= AVDISCARD_ALL)
 return get_consumed_bytes(s, buf_size);
 
-if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
-s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
-s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
-} else {
-s->me.qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab;
-s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
-}
-
 if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
 return ret;
 
diff --git a/libavcodec/mpv_reconstruct_mb_template.c 
b/libavcodec/mpv_reconstruct_mb_template.c
index 5023fe58ae..6f7a5fb1b4 100644
--- a/libavcodec/mpv_reconstruct_mb_template.c
+++ b/libavcodec/mpv_reconstruct_mb_template.c
@@ -145,17 +145,19 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, 
int16_t block[12][64],
 }
 } else {
 op_pixels_func (*op_pix)[4];
-qpel_mc_func (*op_qpix)[16] = s->me.qpel_put;
+qpel_mc_func (*op_qpix)[16];
 
 if ((is_mpeg12 == DEFINITELY_MPEG12 || !s->no_rounding) || 
s->pict_type == AV_PICTURE_TYPE_B) {
 op_pix = s->hdsp.put_pixels_tab;
+op_qpix = s->qdsp.put_qpel_pixels_tab;
 } else {
 op_pix = s->hdsp.put_no_rnd_pixels_tab;
+op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab;
 }
 if (s->mv_dir & MV_DIR_FORWARD) {
 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, 
s->last_picture.f->data, op_pix, op_qpix);
 op_pix  = s->hdsp.avg_pixels_tab;
-op_qpix = s->me.qpel_avg;
+op_qpix = s->qdsp.avg_qpel_pixels_tab;
 }
 if (s->mv_dir & MV_DIR_BACKWARD) {
 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, 
s->next_picture.f->data, op_pix, op_qpix);
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 2469718c8f..1d1ed11f54 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -855,10 +855,6 @@ static av_cold int wmv9_init(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 
-/* error concealment */
-v->s.me.qpel_put = v->s.qdsp.put_qpel_pixels_tab;
-v->s.me.qpel_avg = v->s.qdsp.avg_qpel_pixels_tab;
-
 return 0;
 }
 
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index bcfd2bae0b..e7ad540d84 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1060,9 +1060,6 @@ static int vc1_decode_frame(AVCodecContext *avctx, 
AVFrame *pict,
 s->current_picture_ptr->f->repeat_pict = v->rptfrm * 2;
 }
 
-s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
-s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
-
 if (avctx->hwaccel) {
 s->mb_y = 0;
 if (v->field_mode && buf_start_second_field) {
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3] avcodec/av1_vaapi: fixed a decoding corruption issue

2022-11-02 Thread Wang, Fei W
On Wed, 2022-11-02 at 15:35 -0400, Ruijing Dong wrote:
> In av1_spec.pdf page 38/669, there is a sentence below:
> 
> if ( frame_type == KEY_FRAME && show_frame ) {
>for ( i = 0; i < NUM_REF_FRAMES; i++) {
>   RefValid[ i ] = 0
>   ..
>}
>..
> }
> 
> This shows that the condition of invalidating current
> DPB frames should be the coming frame_type is KEY_FRAME plus
> show_frame is equal to 1. Otherwise, some of the frames
> in sequence after KEY_FRAME still refer to the reference frames
> before KEY_FRAME, and if these before KEY_FRAME reference
> frames were invalidated, these frames could not find their
> reference frames, and it could cause image corruption.
> 
> Mesa fix is in 
> https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19386
> 
> Signed-off-by: Ruijing Dong 
> ---
> update: re-organize commit message and title
> 
>  libavcodec/vaapi_av1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 63374c31c9..d0339b2705 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -274,7 +274,7 @@ static int vaapi_av1_start_frame(AVCodecContext
> *avctx,
>  };
> 
>  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
> -if (pic_param.pic_info_fields.bits.frame_type ==
> AV1_FRAME_KEY)
> +if (pic_param.pic_info_fields.bits.frame_type ==
> AV1_FRAME_KEY && frame_header->show_frame)

LGTM, Thanks.

Fei

>  pic_param.ref_frame_map[i] = VA_INVALID_ID;
>  else
>  pic_param.ref_frame_map[i] = ctx->ref_tab[i].valid ?
> --
> 2.25.1
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32

2022-11-02 Thread Mark Reid
On Wed, Nov 2, 2022 at 3:52 PM Mark Reid  wrote:

>
>
> On Wed, Nov 2, 2022 at 2:03 PM Michael Niedermayer 
> wrote:
>
>> Fixes: integer overflow
>> Signed-off-by: Michael Niedermayer 
>> ---
>>  libswscale/output.c   | 25 +++--
>>  libswscale/x86/output.asm | 16 +++-
>>  2 files changed, 26 insertions(+), 15 deletions(-)
>>
>> diff --git a/libswscale/output.c b/libswscale/output.c
>> index df4647adde..5c85bff971 100644
>> --- a/libswscale/output.c
>> +++ b/libswscale/output.c
>> @@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t
>> *lumFilter,
>>
>>  Y -= c->yuv2rgb_y_offset;
>>  Y *= c->yuv2rgb_y_coeff;
>> -Y += 1 << 13;
>> +Y += (1 << 13) - (1 << 29);
>>  R = V * c->yuv2rgb_v2r_coeff;
>>  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>>  B =U * c->yuv2rgb_u2b_coeff;
>>
>> -R = av_clip_uintp2(Y + R, 30);
>> -G = av_clip_uintp2(Y + G, 30);
>> -B = av_clip_uintp2(Y + B, 30);
>> +dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
>> +dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
>> +dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>>
>> -dest16[0][i] = G >> 14;
>> -dest16[1][i] = B >> 14;
>> -dest16[2][i] = R >> 14;
>>  if (hasAlpha)
>>  dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
>>  }
>> @@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
>> *lumFilter,
>>
>>  Y -= c->yuv2rgb_y_offset;
>>  Y *= c->yuv2rgb_y_coeff;
>> -Y += 1 << 13;
>> +Y += (1 << 13) - (1 << 29);
>>  R = V * c->yuv2rgb_v2r_coeff;
>>  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>>  B =U * c->yuv2rgb_u2b_coeff;
>>
>> -R = av_clip_uintp2(Y + R, 30);
>> -G = av_clip_uintp2(Y + G, 30);
>> -B = av_clip_uintp2(Y + B, 30);
>> +R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
>> +G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
>> +B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>>
>> -dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
>> -dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
>> -dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
>> +dest32[0][i] = av_float2int(float_mult * (float)G);
>> +dest32[1][i] = av_float2int(float_mult * (float)B);
>> +dest32[2][i] = av_float2int(float_mult * (float)R);
>>  if (hasAlpha)
>>  dest32[3][i] = av_float2int(float_mult *
>> (float)(av_clip_uintp2(A, 30) >> 14));
>>  }
>> diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm
>> index 84e94baaf6..f943a27534 100644
>> --- a/libswscale/x86/output.asm
>> +++ b/libswscale/x86/output.asm
>> @@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start:   times 8 dd  (1 << 9)
>>  pd_yuv2gbrp_uv_start:  times 8 dd  ((1 << 9) - (128 << 19))
>>  pd_yuv2gbrp_a_start:   times 8 dd  (1 << 18)
>>  pd_yuv2gbrp16_offset:  times 8 dd  0x1  ;(1 << 16)
>> -pd_yuv2gbrp16_round13: times 8 dd  0x02000  ;(1 << 13)
>> +pd_yuv2gbrp16_round13: times 8 dd  0xE0002000  ;(1 << 13) - (1 << 29)
>>  pd_yuv2gbrp16_a_offset:times 8 dd  0x20002000
>>  pd_yuv2gbrp16_upper30: times 8 dd  0x3FFF ;(1<<30) - 1
>>  pd_yuv2gbrp16_upper27: times 8 dd  0x07FF ;(1<<27) - 1
>> +pd_yuv2gbrp16_upper16: times 8 dd  0x ;(1<<16) - 1
>>
>
> pd_yuv2gbrp16_upper16 doesn't appear to be used anywhere
>

nevermind, I see where it is used now.


>
>
>>  pd_yuv2gbrp16_upperC:  times 8 dd  0xC000
>> +pd_yuv2gbrp_debias:times 8 dd  0x8000 ;(1 << 29 - 14)
>>  pb_pack_shuffle8:   db  0,  4,  8, 12, \
>> -1, -1, -1, -1, \
>> -1, -1, -1, -1, \
>> @@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter,
>> lumSrcx, lumFilterSize, chrFi
>>  paddd G, Y
>>  paddd B, Y
>>
>> +%if  DEPTH < 16
>>  CLIPP2 R, 30
>>  CLIPP2 G, 30
>>  CLIPP2 B, 30
>> +%endif
>>
>>  psrad R, RGB_SHIFT
>>  psrad G, RGB_SHIFT
>>  psrad B, RGB_SHIFT
>>
>> +%if  DEPTH >= 16
>> +paddd R, [pd_yuv2gbrp_debias]
>> +paddd G, [pd_yuv2gbrp_debias]
>> +paddd B, [pd_yuv2gbrp_debias]
>> +
>> +CLIPP2 R, 16
>> +CLIPP2 G, 16
>> +CLIPP2 B, 16
>> +%endif
>> +
>>  %if FLOAT
>>  cvtdq2ps R, R
>>  cvtdq2ps G, G
>> --
>> 2.17.1
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>
__

Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32

2022-11-02 Thread Mark Reid
On Wed, Nov 2, 2022 at 2:03 PM Michael Niedermayer 
wrote:

> Fixes: integer overflow
> Signed-off-by: Michael Niedermayer 
> ---
>  libswscale/output.c   | 25 +++--
>  libswscale/x86/output.asm | 16 +++-
>  2 files changed, 26 insertions(+), 15 deletions(-)
>
> diff --git a/libswscale/output.c b/libswscale/output.c
> index df4647adde..5c85bff971 100644
> --- a/libswscale/output.c
> +++ b/libswscale/output.c
> @@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
>
>  Y -= c->yuv2rgb_y_offset;
>  Y *= c->yuv2rgb_y_coeff;
> -Y += 1 << 13;
> +Y += (1 << 13) - (1 << 29);
>  R = V * c->yuv2rgb_v2r_coeff;
>  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>  B =U * c->yuv2rgb_u2b_coeff;
>
> -R = av_clip_uintp2(Y + R, 30);
> -G = av_clip_uintp2(Y + G, 30);
> -B = av_clip_uintp2(Y + B, 30);
> +dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> +dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> +dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>
> -dest16[0][i] = G >> 14;
> -dest16[1][i] = B >> 14;
> -dest16[2][i] = R >> 14;
>  if (hasAlpha)
>  dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
>  }
> @@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
>
>  Y -= c->yuv2rgb_y_offset;
>  Y *= c->yuv2rgb_y_coeff;
> -Y += 1 << 13;
> +Y += (1 << 13) - (1 << 29);
>  R = V * c->yuv2rgb_v2r_coeff;
>  G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>  B =U * c->yuv2rgb_u2b_coeff;
>
> -R = av_clip_uintp2(Y + R, 30);
> -G = av_clip_uintp2(Y + G, 30);
> -B = av_clip_uintp2(Y + B, 30);
> +R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16);
> +G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16);
> +B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16);
>
> -dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
> -dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
> -dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
> +dest32[0][i] = av_float2int(float_mult * (float)G);
> +dest32[1][i] = av_float2int(float_mult * (float)B);
> +dest32[2][i] = av_float2int(float_mult * (float)R);
>  if (hasAlpha)
>  dest32[3][i] = av_float2int(float_mult *
> (float)(av_clip_uintp2(A, 30) >> 14));
>  }
> diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm
> index 84e94baaf6..f943a27534 100644
> --- a/libswscale/x86/output.asm
> +++ b/libswscale/x86/output.asm
> @@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start:   times 8 dd  (1 << 9)
>  pd_yuv2gbrp_uv_start:  times 8 dd  ((1 << 9) - (128 << 19))
>  pd_yuv2gbrp_a_start:   times 8 dd  (1 << 18)
>  pd_yuv2gbrp16_offset:  times 8 dd  0x1  ;(1 << 16)
> -pd_yuv2gbrp16_round13: times 8 dd  0x02000  ;(1 << 13)
> +pd_yuv2gbrp16_round13: times 8 dd  0xE0002000  ;(1 << 13) - (1 << 29)
>  pd_yuv2gbrp16_a_offset:times 8 dd  0x20002000
>  pd_yuv2gbrp16_upper30: times 8 dd  0x3FFF ;(1<<30) - 1
>  pd_yuv2gbrp16_upper27: times 8 dd  0x07FF ;(1<<27) - 1
> +pd_yuv2gbrp16_upper16: times 8 dd  0x ;(1<<16) - 1
>

pd_yuv2gbrp16_upper16 doesn't appear to be used anywhere


>  pd_yuv2gbrp16_upperC:  times 8 dd  0xC000
> +pd_yuv2gbrp_debias:times 8 dd  0x8000 ;(1 << 29 - 14)
>  pb_pack_shuffle8:   db  0,  4,  8, 12, \
> -1, -1, -1, -1, \
> -1, -1, -1, -1, \
> @@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter,
> lumSrcx, lumFilterSize, chrFi
>  paddd G, Y
>  paddd B, Y
>
> +%if  DEPTH < 16
>  CLIPP2 R, 30
>  CLIPP2 G, 30
>  CLIPP2 B, 30
> +%endif
>
>  psrad R, RGB_SHIFT
>  psrad G, RGB_SHIFT
>  psrad B, RGB_SHIFT
>
> +%if  DEPTH >= 16
> +paddd R, [pd_yuv2gbrp_debias]
> +paddd G, [pd_yuv2gbrp_debias]
> +paddd B, [pd_yuv2gbrp_debias]
> +
> +CLIPP2 R, 16
> +CLIPP2 G, 16
> +CLIPP2 B, 16
> +%endif
> +
>  %if FLOAT
>  cvtdq2ps R, R
>  cvtdq2ps G, G
> --
> 2.17.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/vpp_qsv: Copy side data from input to output frame

2022-11-02 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> "zhilizhao(???)"
> Sent: Tuesday, November 1, 2022 10:18 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] avcodec/vpp_qsv: Copy side
> data from input to output frame
> 
> 
> 
> > On Nov 1, 2022, at 12:58, Xiang, Haihao  intel@ffmpeg.org> wrote:
> >
> > On Mon, 2022-10-24 at 23:04 +, softworkz wrote:
> >> From: softworkz 
> >>
> >> Signed-off-by: softworkz 
> >> ---
> >> libavfilter/qsvvpp.c |  6 ++
> >> libavfilter/vf_overlay_qsv.c | 19 +++
> >> 2 files changed, 21 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> >> index 8428ee89ab..ae9766d12f 100644
> >> --- a/libavfilter/qsvvpp.c
> >> +++ b/libavfilter/qsvvpp.c
> >> @@ -880,6 +880,12 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> AVFilterLink
> >> *inlink, AVFrame *picr
> >> return AVERROR(EAGAIN);
> >> break;
> >> }
> >> +
> >> +av_frame_remove_all_side_data(out_frame->frame);
> >> +ret = av_frame_copy_side_data(out_frame->frame, in_frame-
> >frame, 0);
> >> +if (ret < 0)
> >> +return ret;
> >> +
> >> out_frame->frame->pts = av_rescale_q(out_frame-
> >>> surface.Data.TimeStamp,
> >>  default_tb, outlink-
> >time_base);
> >>
> >> diff --git a/libavfilter/vf_overlay_qsv.c
> b/libavfilter/vf_overlay_qsv.c
> >> index d947a1faa1..04fd284b92 100644
> >> --- a/libavfilter/vf_overlay_qsv.c
> >> +++ b/libavfilter/vf_overlay_qsv.c
> >> @@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
> >> {
> >> AVFilterContext  *ctx = fs->parent;
> >> QSVOverlayContext  *s = fs->opaque;
> >> +AVFrame   *frame0 = NULL;
> >> AVFrame*frame = NULL;
> >> -int   ret = 0, i;
> >> +int   ret = 0;
> >>
> >> -for (i = 0; i < ctx->nb_inputs; i++) {
> >> +for (unsigned i = 0; i < ctx->nb_inputs; i++) {
> >> ret = ff_framesync_get_frame(fs, i, &frame, 0);
> >> -if (ret == 0)
> >> -ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i],
> frame);
> >> +
> >> +if (ret == 0) {
> >> +if (i == 0)
> >> +frame0 = frame;
> >> +else {
> >> +av_frame_remove_all_side_data(frame);
> >> +ret = av_frame_copy_side_data(frame, frame0, 0);
> >> +}
> >> +
> >> +ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv,
> ctx-
> >>> inputs[i], frame);
> >> +}
> >> +
> >> if (ret < 0 && ret != AVERROR(EAGAIN))
> >> break;
> >> }
> >
> > Patchset LGTM, I'll push this patchset if no more comment or
> objection.
> 
> avcodec/vpp_qsv: Copy side data from input to output frame
> ^^^
> 
> avcodec -> avfilter
> 

Good catch!

Thank you,
sw
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 4/4] swscale/output: add rgbaf32 output support

2022-11-02 Thread Mark Reid
On Wed, Nov 2, 2022 at 2:04 PM Michael Niedermayer 
wrote:

> On Sun, Oct 30, 2022 at 05:32:35PM -0700, mindm...@gmail.com wrote:
> > From: Mark Reid 
> >
> > ---
> >  libswscale/output.c  | 92 
> >  libswscale/swscale_unscaled.c|  4 +-
> >  libswscale/tests/floatimg_cmp.c  |  4 +-
> >  libswscale/utils.c   | 16 +++--
> >  libswscale/yuv2rgb.c |  2 +
> >  tests/ref/fate/filter-pixdesc-rgbaf32be  |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbaf32le  |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbf32be   |  1 +
> >  tests/ref/fate/filter-pixdesc-rgbf32le   |  1 +
> >  tests/ref/fate/filter-pixfmts-copy   |  4 ++
> >  tests/ref/fate/filter-pixfmts-crop   |  4 ++
> >  tests/ref/fate/filter-pixfmts-field  |  4 ++
> >  tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
> >  tests/ref/fate/filter-pixfmts-hflip  |  4 ++
> >  tests/ref/fate/filter-pixfmts-il |  4 ++
> >  tests/ref/fate/filter-pixfmts-null   |  4 ++
> >  tests/ref/fate/filter-pixfmts-scale  |  4 ++
> >  tests/ref/fate/filter-pixfmts-transpose  |  4 ++
> >  tests/ref/fate/filter-pixfmts-vflip  |  4 ++
> >  tests/ref/fate/sws-floatimg-cmp  | 16 +
> >  20 files changed, 170 insertions(+), 8 deletions(-)
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32be
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbaf32le
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32be
> >  create mode 100644 tests/ref/fate/filter-pixdesc-rgbf32le
> >
> > diff --git a/libswscale/output.c b/libswscale/output.c
> > index 0e1c1225a0..e2ec9cbdf5 100644
> > --- a/libswscale/output.c
> > +++ b/libswscale/output.c
> > @@ -2474,6 +2474,92 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t
> *lumFilter,
> >  }
> >  }
> >
> > +static void
> > +yuv2rgbaf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
> > +const int16_t **lumSrcx, int lumFilterSize,
> > +const int16_t *chrFilter, const int16_t **chrUSrcx,
> > +const int16_t **chrVSrcx, int chrFilterSize,
> > +const int16_t **alpSrcx, uint8_t *dest,
> > +int dstW, int y)
> > +{
> > +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
> > +int i;
> > +int alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
> > +int hasAlpha = alpha && alpSrcx;
> > +int pixelStep = alpha ? 4 : 3;
> > +uint32_t *dest32 = (uint32_t*)dest;
> > +const int32_t **lumSrc  = (const int32_t**)lumSrcx;
> > +const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
> > +const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
> > +const int32_t **alpSrc  = (const int32_t**)alpSrcx;
> > +static const float float_mult = 1.0f / 65535.0f;
> > +uint32_t a = av_float2int(1.0f);
> > +
> > +for (i = 0; i < dstW; i++) {
> > +int j;
> > +int Y = -0x4000;
> > +int U = -(128 << 23);
> > +int V = -(128 << 23);
> > +int R, G, B, A;
> > +
> > +for (j = 0; j < lumFilterSize; j++)
> > +Y += lumSrc[j][i] * (unsigned)lumFilter[j];
> > +
> > +for (j = 0; j < chrFilterSize; j++) {
> > +U += chrUSrc[j][i] * (unsigned)chrFilter[j];
> > +V += chrVSrc[j][i] * (unsigned)chrFilter[j];
> > +}
> > +
> > +Y >>= 14;
> > +Y += 0x1;
> > +U >>= 14;
> > +V >>= 14;
> > +
> > +if (hasAlpha) {
> > +A = -0x4000;
> > +
> > +for (j = 0; j < lumFilterSize; j++)
> > +A += alpSrc[j][i] * (unsigned)lumFilter[j];
> > +
> > +A >>= 1;
> > +A += 0x20002000;
> > +a = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30)
> >> 14));
> > +}
> > +
> > +Y -= c->yuv2rgb_y_offset;
> > +Y *= c->yuv2rgb_y_coeff;
> > +Y += 1 << 13;
> > +R = V * c->yuv2rgb_v2r_coeff;
> > +G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
> > +B =U * c->yuv2rgb_u2b_coeff;
> > +
>
> > +R = av_clip_uintp2(Y + R, 30);
> > +G = av_clip_uintp2(Y + G, 30);
> > +B = av_clip_uintp2(Y + B, 30);
>
> these additions can overflow i think given sufficiently "bad" input
> especially with the bt2020 matrix
> ive posted a proposed solution for the rgba64 / gbrp16/32f cases
> something similar can be done here
>
> thx
>
>
Make sense. I'll take a look and submit a new version with the fix.
I also have some yuv to float16 patches coming that I will incorporate the
fix into too!


> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Opposition brings concord. Out of discord comes the fairest harmony.
> -- Heraclitus
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/f

Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32

2022-11-02 Thread Martin Storsjö

On Wed, 2 Nov 2022, Michael Niedermayer wrote:


On Wed, Nov 02, 2022 at 10:16:57PM +0100, Andreas Rheinhardt wrote:

Michael Niedermayer:

On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:

Fixes: integer overflow
Signed-off-by: Michael Niedermayer 
---
 libswscale/output.c   | 25 +++--
 libswscale/x86/output.asm | 16 +++-
 2 files changed, 26 insertions(+), 15 deletions(-)


Note, these corner case overflows could affect some of the similary
implemented cases that are not depth 16 too

ill fix them if issues are replicated



The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
touched in your commits.


checkasm-sw_gbrp feeds random data widely outside sane ranges in.
the test certainly makes no sense for testing asm. There is no point
in matching C for widely invalid cases. Of cousre we shouldnt overflow
if any of this can be triggered with valid and real input (which probably
can be done in some cases)


Patches for the checkasm tests, to make them produce sane input values in 
the correct ranges, are very much welcome!


// Martin

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32

2022-11-02 Thread Andreas Rheinhardt
Michael Niedermayer:
> On Wed, Nov 02, 2022 at 10:02:39PM +0100, Michael Niedermayer wrote:
>> Fixes: integer overflow
>> Signed-off-by: Michael Niedermayer 
>> ---
>>  libswscale/output.c   | 25 +++--
>>  libswscale/x86/output.asm | 16 +++-
>>  2 files changed, 26 insertions(+), 15 deletions(-)
> 
> Note, these corner case overflows could affect some of the similary
> implemented cases that are not depth 16 too
> 
> ill fix them if issues are replicated
> 

The checkasm-sw_gbrp runs into many overflows (when run under UBSan);
e.g. fate.ffmpeg.org tells me of an issue in line 2289. Said line is not
touched in your commits.

- Andreas

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add backgroundkey video filter

2022-11-02 Thread Andreas Rheinhardt
Paul B Mahol:
> +static int filter_frame(AVFilterLink *link, AVFrame *frame)
> +{
> +AVFilterContext *avctx = link->dst;
> +BackgroundkeyContext *s = avctx->priv;
> +int64_t sum = 0;
> +int ret;
> +
> +if (!s->background) {
> +s->background = av_frame_clone(frame);
> +if (!s->background)
> +return AVERROR(ENOMEM);
> +av_frame_make_writable(s->background);

You are never writing to the background frame, so there is no point in
making it writable; what you actually want to achieve here is making
frame writable again and to achieve this you should make frame, not
background writable (and of course you should check said call).

(Actually, you never

> +}
> +
> +if (ret = ff_filter_execute(avctx, s->do_slice, frame, NULL,
> +FFMIN(frame->height, s->nb_threads)))
> +return ret;
> +
> +for (int n = 0; n < s->nb_threads; n++)
> +sum += s->sums[n];
> +if (s->max_sum * s->threshold < sum) {
> +av_frame_free(&s->background);
> +s->background = av_frame_clone(frame);
> +if (!s->background)
> +return AVERROR(ENOMEM);
> +av_frame_make_writable(s->background);

Given that you never write to background, there is no need to make it
writable. This time, there is also no need to make frame writable (the
next filter in the chain may not need a writable frame anyway), so just
remove this.
And the av_frame_free+av_frame_clone can become an
av_frame_unref+av_frame_ref (this will necessitate modifying the check
above to not only check for to existence of s->background).

> +}
> +
> +return ff_filter_frame(avctx->outputs[0], frame);
> +}

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avcodec/nvenc: add AV1 encoding support

2022-11-02 Thread Timo Rothenpieler
---
 configure  |  14 ++-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/nvenc.c | 137 ++--
 libavcodec/nvenc.h |   9 ++
 libavcodec/nvenc_av1.c | 197 +
 libavcodec/version.h   |   4 +-
 7 files changed, 349 insertions(+), 14 deletions(-)
 create mode 100644 libavcodec/nvenc_av1.c

diff --git a/configure b/configure
index 30f0ce4e26..1b4e256a19 100755
--- a/configure
+++ b/configure
@@ -3184,6 +3184,8 @@ nvenc_deps_any="libdl LoadLibrary"
 aac_mf_encoder_deps="mediafoundation"
 ac3_mf_encoder_deps="mediafoundation"
 av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
+av1_nvenc_encoder_deps="nvenc NV_ENC_PIC_PARAMS_AV1"
+av1_nvenc_encoder_select="atsc_a53"
 h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
 h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
 h264_amf_encoder_deps="amf"
@@ -6466,10 +6468,10 @@ fi
 
 if ! disabled ffnvcodec; then
 ffnv_hdr_list="ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h 
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h"
-check_pkg_config ffnvcodec "ffnvcodec >= 9.1.23.1" "$ffnv_hdr_list" "" || \
-  check_pkg_config ffnvcodec "ffnvcodec >= 9.0.18.3 ffnvcodec < 9.1" 
"$ffnv_hdr_list" "" || \
-  check_pkg_config ffnvcodec "ffnvcodec >= 8.2.15.10 ffnvcodec < 8.3" 
"$ffnv_hdr_list" "" || \
-  check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.11 ffnvcodec < 8.2" 
"$ffnv_hdr_list" ""
+check_pkg_config ffnvcodec "ffnvcodec >= 12.0.11.0" "$ffnv_hdr_list" "" || 
\
+  check_pkg_config ffnvcodec "ffnvcodec >= 11.1.5.2 ffnvcodec < 12.0" 
"$ffnv_hdr_list" "" || \
+  check_pkg_config ffnvcodec "ffnvcodec >= 11.0.10.2 ffnvcodec < 11.1" 
"$ffnv_hdr_list" "" || \
+  check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.14 ffnvcodec < 8.2" 
"$ffnv_hdr_list" ""
 fi
 
 if enabled_all libglslang libshaderc; then
@@ -7049,6 +7051,10 @@ void f(void) { struct { const GUID guid; } s[] = { { 
NV_ENC_PRESET_HQ_GUID } };
 int main(void) { return 0; }
 EOF
 
+if enabled nvenc; then
+check_type "ffnvcodec/nvEncodeAPI.h" "NV_ENC_PIC_PARAMS_AV1"
+fi
+
 if enabled_any nvdec cuvid; then
 check_type "ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h" 
"CUVIDAV1PICPARAMS"
 fi
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 72d2f92901..32318fd7ed 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -244,6 +244,7 @@ OBJS-$(CONFIG_AURA_DECODER)+= cyuv.o
 OBJS-$(CONFIG_AURA2_DECODER)   += aura.o
 OBJS-$(CONFIG_AV1_DECODER) += av1dec.o
 OBJS-$(CONFIG_AV1_CUVID_DECODER)   += cuviddec.o
+OBJS-$(CONFIG_AV1_NVENC_ENCODER)   += nvenc_av1.o nvenc.o
 OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
 OBJS-$(CONFIG_AVRN_DECODER)+= avrndec.o
 OBJS-$(CONFIG_AVRP_DECODER)+= r210dec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4f1d66cb0c..f5ec3bc6e1 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -827,6 +827,7 @@ extern const FFCodec ff_libaom_av1_decoder;
 /* hwaccel hooks only, so prefer external decoders */
 extern const FFCodec ff_av1_decoder;
 extern const FFCodec ff_av1_cuvid_decoder;
+extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
 extern const FFCodec ff_libopenh264_encoder;
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 73c05fcd37..ffa96d4aa1 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1,5 +1,5 @@
 /*
- * H.264/HEVC hardware encoding using nvidia nvenc
+ * H.264/HEVC/AV1 hardware encoding using nvidia nvenc
  * Copyright (c) 2016 Timo Rothenpieler 
  *
  * This file is part of FFmpeg.
@@ -222,8 +222,14 @@ static void nvenc_map_preset(NvencContext *ctx)
 
 static void nvenc_print_driver_requirement(AVCodecContext *avctx, int level)
 {
-#if NVENCAPI_CHECK_VERSION(11, 2)
+#if NVENCAPI_CHECK_VERSION(12, 1)
 const char *minver = "(unknown)";
+#elif NVENCAPI_CHECK_VERSION(12, 0)
+# if defined(_WIN32) || defined(__CYGWIN__)
+const char *minver = "522.25";
+# else
+const char *minver = "520.56.06";
+# endif
 #elif NVENCAPI_CHECK_VERSION(11, 1)
 # if defined(_WIN32) || defined(__CYGWIN__)
 const char *minver = "471.41";
@@ -658,6 +664,11 @@ static av_cold int nvenc_setup_device(AVCodecContext 
*avctx)
 case AV_CODEC_ID_HEVC:
 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_HEVC_GUID;
 break;
+#if CONFIG_AV1_NVENC_ENCODER
+case AV_CODEC_ID_AV1:
+ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_AV1_GUID;
+break;
+#endif
 default:
 return AVERROR_BUG;
 }
@@ -761,6 +772,11 @@ static av_cold void set_constqp(AVCodecContext *avctx)
 {
 NvencContext *ctx = avctx->priv_data;
 NV_ENC_RC_PARAMS *rc = &ctx->encode_config.rcParams;
+#if CONFIG_AV1_NVENC_ENCODER
+int qmax = avctx->codec->id == AV_CODEC_ID_AV1 ? 255 : 51;
+#else
+int qmax = 51;
+#end

[FFmpeg-devel] [PATCH v3] avcodec/av1_vaapi: fixed a decoding corruption issue

2022-11-02 Thread Ruijing Dong
In av1_spec.pdf page 38/669, there is a sentence below:

if ( frame_type == KEY_FRAME && show_frame ) {
   for ( i = 0; i < NUM_REF_FRAMES; i++) {
  RefValid[ i ] = 0
  ..
   }
   ..
}

This shows that the condition of invalidating current
DPB frames should be the coming frame_type is KEY_FRAME plus
show_frame is equal to 1. Otherwise, some of the frames
in sequence after KEY_FRAME still refer to the reference frames
before KEY_FRAME, and if these before KEY_FRAME reference
frames were invalidated, these frames could not find their
reference frames, and it could cause image corruption.

Mesa fix is in https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19386

Signed-off-by: Ruijing Dong 
---
update: re-organize commit message and title

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

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 63374c31c9..d0339b2705 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -274,7 +274,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
 };

 for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
-if (pic_param.pic_info_fields.bits.frame_type == AV1_FRAME_KEY)
+if (pic_param.pic_info_fields.bits.frame_type == AV1_FRAME_KEY && 
frame_header->show_frame)
 pic_param.ref_frame_map[i] = VA_INVALID_ID;
 else
 pic_param.ref_frame_map[i] = ctx->ref_tab[i].valid ?
--
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add backgroundkey video filter

2022-11-02 Thread Paul B Mahol
On 10/30/22, Paul B Mahol  wrote:
> Patch attached.
>

Improved patch attached.
From 6f9873ca81557fa77d7af957dd7694d5cc6e8019 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Fri, 28 Oct 2022 22:02:29 +0200
Subject: [PATCH] avfilter: add backgroundkey video filter

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   |  19 +++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_backgroundkey.c | 251 +
 4 files changed, 272 insertions(+)
 create mode 100644 libavfilter/vf_backgroundkey.c

diff --git a/doc/filters.texi b/doc/filters.texi
index bcd19cf931..6e95c3a908 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7987,6 +7987,25 @@ The command accepts the same syntax of the corresponding option.
 If the specified expression is not valid, it is kept at its current
 value.
 
+@section backgroundkey
+
+Turns a static background into transparency.
+
+The filter accepts the following option:
+
+@table @option
+@item threshold
+Threshold for scene change detection.
+@item similarity
+Similarity percentage with the background.
+@item blend
+Set the blend amount for pixels that are not similar.
+@end table
+
+@subsection Commands
+This filter supports same @ref{commands} as options except option @code{s}.
+The command accepts the same syntax of the corresponding option.
+
 @section bbox
 
 Compute the bounding box for the non-black pixels in the input frame
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 195e616ccc..0e971d5c3e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -192,6 +192,7 @@ OBJS-$(CONFIG_AVGBLUR_FILTER)+= vf_avgblur.o
 OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
 opencl/avgblur.o boxblur.o
 OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o vulkan_filter.o
+OBJS-$(CONFIG_BACKGROUNDKEY_FILTER)  += vf_backgroundkey.o
 OBJS-$(CONFIG_BBOX_FILTER)   += bbox.o vf_bbox.o
 OBJS-$(CONFIG_BENCH_FILTER)  += f_bench.o
 OBJS-$(CONFIG_BILATERAL_FILTER)  += vf_bilateral.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 97225a3679..1e0391f7a4 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -178,6 +178,7 @@ extern const AVFilter ff_vf_atadenoise;
 extern const AVFilter ff_vf_avgblur;
 extern const AVFilter ff_vf_avgblur_opencl;
 extern const AVFilter ff_vf_avgblur_vulkan;
+extern const AVFilter ff_vf_backgroundkey;
 extern const AVFilter ff_vf_bbox;
 extern const AVFilter ff_vf_bench;
 extern const AVFilter ff_vf_bilateral;
diff --git a/libavfilter/vf_backgroundkey.c b/libavfilter/vf_backgroundkey.c
new file mode 100644
index 00..2c2da60b39
--- /dev/null
+++ b/libavfilter/vf_backgroundkey.c
@@ -0,0 +1,251 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct BackgroundkeyContext {
+const AVClass *class;
+
+float threshold;
+float similarity;
+float blend;
+int max;
+
+int nb_threads;
+int hsub_log2;
+int vsub_log2;
+
+int64_t max_sum;
+int64_t *sums;
+
+AVFrame *background;
+
+int (*do_slice)(AVFilterContext *avctx, void *arg,
+int jobnr, int nb_jobs);
+} BackgroundkeyContext;
+
+static int do_backgroundkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
+{
+BackgroundkeyContext *s = avctx->priv;
+AVFrame *frame = arg;
+const int slice_start = (frame->height * jobnr) / nb_jobs;
+const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
+const int min_diff = (255 + 255 + 255) * s->similarity;
+const float blend = s->blend;
+const int hsub = s->hsub_log2;
+const int vsub = s->vsub_log2;
+int64_t sum = 0;
+
+for (int y = slice_start; y < slice_end; y++) {
+const uint8_t *srcy = frame->data[0] + frame->linesize[0] * y;
+const uint8_t *srcu = frame->data[1] + frame->linesize[1] * (y >> vsub);
+cons

[FFmpeg-devel] [PATCH] lavfi/vf_dnn_processing.c: Fix missing AV_PIX_FMT_GRAY8

2022-11-02 Thread Thilo Borgmann
From: Cosmin Stejerean 

Has been removed by mistake in 2003e32f62d94ba75b59d70632c9f2862b383591, readd 
it to the switch cases.

Signed-off-by: Thilo Borgmann 
---
 libavfilter/vf_dnn_processing.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index cac096a19f..4462915073 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -110,6 +110,7 @@ static int check_modelinput_inlink(const DNNData 
*model_input, const AVFilterLin
 return AVERROR(EIO);
 }
 return 0;
+case AV_PIX_FMT_GRAY8:
 case AV_PIX_FMT_GRAYF32:
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUV422P:
-- 
2.20.1 (Apple Git-117)

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] configure: add pkg-config check for chromaprint

2022-11-02 Thread Timo Rothenpieler
---
 configure | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 30f0ce4e26..2bcdf18a57 100755
--- a/configure
+++ b/configure
@@ -6559,7 +6559,8 @@ enabled avisynth  && { require_headers 
"avisynth/avisynth_c.h avisynth/a
{ test_cpp_condition avisynth/avs/version.h 
"AVS_MAJOR_VER >= 3 && AVS_MINOR_VER >= 7 && AVS_BUGFIX_VER >= 1 || 
AVS_MAJOR_VER >= 3 && AVS_MINOR_VER > 7 || AVS_MAJOR_VER > 3" ||
  die "ERROR: AviSynth+ header version must be 
>= 3.7.1"; } }
 enabled cuda_nvcc && { check_nvcc cuda_nvcc || die "ERROR: failed 
checking for nvcc."; }
-enabled chromaprint   && require chromaprint chromaprint.h 
chromaprint_get_version -lchromaprint
+enabled chromaprint   && { check_pkg_config chromaprint libchromaprint 
"chromaprint.h" chromaprint_get_version ||
+   require chromaprint chromaprint.h 
chromaprint_get_version -lchromaprint; }
 enabled decklink  && { require_headers DeckLinkAPI.h &&
{ test_cpp_condition DeckLinkAPIVersion.h 
"BLACKMAGIC_DECKLINK_API_VERSION >= 0x0a0b" || die "ERROR: Decklink API 
version must be >= 10.11"; } }
 enabled frei0r&& require_headers "frei0r.h"
-- 
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: add AV1 encoding support

2022-11-02 Thread Timo Rothenpieler

On 02/11/2022 02:14, Andreas Rheinhardt wrote:

Timo Rothenpieler:

---

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 3c6fce391d..9a1a1fcc37 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1,5 +1,5 @@
  /*
- * H.264/HEVC hardware encoding using nvidia nvenc
+ * H.264/HEVC/AV1 hardware encoding using nvidia nvenc
   * Copyright (c) 2016 Timo Rothenpieler 
   *
   * This file is part of FFmpeg.
@@ -222,8 +222,14 @@ static void nvenc_map_preset(NvencContext *ctx)
  
  static void nvenc_print_driver_requirement(AVCodecContext *avctx, int level)

  {
-#if NVENCAPI_CHECK_VERSION(11, 2)
+#if NVENCAPI_CHECK_VERSION(12, 1)
  const char *minver = "(unknown)";
+#elif NVENCAPI_CHECK_VERSION(12, 0)
+# if defined(_WIN32) || defined(__CYGWIN__)
+const char *minver = "???.??";
+# else
+const char *minver = "???.??";
+# endif


Either one of the above is wrong or the above #if is superfluous (or I
am blind).


Video SDK 12 is not released yet, so there is no documentation on the 
driver versions.
Whenever it gets release, which was scheduled to happen in October 
already, those need filled in.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavcodec/qsvenc: Add skip_frame support to qsvenc

2022-11-02 Thread wenbin . chen-at-intel . com
From: Wenbin Chen 

Add skip_frame support to qsvenc. Use per-frame metadata
"qsv_skip_frame" to control it. skip_frame option defines the behavior
of qsv_skip_frame.
no_skip: Frame skipping is disabled.
insert_dummy: Encoder inserts into bitstream frame where all macroblocks
are encoded as skipped.
insert_nothing: Similar to insert_dummy, but encoder inserts nothing.
The skipped frames are still used in brc. For example, gop still include
skipped frames, and the frames after skipped frames will be larger in
size.
brc_only: skip_frame metadata indicates the number of missed frames
before the current frame.

Signed-off-by: Wenbin Chen 
---
 doc/encoders.texi| 36 
 libavcodec/qsvenc.c  | 36 
 libavcodec/qsvenc.h  | 13 +
 libavcodec/qsvenc_h264.c |  1 +
 libavcodec/qsvenc_hevc.c |  1 +
 5 files changed, 87 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 53dd02fd28..59f39d18f6 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3564,6 +3564,24 @@ bitrate, @var{target_bitrate}, within the accuracy range 
@var{avbr_accuracy},
 after a @var{avbr_Convergence} period. This method does not follow HRD and the
 instant bitrate is not capped or padded.
 
+@item @var{skip_frame}
+Use per-frame metadata "qsv_skip_frame" to skip frame when encoding. This 
option
+defines the usage of this metadata.
+@table @samp
+@item no_skip
+Frame skipping is disabled.
+@item insert_dummy
+Encoder inserts into bitstream frame where all macroblocks are encoded as
+skipped.
+@item insert_nothing
+Similar to insert_dummy, but encoder inserts nothing into bitstream. The 
skipped
+frames are still used in brc. For example, gop still include skipped frames, 
and
+the frames after skipped frames will be larger in size.
+@item brc_only
+skip_frame metadata indicates the number of missed frames before the current
+frame.
+@end table
+
 @end table
 
 @subsection HEVC Options
@@ -3742,6 +3760,24 @@ bitrate, @var{target_bitrate}, within the accuracy range 
@var{avbr_accuracy},
 after a @var{avbr_Convergence} period. This method does not follow HRD and the
 instant bitrate is not capped or padded.
 
+@item @var{skip_frame}
+Use per-frame metadata "qsv_skip_frame" to skip frame when encoding. This 
option
+defines the usage of this metadata.
+@table @samp
+@item no_skip
+Frame skipping is disabled.
+@item insert_dummy
+Encoder inserts into bitstream frame where all macroblocks are encoded as
+skipped.
+@item insert_nothing
+Similar to insert_dummy, but encoder inserts nothing into bitstream. The 
skipped
+frames are still used in brc. For example, gop still include skipped frames, 
and
+the frames after skipped frames will be larger in size.
+@item brc_only
+skip_frame metadata indicates the number of missed frames before the current
+frame.
+@end table
+
 @end table
 
 @subsection MPEG2 Options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 0db774ea63..4bfa65c575 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -329,6 +329,22 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
"MinQPI: %"PRIu8"; MaxQPI: %"PRIu8"; MinQPP: %"PRIu8"; MaxQPP: 
%"PRIu8"; MinQPB: %"PRIu8"; MaxQPB: %"PRIu8"\n",
co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, 
co2->MinQPB, co2->MaxQPB);
 av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", 
co2->DisableDeblockingIdc);
+
+switch (co2->SkipFrame) {
+case MFX_SKIPFRAME_NO_SKIP:
+av_log(avctx, AV_LOG_VERBOSE, "SkipFrame: no_skip\n");
+break;
+case MFX_SKIPFRAME_INSERT_DUMMY:
+av_log(avctx, AV_LOG_VERBOSE, "SkipFrame: insert_dummy\n");
+break;
+case MFX_SKIPFRAME_INSERT_NOTHING:
+av_log(avctx, AV_LOG_VERBOSE, "SkipFrame: insert_nothing\n");
+break;
+case MFX_SKIPFRAME_BRC_ONLY:
+av_log(avctx, AV_LOG_VERBOSE, "SkipFrame: brc_only\n");
+break;
+default: break;
+}
 }
 
 if (co3) {
@@ -991,6 +1007,8 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->old_max_qp_b = q->max_qp_b;
 if (q->mbbrc >= 0)
 q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
+if (q->skip_frame >= 0)
+q->extco2.SkipFrame = q->skip_frame;
 
 q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
 q->extco2.Header.BufferSz = sizeof(q->extco2);
@@ -1911,6 +1929,19 @@ static int set_roi_encode_ctrl(AVCodecContext *avctx, 
const AVFrame *frame,
 return 0;
 }
 
+static void set_skip_frame_encode_ctrl(AVCodecContext *avctx, const AVFrame 
*frame,
+   mfxEncodeCtrl *enc_ctrl)
+{
+AVDictionaryEntry* skip_frame_dict = NULL;
+if (!frame->metadata)
+return;
+skip_frame_dict = av_dict_get(fr