Re: [FFmpeg-devel] [PATCH] avfilter/colorize: add speed option

2024-05-01 Thread Gyan Doshi



On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. 
This allows for an easy way of creating an color changing effect 
without relying on somewhat complicated expressions.


Signed-off-by: Yannis Gerlach 
---
 libavfilter/vf_colorize.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index e6c563e3e2..ad8577c8fd 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -29,6 +29,7 @@ typedef struct ColorizeContext {
 float saturation;
 float lightness;
 float mix;
+    float speed;
  int depth;
 int c[3];
@@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, 
AVFrame *frame)

 ff_filter_execute(ctx, do_slice, frame, NULL,
   FFMIN(s->planeheight[1], 
ff_filter_get_nb_threads(ctx)));

 +    s->hue += s->speed;
+    if (s->hue < 0.f) {
+    s->hue += 360.f;
+    } else if(s->hue > 360.f) {
+    s->hue -= 360.f;
+    }
+
 return ff_filter_frame(ctx->outputs[0], frame);
 }
 @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = {
 #define VF 
AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM

  static const AVOption colorize_options[] = {
-    { "hue",    "set the hue", OFFSET(hue),    AV_OPT_TYPE_FLOAT, 
{.dbl=0},  0, 360, VF },
-    { "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "lightness",  "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "mix",    "set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},  0,   1, VF },
+    { "hue",    "set the hue", OFFSET(hue),    AV_OPT_TYPE_FLOAT, 
{.dbl=0},    0, 360, VF },
+    { "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+    { "lightness",  "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+    { "mix",    "set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},    0,   1, VF },


The cosmetic changes should be in a separate patch.

Regards,
Gyan

+    { "speed",  "set the change of hue per frame", OFFSET(speed), 
AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF },

 { NULL }
 };
 -- 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 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 1/2] avfilter/colorize: add speed option

2024-05-01 Thread Yannis Gerlach
The speed option allows to have a constant (per frame) change of hue. 
This allows for an easy way of creating an color changing effect without 
relying on somewhat complicated expressions.


Signed-off-by: Yannis Gerlach 
---
libavfilter/vf_colorize.c | 9 +
1 file changed, 9 insertions(+)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index e6c563e3e2..cfcf1a54fb 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -29,6 +29,7 @@ typedef struct ColorizeContext {
float saturation;
float lightness;
float mix;
+ float speed;
int depth;
int c[3];
@@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, 
AVFrame *frame)

ff_filter_execute(ctx, do_slice, frame, NULL,
FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx)));
+ s->hue += s->speed;
+ if (s->hue < 0.f) {
+ s->hue += 360.f;
+ } else if(s->hue > 360.f) {
+ s->hue -= 360.f;
+ }
+
return ff_filter_frame(ctx->outputs[0], frame);
}
@@ -267,6 +275,7 @@ static const AVOption colorize_options[] = {
{ "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF },
{ "lightness", "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF },
{ "mix", "set the mix of source lightness", OFFSET(mix), 
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
+ { "speed", "set the change of hue per frame", OFFSET(speed), 
AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF },

{ NULL }
};
-- 2.34.1




Am 01.05.24 um 09:49 schrieb Gyan Doshi:



On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. 
This allows for an easy way of creating an color changing effect 
without relying on somewhat complicated expressions.


Signed-off-by: Yannis Gerlach 
---
 libavfilter/vf_colorize.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index e6c563e3e2..ad8577c8fd 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -29,6 +29,7 @@ typedef struct ColorizeContext {
 float saturation;
 float lightness;
 float mix;
+    float speed;
  int depth;
 int c[3];
@@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, 
AVFrame *frame)

 ff_filter_execute(ctx, do_slice, frame, NULL,
   FFMIN(s->planeheight[1], 
ff_filter_get_nb_threads(ctx)));

 +    s->hue += s->speed;
+    if (s->hue < 0.f) {
+    s->hue += 360.f;
+    } else if(s->hue > 360.f) {
+    s->hue -= 360.f;
+    }
+
 return ff_filter_frame(ctx->outputs[0], frame);
 }
 @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = {
 #define VF 
AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM

  static const AVOption colorize_options[] = {
-    { "hue",    "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, 
{.dbl=0},  0, 360, VF },
-    { "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "lightness",  "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "mix",    "set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},  0,   1, VF },
+    { "hue",    "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, 
{.dbl=0},    0, 360, VF },
+    { "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+    { "lightness",  "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+    { "mix",    "set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},    0,   1, VF },


The cosmetic changes should be in a separate patch.


I have split them now.



Regards,
Gyan

+    { "speed",  "set the change of hue per frame", 
OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF },

 { NULL }
 };
 -- 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 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".


[FFmpeg-devel] [PATCH 2/2] avfilter/colorize: formatting

2024-05-01 Thread Yannis Gerlach

Add spaces to format option list table-like

Signed-off-by: Yannis Gerlach 
---
 libavfilter/vf_colorize.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index cfcf1a54fb..ad8577c8fd 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -271,10 +271,10 @@ static const AVFilterPad colorize_inputs[] = {
 #define VF 
AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM

  static const AVOption colorize_options[] = {
-{ "hue","set the hue", OFFSET(hue), 
   AV_OPT_TYPE_FLOAT, {.dbl=0},  0, 360, VF },
-{ "saturation", "set the saturation", 
OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-{ "lightness",  "set the lightness", 
OFFSET(lightness),  AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-{ "mix","set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},  0,   1, VF },
+{ "hue","set the hue", OFFSET(hue), 
   AV_OPT_TYPE_FLOAT, {.dbl=0},0, 360, VF },
+{ "saturation", "set the saturation", 
OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+{ "lightness",  "set the lightness", 
OFFSET(lightness),  AV_OPT_TYPE_FLOAT, {.dbl=0.5},  0,   1, VF },
+{ "mix","set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},0,   1, VF },
 { "speed",  "set the change of hue per frame", OFFSET(speed), 
AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF },

 { NULL }
 };
--
2.34.1



Am 01.05.24 um 10:37 schrieb Yannis Gerlach:
The speed option allows to have a constant (per frame) change of hue. 
This allows for an easy way of creating an color changing effect 
without relying on somewhat complicated expressions.


Signed-off-by: Yannis Gerlach 
---
libavfilter/vf_colorize.c | 9 +
1 file changed, 9 insertions(+)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index e6c563e3e2..cfcf1a54fb 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -29,6 +29,7 @@ typedef struct ColorizeContext {
float saturation;
float lightness;
float mix;
+ float speed;
int depth;
int c[3];
@@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, 
AVFrame *frame)

ff_filter_execute(ctx, do_slice, frame, NULL,
FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx)));
+ s->hue += s->speed;
+ if (s->hue < 0.f) {
+ s->hue += 360.f;
+ } else if(s->hue > 360.f) {
+ s->hue -= 360.f;
+ }
+
return ff_filter_frame(ctx->outputs[0], frame);
}
@@ -267,6 +275,7 @@ static const AVOption colorize_options[] = {
{ "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF },
{ "lightness", "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF },
{ "mix", "set the mix of source lightness", OFFSET(mix), 
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
+ { "speed", "set the change of hue per frame", OFFSET(speed), 
AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF },

{ NULL }
};
-- 2.34.1




Am 01.05.24 um 09:49 schrieb Gyan Doshi:



On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of 
hue. This allows for an easy way of creating an color changing 
effect without relying on somewhat complicated expressions.


Signed-off-by: Yannis Gerlach 
---
 libavfilter/vf_colorize.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c
index e6c563e3e2..ad8577c8fd 100644
--- a/libavfilter/vf_colorize.c
+++ b/libavfilter/vf_colorize.c
@@ -29,6 +29,7 @@ typedef struct ColorizeContext {
 float saturation;
 float lightness;
 float mix;
+    float speed;
  int depth;
 int c[3];
@@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, 
AVFrame *frame)

 ff_filter_execute(ctx, do_slice, frame, NULL,
   FFMIN(s->planeheight[1], 
ff_filter_get_nb_threads(ctx)));

 +    s->hue += s->speed;
+    if (s->hue < 0.f) {
+    s->hue += 360.f;
+    } else if(s->hue > 360.f) {
+    s->hue -= 360.f;
+    }
+
 return ff_filter_frame(ctx->outputs[0], frame);
 }
 @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = {
 #define VF 
AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM

  static const AVOption colorize_options[] = {
-    { "hue",    "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, 
{.dbl=0},  0, 360, VF },
-    { "saturation", "set the saturation", OFFSET(saturation), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "lightness",  "set the lightness", OFFSET(lightness), 
AV_OPT_TYPE_FLOAT, {.dbl=0.5},0,   1, VF },
-    { "mix",    "set the mix of source lightness", OFFSET(mix), 
   AV_OPT_TYPE_FLOAT, {.dbl=1},  0,   1, VF },
+    { "hue",    "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, 
{.dbl=0},    0, 360, 

Re: [FFmpeg-devel] Fixes #10509

2024-05-01 Thread Poorva
On Fri, Apr 5, 2024 at 2:08 AM Marton Balint  wrote:
>
>
>
> On Mon, 1 Apr 2024, Poorva wrote:
>
> >>
> >>
> >>
> > On Sun, Mar 31, 2024 at 8:35 PM Marton Balint  wrote:
> >
> >>
> >>
> >> On Fri, 29 Mar 2024, Poorva wrote:
> >>
> 
> >>>
> >>> On Tue, Mar 26, 2024 at 2:36 AM Poorva <2003gaikarpoo...@gmail.com>
> >> wrote:
> >
> >
> 
> 
>  Thank you for your feedback on the Git patch I submitted for review.
>  I have rectified the problem by adding the necessary changes .
>  The updated patch file is attached for your review.
> >
> >
> >>> I wanted to follow up on the patch titled
> >>> "v3-0001-avfilter-f_select.c - Add Support for IW and IH" that I
> >>> submitted earlier and provide an update based on the feedback
> >>> received.
> >>>
> >>> In response to your suggestion about the switch block, I have
> >>> integrated the changes into the existing switch block for
> >>> AVMEDIA_TYPE_VIDEO. Additionally, I have removed an unnecessary new
> >>> line that was added at the end of the file.
> >>>
> >>> Despite these modifications, I have not received any further feedback
> >>> or comments on the patch. Therefore, I kindly request the community to
> >>> review the updated patch attached to this email.
> >>
> >> [..]
> >>
> >>> @@ -371,6 +383,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >>>  break;
> >>>  }
> >>>
> >>> +
> >>>  select->select = res = av_expr_eval(select->expr,
> >> select->var_values, NULL);
> >>>  av_log(inlink->dst, AV_LOG_DEBUG,
> >>> "n:%f pts:%f t:%f key:%d",
> >>> @@ -545,4 +558,4 @@ const AVFilter ff_vf_select = {
> >>>  FILTER_QUERY_FUNC(query_formats),
> >>>  .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
> >> AVFILTER_FLAG_METADATA_ONLY,
> >>>  };
> >>> -#endif /* CONFIG_SELECT_FILTER */
> >>> +#endif /* CONFIG_SELECT_FILTER */
> >>> \ No newline at end of file
> >>> --
> >>> 2.43.0.windows.1
> >>>
> >>
> >> These two whitespace changes are still unnecessary. Please check your
> >> patch before sending.
> >>
> >> I did remove all the unnecessary whitespaces ,rest which are present are
> > to keep the code style .
> > Patch is attached to this email.
>
> No, the last hunk still removes a newline.
Sir, as far as I know git does that automatically.
>
> Regards,
> Marton
> ___
> 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".


[FFmpeg-devel] 回复: [PATCH 1/4] avcodec/x86/vvc: add alf filter luma and chroma avx2 optimizations

2024-05-01 Thread Wu Jianhua
> 发件人: ffmpeg-devel  代表 Nuo Mi 
> 
> 发送时间: 2024年4月30日 11:03
> 收件人: FFmpeg development discussions and patches
> 主题: Re: [FFmpeg-devel] [PATCH 1/4] avcodec/x86/vvc: add alf filter luma and 
> chroma avx2 optimizations
> 
> On Tue, Apr 30, 2024 at 12:34 AM Andreas Rheinhardt <
> andreas.rheinha...@outlook.com> wrote:
> 
> > toq...@outlook.com:
> > > vvc_alf_filter_chroma_16x12_10_c: 7235.5
> > > vvc_alf_filter_chroma_16x12_10_avx2: 9751.0
> >
> > Are these numbers correct? If so, the avx2 version should not be committed.
> >
> It could be a system turbulence. The data around it appears to be correct.
> 
> Hi Jianhua,
> Maybe you can test it again
> Thank you for the patch, Now we can smoothly play a 4k@60 on a modern i7.
> 

Sure. Will rerun the performance test without other processes with high CPU 
usage running  and resend the v2.
___
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 1/4] avcodec/x86/vvc: add alf filter luma and chroma avx2 optimizations

2024-05-01 Thread toqsxw
From: Wu Jianhua 

ff_vvc_alf_filter_luma_4x4_10_c: 135
ff_vvc_alf_filter_luma_4x4_10_avx2: 54
ff_vvc_alf_filter_luma_4x8_10_c: 268
ff_vvc_alf_filter_luma_4x8_10_avx2: 106
ff_vvc_alf_filter_luma_4x12_10_c: 400
ff_vvc_alf_filter_luma_4x12_10_avx2: 160
ff_vvc_alf_filter_luma_4x16_10_c: 535
ff_vvc_alf_filter_luma_4x16_10_avx2: 213
ff_vvc_alf_filter_luma_4x20_10_c: 646
ff_vvc_alf_filter_luma_4x20_10_avx2: 262
ff_vvc_alf_filter_luma_4x24_10_c: 783
ff_vvc_alf_filter_luma_4x24_10_avx2: 309
ff_vvc_alf_filter_luma_4x28_10_c: 908
ff_vvc_alf_filter_luma_4x28_10_avx2: 361
ff_vvc_alf_filter_luma_4x32_10_c: 1039
ff_vvc_alf_filter_luma_4x32_10_avx2: 412
ff_vvc_alf_filter_luma_8x4_10_c: 260
ff_vvc_alf_filter_luma_8x4_10_avx2: 53
ff_vvc_alf_filter_luma_8x8_10_c: 516
ff_vvc_alf_filter_luma_8x8_10_avx2: 105
ff_vvc_alf_filter_luma_8x12_10_c: 779
ff_vvc_alf_filter_luma_8x12_10_avx2: 157
ff_vvc_alf_filter_luma_8x16_10_c: 1038
ff_vvc_alf_filter_luma_8x16_10_avx2: 210
ff_vvc_alf_filter_luma_8x20_10_c: 1293
ff_vvc_alf_filter_luma_8x20_10_avx2: 259
ff_vvc_alf_filter_luma_8x24_10_c: 1553
ff_vvc_alf_filter_luma_8x24_10_avx2: 309
ff_vvc_alf_filter_luma_8x28_10_c: 1815
ff_vvc_alf_filter_luma_8x28_10_avx2: 361
ff_vvc_alf_filter_luma_8x32_10_c: 2067
ff_vvc_alf_filter_luma_8x32_10_avx2: 419
ff_vvc_alf_filter_luma_12x4_10_c: 390
ff_vvc_alf_filter_luma_12x4_10_avx2: 54
ff_vvc_alf_filter_luma_12x8_10_c: 773
ff_vvc_alf_filter_luma_12x8_10_avx2: 107
ff_vvc_alf_filter_luma_12x12_10_c: 1159
ff_vvc_alf_filter_luma_12x12_10_avx2: 155
ff_vvc_alf_filter_luma_12x16_10_c: 1550
ff_vvc_alf_filter_luma_12x16_10_avx2: 207
ff_vvc_alf_filter_luma_12x20_10_c: 1970
ff_vvc_alf_filter_luma_12x20_10_avx2: 260
ff_vvc_alf_filter_luma_12x24_10_c: 2379
ff_vvc_alf_filter_luma_12x24_10_avx2: 309
ff_vvc_alf_filter_luma_12x28_10_c: 2763
ff_vvc_alf_filter_luma_12x28_10_avx2: 362
ff_vvc_alf_filter_luma_12x32_10_c: 3158
ff_vvc_alf_filter_luma_12x32_10_avx2: 419
ff_vvc_alf_filter_luma_16x4_10_c: 523
ff_vvc_alf_filter_luma_16x4_10_avx2: 53
ff_vvc_alf_filter_luma_16x8_10_c: 1049
ff_vvc_alf_filter_luma_16x8_10_avx2: 103
ff_vvc_alf_filter_luma_16x12_10_c: 1566
ff_vvc_alf_filter_luma_16x12_10_avx2: 159
ff_vvc_alf_filter_luma_16x16_10_c: 2078
ff_vvc_alf_filter_luma_16x16_10_avx2: 211
ff_vvc_alf_filter_luma_16x20_10_c: 2631
ff_vvc_alf_filter_luma_16x20_10_avx2: 259
ff_vvc_alf_filter_luma_16x24_10_c: 3149
ff_vvc_alf_filter_luma_16x24_10_avx2: 316
ff_vvc_alf_filter_luma_16x28_10_c: 3631
ff_vvc_alf_filter_luma_16x28_10_avx2: 359
ff_vvc_alf_filter_luma_16x32_10_c: 4233
ff_vvc_alf_filter_luma_16x32_10_avx2: 428
ff_vvc_alf_filter_luma_20x4_10_c: 649
ff_vvc_alf_filter_luma_20x4_10_avx2: 106
ff_vvc_alf_filter_luma_20x8_10_c: 1294
ff_vvc_alf_filter_luma_20x8_10_avx2: 206
ff_vvc_alf_filter_luma_20x12_10_c: 1936
ff_vvc_alf_filter_luma_20x12_10_avx2: 310
ff_vvc_alf_filter_luma_20x16_10_c: 2594
ff_vvc_alf_filter_luma_20x16_10_avx2: 411
ff_vvc_alf_filter_luma_20x20_10_c: 3234
ff_vvc_alf_filter_luma_20x20_10_avx2: 517
ff_vvc_alf_filter_luma_20x24_10_c: 3894
ff_vvc_alf_filter_luma_20x24_10_avx2: 621
ff_vvc_alf_filter_luma_20x28_10_c: 4542
ff_vvc_alf_filter_luma_20x28_10_avx2: 722
ff_vvc_alf_filter_luma_20x32_10_c: 5205
ff_vvc_alf_filter_luma_20x32_10_avx2: 832
ff_vvc_alf_filter_luma_24x4_10_c: 774
ff_vvc_alf_filter_luma_24x4_10_avx2: 104
ff_vvc_alf_filter_luma_24x8_10_c: 1546
ff_vvc_alf_filter_luma_24x8_10_avx2: 206
ff_vvc_alf_filter_luma_24x12_10_c: 2318
ff_vvc_alf_filter_luma_24x12_10_avx2: 312
ff_vvc_alf_filter_luma_24x16_10_c: 3104
ff_vvc_alf_filter_luma_24x16_10_avx2: 411
ff_vvc_alf_filter_luma_24x20_10_c: 3893
ff_vvc_alf_filter_luma_24x20_10_avx2: 513
ff_vvc_alf_filter_luma_24x24_10_c: 4681
ff_vvc_alf_filter_luma_24x24_10_avx2: 616
ff_vvc_alf_filter_luma_24x28_10_c: 5474
ff_vvc_alf_filter_luma_24x28_10_avx2: 721
ff_vvc_alf_filter_luma_24x32_10_c: 6271
ff_vvc_alf_filter_luma_24x32_10_avx2: 832
ff_vvc_alf_filter_luma_28x4_10_c: 907
ff_vvc_alf_filter_luma_28x4_10_avx2: 103
ff_vvc_alf_filter_luma_28x8_10_c: 1797
ff_vvc_alf_filter_luma_28x8_10_avx2: 206
ff_vvc_alf_filter_luma_28x12_10_c: 2708
ff_vvc_alf_filter_luma_28x12_10_avx2: 309
ff_vvc_alf_filter_luma_28x16_10_c: 3632
ff_vvc_alf_filter_luma_28x16_10_avx2: 413
ff_vvc_alf_filter_luma_28x20_10_c: 4537
ff_vvc_alf_filter_luma_28x20_10_avx2: 519
ff_vvc_alf_filter_luma_28x24_10_c: 5463
ff_vvc_alf_filter_luma_28x24_10_avx2: 616
ff_vvc_alf_filter_luma_28x28_10_c: 6372
ff_vvc_alf_filter_luma_28x28_10_avx2: 719
ff_vvc_alf_filter_luma_28x32_10_c: 7274
ff_vvc_alf_filter_luma_28x32_10_avx2: 823
ff_vvc_alf_filter_luma_32x4_10_c: 1029
ff_vvc_alf_filter_luma_32x4_10_avx2: 104
ff_vvc_alf_filter_luma_32x8_10_c: 2060
ff_vvc_alf_filter_luma_32x8_10_avx2: 206
ff_vvc_alf_filter_luma_32x12_10_c: 3112
ff_vvc_alf_filter_luma_32x12_10_avx2: 307
ff_vvc_alf_filter_luma_32x16_10_c: 4161
ff_vvc_alf_filter_luma_32x16_10_avx2: 413
ff_vvc_alf_filter_luma_32x20_10_c: 5211
ff_vvc_alf_filter_luma_32x20_10_avx2: 514
ff_vvc_alf_filter_luma_32x24_10_c: 6238
ff_vvc_alf_filter_luma

[FFmpeg-devel] [PATCH v2 2/4] tests/checkasm: add checkasm_check_vvc_alf and check_alf_filter

2024-05-01 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/Makefile   |   2 +-
 tests/checkasm/checkasm.c |   3 +-
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/vvc_alf.c  | 133 ++
 4 files changed, 137 insertions(+), 2 deletions(-)
 create mode 100644 tests/checkasm/vvc_alf.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 2673e1d098..5a3e3985c4 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -41,7 +41,7 @@ AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
 AVCODECOBJS-$(CONFIG_VORBIS_DECODER)+= vorbisdsp.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
-AVCODECOBJS-$(CONFIG_VVC_DECODER)   += vvc_mc.o
+AVCODECOBJS-$(CONFIG_VVC_DECODER)   += vvc_alf.o vvc_mc.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 8be6cb0f55..8b2bf2827b 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -198,7 +198,8 @@ static const struct {
 { "vorbisdsp", checkasm_check_vorbisdsp },
 #endif
 #if CONFIG_VVC_DECODER
-{ "vvc_mc", checkasm_check_vvc_mc },
+{ "vvc_alf", checkasm_check_vvc_alf },
+{ "vvc_mc",  checkasm_check_vvc_mc  },
 #endif
 #endif
 #if CONFIG_AVFILTER
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index f90920dee7..c6a5cf42dd 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -132,6 +132,7 @@ void checkasm_check_vp8dsp(void);
 void checkasm_check_vp9dsp(void);
 void checkasm_check_videodsp(void);
 void checkasm_check_vorbisdsp(void);
+void checkasm_check_vvc_alf(void);
 void checkasm_check_vvc_mc(void);
 
 struct CheckasmPerf;
diff --git a/tests/checkasm/vvc_alf.c b/tests/checkasm/vvc_alf.c
new file mode 100644
index 00..10469e1528
--- /dev/null
+++ b/tests/checkasm/vvc_alf.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2023-2024 Nuo Mi 
+ * Copyright (c) 2023-2024 Wu Jianhua 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 
+
+#include "checkasm.h"
+#include "libavcodec/vvc/ctu.h"
+#include "libavcodec/vvc/data.h"
+#include "libavcodec/vvc/dsp.h"
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
+
+static const uint32_t pixel_mask[3] = { 0x, 0x03ff03ff, 0x0fff0fff };
+
+#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
+#define SRC_PIXEL_STRIDE (MAX_CTU_SIZE + 2 * ALF_PADDING_SIZE)
+#define DST_PIXEL_STRIDE (SRC_PIXEL_STRIDE + 4)
+#define SRC_BUF_SIZE (SRC_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2) //+3 * 2 
for top and bottom row, *2 for high bit depth
+#define DST_BUF_SIZE (DST_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2)
+#define LUMA_PARAMS_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / 
ALF_BLOCK_SIZE * ALF_NUM_COEFF_LUMA)
+
+#define randomize_buffers(buf0, buf1, size) \
+do {\
+uint32_t mask = pixel_mask[(bit_depth - 8) >> 1];   \
+int k;  \
+for (k = 0; k < size; k += 4) { \
+uint32_t r = rnd() & mask;  \
+AV_WN32A(buf0 + k, r);  \
+AV_WN32A(buf1 + k, r);  \
+}   \
+} while (0)
+
+#define randomize_buffers2(buf, size, filter)   \
+do {\
+int k;  \
+if (filter) {   \
+for (k = 0; k < size; k++) {\
+int8_t r = rnd();   \
+buf[k] = r; \
+}   \
+} else {\
+for (k = 0; k < size; k++) {\
+int r = rnd() % FF_ARRAY_ELEMS(clip_set);   \
+buf[k] = clip_set[r];   \
+}   

[FFmpeg-devel] [PATCH v2 4/4] tests/checkasm/vvc_alf: add check_alf_classify

2024-05-01 Thread toqsxw
From: Wu Jianhua 

Perforamnce Test (fps):
clip  before  after delta
Tango2_3840x2160_60_10_420_27_LD.266  56  115   105.36%
RitualDance_1920x1080_60_10_420_32_LD.266 272 481   76.83%
RitualDance_1920x1080_60_10_420_37_RA.266 303 426   40.59%

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/vvc_alf.c | 47 
 1 file changed, 47 insertions(+)

diff --git a/tests/checkasm/vvc_alf.c b/tests/checkasm/vvc_alf.c
index 10469e1528..9526260598 100644
--- a/tests/checkasm/vvc_alf.c
+++ b/tests/checkasm/vvc_alf.c
@@ -121,6 +121,47 @@ static void check_alf_filter(VVCDSPContext *c, const int 
bit_depth)
 }
 }
 
+static void check_alf_classify(VVCDSPContext *c, const int bit_depth)
+{
+LOCAL_ALIGNED_32(int, class_idx0, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int, transpose_idx0, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int, class_idx1, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int, transpose_idx1, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int32_t, alf_gradient_tmp, [ALF_GRADIENT_SIZE * 
ALF_GRADIENT_SIZE * ALF_NUM_DIR]);
+
+ptrdiff_t stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL;
+int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL;
+
+declare_func_emms(AV_CPU_FLAG_AVX2, void, int *class_idx, int 
*transpose_idx,
+const uint8_t *src, ptrdiff_t src_stride, int width, int height, int 
vb_pos, int *gradient_tmp);
+
+randomize_buffers(src0, src1, SRC_BUF_SIZE);
+
+for (int h = 4; h <= MAX_CTU_SIZE; h += 4) {
+for (int w = 4; w <= MAX_CTU_SIZE; w += 4) {
+const int id_size = w * h / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * 
sizeof(int);
+const int vb_pos  = MAX_CTU_SIZE - ALF_BLOCK_SIZE;
+if (check_func(c->alf.classify, "vvc_alf_classify_%dx%d_%d", w, h, 
bit_depth)) {
+memset(class_idx0, 0, id_size);
+memset(class_idx1, 0, id_size);
+memset(transpose_idx0, 0, id_size);
+memset(transpose_idx1, 0, id_size);
+call_ref(class_idx0, transpose_idx0, src0 + offset, stride, w, 
h, vb_pos, alf_gradient_tmp);
+
+call_new(class_idx1, transpose_idx1, src1 + offset, stride, w, 
h, vb_pos, alf_gradient_tmp);
+
+if (memcmp(class_idx0, class_idx1, id_size))
+fail();
+if (memcmp(transpose_idx0, transpose_idx1, id_size))
+fail();
+bench_new(class_idx1, transpose_idx1, src1 + offset, stride, 
w, h, vb_pos, alf_gradient_tmp);
+}
+}
+}
+}
+
 void checkasm_check_vvc_alf(void)
 {
 int bit_depth;
@@ -130,4 +171,10 @@ void checkasm_check_vvc_alf(void)
 check_alf_filter(&h, bit_depth);
 }
 report("alf_filter");
+
+for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
+ff_vvc_dsp_init(&h, bit_depth);
+check_alf_classify(&h, bit_depth);
+}
+report("alf_classify");
 }
-- 
2.44.0.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".


Re: [FFmpeg-devel] [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-05-01 Thread Yigithan Yigit

Included mem.h and made some changes about readability.




v8-avfilter-af_volumedetect.c-Add-32bit-float-audio-sup.patch
Description: Binary data
___
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 3/3] avutil/opt: Preserve nb_channels in opt_free

2024-05-01 Thread James Almer

On 4/30/2024 9:38 PM, Michael Niedermayer wrote:

On Tue, Apr 30, 2024 at 06:27:23PM -0300, James Almer wrote:

On 4/29/2024 9:48 PM, Michael Niedermayer wrote:

Fixes: division by 0
Fixes: decoder modifying demuxer channels on failure
Fixes: -sseof -5 -i zgclab/ffmpeg_crash/poc3

Found-by: Wang Dawei and Zhou Geng, from Zhongguancun Laboratory
Signed-off-by: Michael Niedermayer 
---
   libavutil/opt.c | 6 --
   1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index ecbf7efe5fb..24c08e4bc06 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -132,9 +132,11 @@ static void opt_free_elem(const AVOption *o, void *ptr)
   av_dict_free((AVDictionary **)ptr);
   break;
-case AV_OPT_TYPE_CHLAYOUT:
+case AV_OPT_TYPE_CHLAYOUT: {
+int nb_channels = ((AVChannelLayout *)ptr)->nb_channels;
   av_channel_layout_uninit((AVChannelLayout *)ptr);
-break;
+((AVChannelLayout *)ptr)->nb_channels = nb_channels;
+break;}
   default:
   break;


A little bit of context would be helpful here. What's using nb_channels
after av_opt_free was called and where?


demuxer sets nb_channels
find stream info copies codec params to context
find stream info tries opening decoder
decoder, refuses, and opt_free_elem() is called on cleanup
context now has 0 channels
context gets copied into params of demuxer
demuxer goes like i have set the channels to a non zero value let me devide by 
them
and oops

there is more than one position in this chain of events this can be fixed

thx


I think we should prevent avcodec_open2() from clearing a user-set 
parameter when closing, rather than change how av_opt_free works.


Like so:


diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 888dd76228..fc8a40e4db 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -414,6 +414,7 @@ void avsubtitle_free(AVSubtitle *sub)

 av_cold void ff_codec_close(AVCodecContext *avctx)
 {
+AVChannelLayout ch_layout;
 int i;

 if (!avctx)
@@ -468,7 +469,13 @@ av_cold void ff_codec_close(AVCodecContext *avctx)

 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
 av_opt_free(avctx->priv_data);
+
+// Work around av_opt_free() unsetting ch_layout
+ch_layout = avctx->ch_layout;
+memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout));
 av_opt_free(avctx);
+avctx->ch_layout = ch_layout;
+
 av_freep(&avctx->priv_data);
 if (av_codec_is_encoder(avctx->codec)) {
 av_freep(&avctx->extradata);

___
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] configure: support msvc build inside WSL

2024-05-01 Thread Alexander Strasser via ffmpeg-devel
On 2024-04-27 22:14 +0200, Timo Rothenpieler wrote:
> ---
>  configure | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 8101b4fce6..89af5f75e7 100755
> --- a/configure
> +++ b/configure
> @@ -5036,7 +5036,12 @@ probe_cc(){
>  else
>  _ident=$($_cc --version 2>/dev/null | head -n1 | tr -d '\r')
>  fi
> -_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk 
> '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / 
> /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
> +if [ -x "$(command -v wslpath)" ]; then
> +_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | 
> awk '\''/including/ { sub(/^.*file: */, ""); if (!match($$0, / /)) { print 
> $$0 } }'\'' | xargs -d\\n -n1 wslpath -u | awk '\''BEGIN { printf "%s:", "$@" 
> }; { sub(/\r/,""); printf " %s", $$0 }; END { print "" }'\'' > $(@:.o=.d)'
> +
> +else
> +_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | 
> awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, 
> / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
> +fi
>  _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
>  _cflags_speed="-O2"
>  _cflags_size="-O1"
> --

Should be good enough if it doesn't break MSVC builds outside of WSL.


  Alexander
___
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] GSoC 2024

2024-05-01 Thread Thilo Borgmann via ffmpeg-devel

Hi,


the application period for GSoC 2024 begins on Jan 22nd.

Everyone interested in mentoring a project in 2024, please add your idea(s) to 
[1].


we've been granted 7 slots this year!
All mentors received a mail already, work period begins May 27th.

There are pending patches from the students on the list, please help reviewing!

Thanks,
Thilo




___
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] Massive memory leak in 6.1.1 (fixed on master)

2024-05-01 Thread Ville Syrjälä
Hi,

I ran into a massive memory leak while transcoding some audio
books after upgrading to ffmpeg 6.1.1 from 6.0.1.

Instead of the normal ~100 MiB rss it now exceeds 10 GiB in about
ten seconds and keeps on going up.

Command line used was approximately this:
ffmpeg -activation_bytes XXX -i book.aax -map 0:a -map 0:v -c:a mp3 -c:v copy \
-ss 0.00 -to 909.038005 -metadata track="1/69" -metadata title="Chapter 1" 
book_01.mp3

Bisect points to:
commit 90fba2774304 ("avfilter/trim: switch to activate")

I then tried master and discovered that the leak is has been
fixed by these two commits:
commit 84e400ae37b1 ("avfilter/buffersrc: switch to activate")
commit d9e41ead8226 ("avfilter/avfilter: fix OOM case for default activate")

So those should be cherry-picked to the next 6.1 release (assuming
there will be one). Both cherry-pick cleanly, and afterwards the
leak is gone from the 6.1 branch as well.

-- 
Ville Syrjälä
syrj...@sci.fi
___
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] configure: support msvc build inside WSL

2024-05-01 Thread Timo Rothenpieler

On 01.05.2024 17:06, Alexander Strasser via ffmpeg-devel wrote:

On 2024-04-27 22:14 +0200, Timo Rothenpieler wrote:

---
  configure | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 8101b4fce6..89af5f75e7 100755
--- a/configure
+++ b/configure
@@ -5036,7 +5036,12 @@ probe_cc(){
  else
  _ident=$($_cc --version 2>/dev/null | head -n1 | tr -d '\r')
  fi
-_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, 
""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
+if [ -x "$(command -v wslpath)" ]; then
+_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); if 
(!match($$0, / /)) { print $$0 } }'\'' | xargs -d\\n -n1 wslpath -u | awk '\''BEGIN { printf "%s:", "$@" }; { 
sub(/\r/,""); printf " %s", $$0 }; END { print "" }'\'' > $(@:.o=.d)'
+
+else
+_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: 
*/, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
+fi
  _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
  _cflags_speed="-O2"
  _cflags_size="-O1"
--


Should be good enough if it doesn't break MSVC builds outside of WSL.


Unless there for some reason is a wslpath binary on the path, that won't 
be an issue.

Will apply shortly
___
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 01/10, v2] avutil: add hwcontext_amf.

2024-05-01 Thread Dmitrii Ovchinnikov
Adds hwcontext_amf, which allows to use shared AMF
context for the encoder, decoder and AMF-based filters,
without copy to the host memory.
It will also allow you to use some optimizations in
the interaction of components (for example, SAV) and make a more
manageable and optimal setup for using GPU devices with AMF
in the case of a fully AMF pipeline.
It will be a significant performance uplift when full AMF pipeline
with filters is used.

We also plan to add Compression artefact removal filter in near feature.
v2: cleanup header files, fixed naming and formats
---
 libavutil/Makefile |   4 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 588 +
 libavutil/hwcontext_amf.h  |  41 ++
 libavutil/hwcontext_amf_internal.h |  77 
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   5 +
 9 files changed, 725 insertions(+)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h
 create mode 100644 libavutil/hwcontext_amf_internal.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6e6fa8d800..13c318560d 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -45,6 +45,7 @@ HEADERS = adler32.h   
  \
   hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
+  hwcontext_amf.h   \
   hwcontext_qsv.h   \
   hwcontext_mediacodec.h\
   hwcontext_opencl.h\
@@ -196,6 +197,7 @@ OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
 OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
+OBJS-$(CONFIG_AMF)  += hwcontext_amf.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
 OBJS-$(CONFIG_MEDIACODEC)   += hwcontext_mediacodec.o
@@ -220,6 +222,8 @@ SKIPHEADERS-$(CONFIG_CUDA) += 
hwcontext_cuda_internal.h \
 SKIPHEADERS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.h
 SKIPHEADERS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= hwcontext_dxva2.h
+SKIPHEADERS-$(CONFIG_AMF)  += hwcontext_amf.h   \
+  hwcontext_amf_internal
 SKIPHEADERS-$(CONFIG_QSV)  += hwcontext_qsv.h
 SKIPHEADERS-$(CONFIG_OPENCL)   += hwcontext_opencl.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index fa99a0d8a4..f06d49c45c 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -65,6 +65,9 @@ static const HWContextType * const hw_table[] = {
 #endif
 #if CONFIG_VULKAN
 &ff_hwcontext_type_vulkan,
+#endif
+#if CONFIG_AMF
+&ff_hwcontext_type_amf,
 #endif
 NULL,
 };
@@ -82,6 +85,7 @@ static const char *const hw_type_names[] = {
 [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
 [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
 [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
+[AV_HWDEVICE_TYPE_AMF] = "amf",
 };
 
 typedef struct FFHWDeviceContext {
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index bac30debae..96042ba197 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -38,6 +38,7 @@ enum AVHWDeviceType {
 AV_HWDEVICE_TYPE_MEDIACODEC,
 AV_HWDEVICE_TYPE_VULKAN,
 AV_HWDEVICE_TYPE_D3D12VA,
+AV_HWDEVICE_TYPE_AMF,
 };
 
 /**
diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
new file mode 100644
index 00..8edfb20fbb
--- /dev/null
+++ b/libavutil/hwcontext_amf.c
@@ -0,0 +1,588 @@
+/*
+ * 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
+ */
+
+#incl

[FFmpeg-devel] [PATCH 02/10, v2] avcodec: add amfdec.

2024-05-01 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

Added AMF based h264, hevc, av1 decoders.
Co-authored-by: Dmitrii Ovchinnikov 
v2: added encoder reinitialisation
---
 libavcodec/Makefile|   7 +-
 libavcodec/allcodecs.c |   3 +
 libavcodec/amfdec.c| 719 +
 libavcodec/amfdec.h|  72 +
 4 files changed, 799 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/amfdec.c
 create mode 100644 libavcodec/amfdec.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cff6347bdb..bba5191a70 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -70,7 +70,7 @@ include $(SRC_PATH)/libavcodec/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
 OBJS-$(CONFIG_AC3DSP)  += ac3dsp.o ac3.o ac3tab.o
 OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o 
mpeg4audio_sample_rates.o
-OBJS-$(CONFIG_AMF) += amfenc.o
+OBJS-$(CONFIG_AMF) += amfenc.o amfdec.o
 OBJS-$(CONFIG_AUDIO_FRAME_QUEUE)   += audio_frame_queue.o
 OBJS-$(CONFIG_ATSC_A53)+= atsc_a53.o
 OBJS-$(CONFIG_AUDIODSP)+= audiodsp.o
@@ -167,6 +167,7 @@ OBJS-$(CONFIG_TEXTUREDSPENC)   += texturedspenc.o
 OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
 OBJS-$(CONFIG_VAAPI_ENCODE)+= vaapi_encode.o
 OBJS-$(CONFIG_AV1_AMF_ENCODER) += amfenc_av1.o
+OBJS-$(CONFIG_AV1_AMF_DECODER) += amfdec.o
 OBJS-$(CONFIG_VC1DSP)  += vc1dsp.o
 OBJS-$(CONFIG_VIDEODSP)+= videodsp.o
 OBJS-$(CONFIG_VP3DSP)  += vp3dsp.o
@@ -411,6 +412,7 @@ OBJS-$(CONFIG_H264_DECODER)+= h264dec.o 
h264_cabac.o h264_cavlc.o \
   h264_refs.o \
   h264_slice.o h264data.o h274.o
 OBJS-$(CONFIG_H264_AMF_ENCODER)+= amfenc_h264.o
+OBJS-$(CONFIG_H264_AMF_DECODER)+= amfdec.o
 OBJS-$(CONFIG_H264_CUVID_DECODER)  += cuviddec.o
 OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_H264_MEDIACODEC_ENCODER) += mediacodecenc.o
@@ -437,6 +439,7 @@ OBJS-$(CONFIG_HEVC_DECODER)+= hevcdec.o 
hevc_mvs.o \
   hevcdsp.o hevc_filter.o hevc_data.o \
   h274.o aom_film_grain.o
 OBJS-$(CONFIG_HEVC_AMF_ENCODER)+= amfenc_hevc.o
+OBJS-$(CONFIG_HEVC_AMF_DECODER)+= amfdec.o
 OBJS-$(CONFIG_HEVC_CUVID_DECODER)  += cuviddec.o
 OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_HEVC_MEDIACODEC_ENCODER) += mediacodecenc.o
@@ -1265,7 +1268,7 @@ SKIPHEADERS+= %_tablegen.h
  \
   bitstream_template.h  \
   $(ARCH)/vpx_arith.h   \
 
-SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
+SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h amfdec.h
 SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
 SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb..58a49b5825 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -843,10 +843,12 @@ 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_av1_amf_encoder;
+extern const FFCodec ff_av1_amf_decoder;
 extern const FFCodec ff_av1_vaapi_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
+extern const FFCodec ff_h264_amf_decoder;
 extern const FFCodec ff_h264_cuvid_decoder;
 extern const FFCodec ff_h264_mf_encoder;
 extern const FFCodec ff_h264_nvenc_encoder;
@@ -856,6 +858,7 @@ extern const FFCodec ff_h264_v4l2m2m_encoder;
 extern const FFCodec ff_h264_vaapi_encoder;
 extern const FFCodec ff_h264_videotoolbox_encoder;
 extern const FFCodec ff_hevc_amf_encoder;
+extern const FFCodec ff_hevc_amf_decoder;
 extern const FFCodec ff_hevc_cuvid_decoder;
 extern const FFCodec ff_hevc_mediacodec_decoder;
 extern const FFCodec ff_hevc_mediacodec_encoder;
diff --git a/libavcodec/amfdec.c b/libavcodec/amfdec.c
new file mode 100644
index 00..c41ad3c2db
--- /dev/null
+++ b/libavcodec/amfdec.c
@@ -0,0 +1,719 @@
+/*
+ * 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 Ge

[FFmpeg-devel] [PATCH 03/10, v2] avcodec/amfenc: Fixes the color information in the output.

2024-05-01 Thread Dmitrii Ovchinnikov
From: Michael Fabian 'Xaymar' Dirks 

added 10 bit support for amf hevc.

before:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file.mkv -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  Format of input frames context (p010le) is not supported by AMF.
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  Format of input frames context (p010le) is not supported by AMF.

after:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  10-bit input video is not supported by AMF H264 encoder
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  10bit file

v2 - lost line returned in ff_amf_pix_fmts
v3 - fixes after review
v4 - extract duplicated code, fix incorrect processing of 10-bit input for h264
v5 - non-functional changes after review

Co-authored-by: Evgeny Pavlov 
Co-authored-by: Araz Iusubov 
---
 libavcodec/amfenc.c  | 37 +
 libavcodec/amfenc.h  |  3 +++
 libavcodec/amfenc_h264.c | 24 
 libavcodec/amfenc_hevc.c | 26 +-
 4 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..0bd15dd812 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -60,6 +60,7 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_P010,
 AV_PIX_FMT_NONE
 };
 
@@ -72,6 +73,7 @@ static const FormatMap format_map[] =
 {
 { AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
 { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_P010,   AMF_SURFACE_P010 },
 { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
 { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
@@ -785,6 +787,41 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 return ret;
 }
 
+int ff_amf_get_color_profile(AVCodecContext *avctx)
+{
+amf_int64 color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
+if (avctx->color_range == AVCOL_RANGE_JPEG) {
+/// Color Space for Full (JPEG) Range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
+break;
+}
+} else {
+/// Color Space for Limited (MPEG) range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
+break;
+}
+}
+return color_profile;
+}
+
 const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[] = {
 #if CONFIG_D3D11VA
 HW_CONFIG_ENCODER_FRAMES(D3D11, D3D11VA),
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..62736ef579 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -21,6 +21,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -170,6 +171,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt);
 */
 extern const enum AVPixelFormat ff_amf_pix_fmts[];
 
+int ff_amf_get_color_profile(AVCodecContext *avctx);
+
 /**
 * Error handling helper
 */
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index abfac2a90f..ad5fcc9ecb 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -199,6 +199,8 @@ static av_cold int amf_encode_init_h264(AVCodecContext 
*avctx)
 AMFRate  framerate;
 AMFSize  framesize = 
AMFConstructSize(avctx->width, avctx->height);
 int  deblocking_filter = (avctx->flags & 
AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
+amf_int64color_profile;
+enum AVPixelFormat pix_fmt;
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
 framerate = AMFConstructRate(avctx->framerate.num, 
avctx->framerate.den);
@@ -262,10 +264,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
 AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ASPECT_RATIO, ratio);
 }
 
-/// Color Range (Parti

[FFmpeg-devel] [PATCH 04/10, v2] avcodec/amfenc: HDR metadata.

2024-05-01 Thread Dmitrii Ovchinnikov
From: nyanmisaka 

v2: fixes for indentation
---
 libavcodec/amfenc.c | 83 +
 1 file changed, 83 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 0bd15dd812..068bb53002 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -36,6 +36,57 @@
 #include "amfenc.h"
 #include "encode.h"
 #include "internal.h"
+#include "libavutil/mastering_display_metadata.h"
+
+static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, 
AMFHDRMetadata *hdrmeta)
+{
+AVFrameSideData*sd_display;
+AVFrameSideData*sd_light;
+AVMasteringDisplayMetadata *display_meta;
+AVContentLightMetadata *light_meta;
+
+sd_display = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd_display) {
+display_meta = (AVMasteringDisplayMetadata *)sd_display->data;
+if (display_meta->has_luminance) {
+const unsigned int luma_den = 1;
+hdrmeta->maxMasteringLuminance =
+(amf_uint32)(luma_den * av_q2d(display_meta->max_luminance));
+hdrmeta->minMasteringLuminance =
+FFMIN((amf_uint32)(luma_den * 
av_q2d(display_meta->min_luminance)), hdrmeta->maxMasteringLuminance);
+}
+if (display_meta->has_primaries) {
+const unsigned int chroma_den = 5;
+hdrmeta->redPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][0])), chroma_den);
+hdrmeta->redPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][1])), chroma_den);
+hdrmeta->greenPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][0])), chroma_den);
+hdrmeta->greenPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][1])), chroma_den);
+hdrmeta->bluePrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][0])), chroma_den);
+hdrmeta->bluePrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][1])), chroma_den);
+hdrmeta->whitePoint[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[0])), chroma_den);
+hdrmeta->whitePoint[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[1])), chroma_den);
+}
+
+sd_light = av_frame_get_side_data(frame, 
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd_light) {
+light_meta = (AVContentLightMetadata *)sd_light->data;
+if (light_meta) {
+hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->MaxCLL;
+hdrmeta->maxFrameAverageLightLevel = 
(amf_uint16)light_meta->MaxFALL;
+}
+}
+return 0;
+}
+return 1;
+}
 
 #if CONFIG_D3D11VA
 #include 
@@ -683,6 +734,26 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
 }
 
+// HDR10 metadata
+if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
+AMFBuffer * hdrmeta_buffer = NULL;
+res = ctx->context->pVtbl->AllocBuffer(ctx->context, 
AMF_MEMORY_HOST, sizeof(AMFHDRMetadata), &hdrmeta_buffer);
+if (res == AMF_OK) {
+AMFHDRMetadata * hdrmeta = 
(AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
+if (amf_save_hdr_metadata(avctx, frame, hdrmeta) == 0) {
+switch (avctx->codec->id) {
+case AV_CODEC_ID_H264:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_HEVC:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+}
+res = amf_set_property_buffer(surface, 
L"av_frame_hdrmeta", hdrmeta_buffer);
+AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
+}
+hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
+}
+}
+
 surface->pVtbl->SetPts(surface, frame->pts);
 AMF_ASSIGN_PROPERTY_INT64(res, surface, PTS_PROP, frame->pts);
 
@@ -746,6 +817,18 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 }
 res_resubmit = AMF_OK;
 if (ctx->delayed_surface != NULL) { // try to resubmit frame
+if (ctx->delayed_surface->pVtbl->HasProperty(ctx->delayed_surface, 
L"av_frame_hdrmeta")) {
+AMFBuffer

[FFmpeg-devel] [PATCH 05/10, v2] avcodec/amfenc: add 10 bit encoding in av1_amf

2024-05-01 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

v2: refactored after review

Signed-off-by: Evgeny Pavlov 
Co-authored-by: Araz Iusubov 
---
 libavcodec/amfenc.c |  2 ++
 libavcodec/amfenc_av1.c | 22 ++
 2 files changed, 24 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 068bb53002..49dd91c4e0 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -746,6 +746,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 case AV_CODEC_ID_HEVC:
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_AV1:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 }
 res = amf_set_property_buffer(surface, 
L"av_frame_hdrmeta", hdrmeta_buffer);
 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 9f18aac648..cc48e93fcb 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -165,6 +165,9 @@ static av_cold int amf_encode_init_av1(AVCodecContext* 
avctx)
 AMFGuid guid;
 AMFRate framerate;
 AMFSize framesize = AMFConstructSize(avctx->width, 
avctx->height);
+amf_int64   color_depth;
+amf_int64   color_profile;
+enumAVPixelFormat pix_fmt;
 
 
 
@@ -203,6 +206,25 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_PROFILE, profile);
 
+/// Color profile
+color_profile = ff_amf_get_color_profile(avctx);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+
+/// Color Depth
+pix_fmt = avctx->hw_frames_ctx ? 
((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format
+: avctx->pix_fmt;
+color_depth = AMF_COLOR_BIT_DEPTH_8;
+if (pix_fmt == AV_PIX_FMT_P010) {
+color_depth = AMF_COLOR_BIT_DEPTH_10;
+}
+
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_COLOR_BIT_DEPTH, color_depth);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+/// Color Transfer Characteristics (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, 
(amf_int64)avctx->color_trc);
+/// Color Primaries (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, 
(amf_int64)avctx->color_primaries);
+
 profile_level = avctx->level;
 if (profile_level == AV_LEVEL_UNKNOWN) {
 profile_level = ctx->level;
-- 
2.38.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 06/10, v2] avcodec/amfenc: GPU driver version check

2024-05-01 Thread Dmitrii Ovchinnikov
From: Araz Iusubov 

Implemented gpu driver check.
10-bit patch works incorrectly on driver version lower than 23.30.

Signed-off-by: Araz Iusubov 
---
 libavcodec/amfenc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 49dd91c4e0..510050e282 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -558,6 +558,10 @@ int ff_amf_encode_init(AVCodecContext *avctx)
 if ((ret = amf_load_library(avctx)) == 0) {
 if ((ret = amf_init_context(avctx)) == 0) {
 if ((ret = amf_init_encoder(avctx)) == 0) {
+if (avctx->pix_fmt == AV_PIX_FMT_P010) {
+AmfContext *ctx = avctx->priv_data;
+AMF_RETURN_IF_FALSE(ctx, ctx->version >= 
AMF_MAKE_FULL_VERSION(1, 4, 32, 0), AVERROR_UNKNOWN, "10-bit encoder is not 
supported by AMD GPU drivers versions lower than 23.30.\n");
+}
 return 0;
 }
 }
-- 
2.38.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 07/10, v2] avcodec/amfenc: add smart access video option

2024-05-01 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

This commit adds option for enabling SmartAccess Video (SAV)
in AMF encoders. SAV is an AMD hardware-specific feature which
enables the parallelization of encode and decode streams across
multiple Video Codec Engine (VCN) hardware instances.

Signed-off-by: Evgeny Pavlov 
---
 libavcodec/amfenc.h  |  1 +
 libavcodec/amfenc_av1.c  | 18 ++
 libavcodec/amfenc_h264.c | 18 ++
 libavcodec/amfenc_hevc.c | 18 ++
 4 files changed, 55 insertions(+)

diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 62736ef579..1bda0136bd 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -90,6 +90,7 @@ typedef struct AmfContext {
 int quality;
 int b_frame_delta_qp;
 int ref_b_frame_delta_qp;
+int smart_access_video;
 
 // Dynamic options, can be set after Init() call
 
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index cc48e93fcb..7d37a242fc 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -104,6 +104,8 @@ static const AVOption options[] = {
 
 { "log_to_dbg", "Enable AMF logging to debug output",   
OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL,{.i64 = 0 }, 0, 1, VE },
 
+{ "smart_access_video", "Enable Smart Access Video",
OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1  }, -1, 1, 
VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -265,6 +267,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+if (ctx->smart_access_video != -1) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
+if (res != AMF_OK) {
+av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not 
supported by AMF.\n");
+if (ctx->smart_access_video != 0)
+return AVERROR(ENOSYS);
+} else {
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is 
set.\n", ctx->smart_access_video);
+// Set low latency mode if Smart Access Video is enabled
+if (ctx->smart_access_video != 0) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE, 
AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE_LOWEST_LATENCY);
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low 
latency mode.\n");
+}
+}
+}
+
 // Pre-Pass, Pre-Analysis, Two-Pass
 if (ctx->rate_control_mode == 
AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_CONSTANT_QP) {
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_PREENCODE, 0);
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index ad5fcc9ecb..a26a6dbef8 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -136,6 +136,8 @@ static const AVOption options[] = {
 
 { "log_to_dbg", "Enable AMF logging to debug output",   
OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 
+{ "smart_access_video", "Enable Smart Access Video",
OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1  }, -1, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -369,6 +371,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_log(ctx, AV_LOG_WARNING, "rate control mode is PEAK_CONSTRAINED_VBR 
but rc_max_rate is not set\n");
 }
 
+if (ctx->smart_access_video != -1) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
+if (res != AMF_OK) {
+av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not 
supported by AMF.\n");
+if (ctx->smart_access_video != 0)
+return AVERROR(ENOSYS);
+} else {
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is 
set.\n", ctx->smart_access_video);
+// Set low latency mode if Smart Access Video is enabled
+if (ctx->smart_access_video != 0) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_LOWLATENCY_MODE, true);
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low 
latency mode.\n");
+}
+}
+}
+
 if (ctx->preanalysis != -1) {
 AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_PRE_ANALYSIS_ENABLE, !!((ctx->preanalysis == 0) ? false : 
true));
 }
diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c
index a89a3cf20c..8c26956513 100644
--- a/

[FFmpeg-devel] [PATCH 08/10, v2] avcodec/amfenc: redesign to use hwcontext_amf.

2024-05-01 Thread Dmitrii Ovchinnikov
Co-authored-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c | 568 +---
 libavcodec/amfenc.h |  23 +-
 2 files changed, 163 insertions(+), 428 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 510050e282..781254327a 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -29,6 +29,8 @@
 #define COBJMACROS
 #include "libavutil/hwcontext_dxva2.h"
 #endif
+#include "libavutil/hwcontext_amf.h"
+#include "libavutil/hwcontext_amf_internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -38,6 +40,18 @@
 #include "internal.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+#ifdef _WIN32
+#include "compat/w32dlfcn.h"
+#else
+#include 
+#endif
+
+#define PTS_PROP L"PtsProp"
+
 static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, 
AMFHDRMetadata *hdrmeta)
 {
 AVFrameSideData*sd_display;
@@ -88,20 +102,6 @@ static int amf_save_hdr_metadata(AVCodecContext *avctx, 
const AVFrame *frame, AM
 return 1;
 }
 
-#if CONFIG_D3D11VA
-#include 
-#endif
-
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
-#endif
-
-#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
-
-#define PTS_PROP L"PtsProp"
-
 const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_NV12,
 AV_PIX_FMT_YUV420P,
@@ -111,289 +111,18 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_AMF_SURFACE,
 AV_PIX_FMT_P010,
 AV_PIX_FMT_NONE
 };
 
-typedef struct FormatMap {
-enum AVPixelFormat   av_format;
-enum AMF_SURFACE_FORMAT  amf_format;
-} FormatMap;
-
-static const FormatMap format_map[] =
-{
-{ AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
-{ AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
-{ AV_PIX_FMT_P010,   AMF_SURFACE_P010 },
-{ AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
-{ AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
-{ AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
-{ AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
-{ AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
-};
-
-static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
-{
-int i;
-for (i = 0; i < amf_countof(format_map); i++) {
-if (format_map[i].av_format == fmt) {
-return format_map[i].amf_format;
-}
-}
-return AMF_SURFACE_UNKNOWN;
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
-{
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
-
-ctx->delayed_frame = av_frame_alloc();
-if (!ctx->delayed_frame) {
-return AVERROR(ENOMEM);
-}
-// hardcoded to current HW queue size - will auto-realloc if too small
-ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, 
sizeof(int64_t),
- AV_FIFO_FLAG_AUTO_GROW);
-if (!ctx->timestamp_list) {
-return AVERROR(ENOMEM);
-}
-ctx->dts_delay = 0;
-
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(&ctx->version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, &ctx->factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, &ctx->trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG

[FFmpeg-devel] [PATCH 09/10, v2] avfilter/scale_amf: Add AMF VPP & super resolution filters

2024-05-01 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

This commit adds two AMF filters: vpp_amf & sr_amf.
Both filters are using AMF hardware acceleration.
vpp_amf supports simple scaling algorithms & color conversion.
sr_amf supports advanced scaling algorithms such as FSR & can
be used for upscaling only.
---
 configure   |   1 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_amf_common.c | 516 
 libavfilter/vf_amf_common.h |  71 +
 libavfilter/vf_sr_amf.c | 192 ++
 libavfilter/vf_vpp_amf.c| 267 +++
 7 files changed, 1051 insertions(+)
 create mode 100644 libavfilter/vf_amf_common.c
 create mode 100644 libavfilter/vf_amf_common.h
 create mode 100644 libavfilter/vf_sr_amf.c
 create mode 100644 libavfilter/vf_vpp_amf.c

diff --git a/configure b/configure
index 8101b4fce6..34313172e1 100755
--- a/configure
+++ b/configure
@@ -3902,6 +3902,7 @@ rubberband_filter_deps="librubberband"
 sab_filter_deps="gpl swscale"
 scale2ref_filter_deps="swscale"
 scale_filter_deps="swscale"
+scale_amf_filter_deps="amf"
 scale_qsv_filter_deps="libmfx"
 scale_qsv_filter_select="qsvvpp"
 scdet_filter_select="scene_sad"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8571e9e2af..f903e8031e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -499,6 +499,7 @@ OBJS-$(CONFIG_SITI_FILTER)   += vf_siti.o
 OBJS-$(CONFIG_SPLIT_FILTER)  += split.o
 OBJS-$(CONFIG_SPP_FILTER)+= vf_spp.o qp_table.o
 OBJS-$(CONFIG_SR_FILTER) += vf_sr.o
+OBJS-$(CONFIG_SR_AMF_FILTER) += vf_sr_amf.o scale_eval.o 
vf_amf_common.o
 OBJS-$(CONFIG_SSIM_FILTER)   += vf_ssim.o framesync.o
 OBJS-$(CONFIG_SSIM360_FILTER)+= vf_ssim360.o framesync.o
 OBJS-$(CONFIG_STEREO3D_FILTER)   += vf_stereo3d.o
@@ -552,6 +553,7 @@ OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER)   += 
vidstabutils.o vf_vidstabtransfo
 OBJS-$(CONFIG_VIF_FILTER)+= vf_vif.o framesync.o
 OBJS-$(CONFIG_VIGNETTE_FILTER)   += vf_vignette.o
 OBJS-$(CONFIG_VMAFMOTION_FILTER) += vf_vmafmotion.o framesync.o
+OBJS-$(CONFIG_VPP_AMF_FILTER)+= vf_vpp_amf.o scale_eval.o 
vf_amf_common.o
 OBJS-$(CONFIG_VPP_QSV_FILTER)+= vf_vpp_qsv.o
 OBJS-$(CONFIG_VSTACK_FILTER) += vf_stack.o framesync.o
 OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index c532682fc2..2f40fb8f6f 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -430,6 +430,8 @@ extern const AVFilter ff_vf_roberts_opencl;
 extern const AVFilter ff_vf_rotate;
 extern const AVFilter ff_vf_sab;
 extern const AVFilter ff_vf_scale;
+extern const AVFilter ff_vf_vpp_amf;
+extern const AVFilter ff_vf_sr_amf;
 extern const AVFilter ff_vf_scale_cuda;
 extern const AVFilter ff_vf_scale_npp;
 extern const AVFilter ff_vf_scale_qsv;
diff --git a/libavfilter/vf_amf_common.c b/libavfilter/vf_amf_common.c
new file mode 100644
index 00..144b9cf604
--- /dev/null
+++ b/libavfilter/vf_amf_common.c
@@ -0,0 +1,516 @@
+/*
+ * 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 "vf_amf_common.h"
+
+#include "libavutil/avassert.h"
+#include "avfilter.h"
+#include "internal.h"
+#include "formats.h"
+#include "libavutil/imgutils.h"
+
+#include "libavutil/hwcontext_amf.h"
+#include "libavutil/hwcontext_amf_internal.h"
+#include "AMF/components/ColorSpace.h"
+#include "scale_eval.h"
+
+#if CONFIG_DXVA2
+#include 
+#endif
+
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+int amf_filter_init(AVFilterContext *avctx)
+{
+AMFFilterContext *ctx = avctx->priv;
+
+if (!strcmp(ctx->format_str, "same")) {
+ctx->format = AV_PIX_FMT_NONE;
+} else {
+ctx->format = av_get_pix_fmt(ctx->format_str);
+if (ctx->format == AV_PIX_FMT_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", 
ctx->format_str);
+return AVERROR(EINVAL);
+}
+}
+
+return 0;
+}
+
+void amf_filter_uninit(AVFilterContext *avctx)
+{
+AMFFilterContext *ctx = avctx->priv;
+
+if (ctx-

[FFmpeg-devel] [PATCH 10/10, v2] doc/filters: Add documentation for AMF filters

2024-05-01 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

Signed-off-by: Evgeny Pavlov 
---
 doc/filters.texi | 238 +++
 1 file changed, 238 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index fc813f12c1..81dad32ce9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22822,6 +22822,76 @@ input upscaled using bicubic upscaling with proper 
scale factor.
 
 To get full functionality (such as async execution), please use the 
@ref{dnn_processing} filter.
 
+@anchor{sr_amf}
+@section sr_amf
+
+Upscale (size increasing) for the input video using AMD Advanced Media 
Framework library for hardware acceleration.
+Use advanced algorithms for upscaling with higher output quality.
+Setting the output width and height works in the same way as for the 
@ref{scale} filter.
+
+The filter accepts the following options:
+@table @option
+@item w
+@item h
+Set the output video dimension expression. Default value is the input 
dimension.
+
+Allows for the same expressions as the @ref{scale} filter.
+
+@item algorithm
+Sets the algorithm used for scaling:
+
+@table @var
+@item bilinear
+Bilinear
+
+@item bicubic
+Bicubic
+
+@item sr1-0
+Video SR1.0
+This is a default value
+
+@item point
+Point
+
+@item sr1-1
+Video SR1.1
+
+@end table
+
+@item sharpness
+Control hq scaler sharpening. The value is a float in the range of [0.0, 2.0]
+
+@item format
+Controls the output pixel format. By default, or if none is specified, the 
input
+pixel format is used.
+
+@item keep-ratio
+Force the scaler to keep the aspect ratio of the input image when the output 
size has a different aspect ratio.
+Default value is false.
+
+@item fill
+Specifies whether the output image outside the region of interest,
+which does not fill the entire output surface should be filled with a solid 
color.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Scale input to 720p, keeping aspect ratio and ensuring the output is yuv420p.
+@example
+sr_amf=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K with algorithm video SR1.1.
+@example
+sr_amf=4096:2160:algorithm=sr1-1
+@end example
+@end itemize
+
 @section ssim
 
 Obtain the SSIM (Structural SImilarity Metric) between two input videos.
@@ -25559,6 +25629,174 @@ Example:
 ffmpeg -i ref.mpg -vf vmafmotion -f null -
 @end example
 
+@anchor{vpp_amf}
+@section vpp_amf
+
+Scale (resize) and convert colorspace, transfer characteristics or color 
primaries for the input video, using AMD Advanced Media Framework library for 
hardware acceleration.
+Setting the output width and height works in the same way as for the 
@ref{scale} filter.
+
+The filter accepts the following options:
+@table @option
+@item w
+@item h
+Set the output video dimension expression. Default value is the input 
dimension.
+
+Allows for the same expressions as the @ref{scale} filter.
+
+@item scale_type
+Sets the algorithm used for scaling:
+
+@table @var
+@item bilinear
+Bilinear
+
+This is the default.
+
+@item bicubic
+Bicubic
+
+@end table
+
+@item format
+Controls the output pixel format. By default, or if none is specified, the 
input
+pixel format is used.
+
+
+@item force_original_aspect_ratio
+@item force_divisible_by
+Work the same as the identical @ref{scale} filter options.
+
+@anchor{color_profile}
+@item color_profile
+Specify all color properties at once.
+
+The accepted values are:
+@table @samp
+@item bt601
+BT.601
+
+@item bt709
+BT.709
+
+@item bt2020
+BT.2020
+
+@end table
+
+@anchor{trc}
+@item trc
+Specify output transfer characteristics.
+
+The accepted values are:
+@table @samp
+@item bt709
+BT.709
+
+@item gamma22
+Constant gamma of 2.2
+
+@item gamma28
+Constant gamma of 2.8
+
+@item smpte170m
+SMPTE-170M
+
+@item smpte240m
+SMPTE-240M
+
+@item linear
+Linear
+
+@item log
+LOG
+
+@item log-sqrt
+LOG_SQRT
+
+@item iec61966-2-4
+iec61966-2-4
+
+@item bt1361-ecg
+BT1361_ECG
+
+@item iec61966-2-1
+iec61966-2-1
+
+@item bt2020-10
+BT.2020 for 10-bits content
+
+@item bt2020-12
+BT.2020 for 12-bits content
+
+@item smpte2084
+SMPTE2084
+
+@item smpte428
+SMPTE428
+
+@item arib-std-b67
+ARIB_STD_B67
+
+@end table
+
+@anchor{primaries}
+@item primaries
+Specify output color primaries.
+
+The accepted values are:
+@table @samp
+@item bt709
+BT.709
+
+@item bt470m
+BT.470M
+
+@item bt470bg
+BT.470BG or BT.601-6 625
+
+@item smpte170m
+SMPTE-170M or BT.601-6 525
+
+@item smpte240m
+SMPTE-240M
+
+@item film
+film
+
+@item bt2020
+BT.2020
+
+@item smpte428
+SMPTE-428
+
+@item smpte431
+SMPTE-431
+
+@item smpte432
+SMPTE-432
+
+@item jedec-p22
+JEDEC P22 phosphors
+
+@end table
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Scale input to 720p, keeping aspect ratio and ensuring the output is yuv420p.
+@example
+vpp_amf=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K and change color profile to bt2020.
+@example
+vpp_amf=4096:2160:color_profile=bt2020
+@end example
+@end itemize
+
 @anchor{vstack}
 @section vstack
 Stack input videos vertically.
-- 
2.38.1.windows.1

Re: [FFmpeg-devel] Massive memory leak in 6.1.1 (fixed on master)

2024-05-01 Thread James Almer

On 5/1/2024 1:52 PM, Ville Syrjälä wrote:

Hi,

I ran into a massive memory leak while transcoding some audio
books after upgrading to ffmpeg 6.1.1 from 6.0.1.

Instead of the normal ~100 MiB rss it now exceeds 10 GiB in about
ten seconds and keeps on going up.

Command line used was approximately this:
ffmpeg -activation_bytes XXX -i book.aax -map 0:a -map 0:v -c:a mp3 -c:v copy \
-ss 0.00 -to 909.038005 -metadata track="1/69" -metadata title="Chapter 1" 
book_01.mp3

Bisect points to:
commit 90fba2774304 ("avfilter/trim: switch to activate")

I then tried master and discovered that the leak is has been
fixed by these two commits:
commit 84e400ae37b1 ("avfilter/buffersrc: switch to activate")
commit d9e41ead8226 ("avfilter/avfilter: fix OOM case for default activate")

So those should be cherry-picked to the next 6.1 release (assuming
there will be one). Both cherry-pick cleanly, and afterwards the
leak is gone from the 6.1 branch as well.


Just backported both commits. Thanks.
___
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 1/3] avcodec/avcodec: prevent ch_layout from being uninitialized in ff_codec_close()

2024-05-01 Thread James Almer
It's a user-set parameter shared with AVCodecParameters, so it should only
be freed by avcodec_free_context().

Signed-off-by: James Almer 
---
 libavcodec/avcodec.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 888dd76228..fc8a40e4db 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -414,6 +414,7 @@ void avsubtitle_free(AVSubtitle *sub)
 
 av_cold void ff_codec_close(AVCodecContext *avctx)
 {
+AVChannelLayout ch_layout;
 int i;
 
 if (!avctx)
@@ -468,7 +469,13 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
 
 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
 av_opt_free(avctx->priv_data);
+
+// Work around av_opt_free() unsetting ch_layout
+ch_layout = avctx->ch_layout;
+memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout));
 av_opt_free(avctx);
+avctx->ch_layout = ch_layout;
+
 av_freep(&avctx->priv_data);
 if (av_codec_is_encoder(avctx->codec)) {
 av_freep(&avctx->extradata);
-- 
2.44.0

___
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 2/3] avcodec/avcodec: don't free coded_side_data in ff_codec_close() when decoding

2024-05-01 Thread James Almer
It's a user-set parameter shared with AVCodecParameters, so it should only
be freed by avcodec_free_context().

Signed-off-by: James Almer 
---
 libavcodec/avcodec.c | 11 ++-
 libavcodec/options.c |  4 
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index fc8a40e4db..e560efff6a 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -458,11 +458,12 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
 
 av_freep(&avctx->internal);
 }
-
-for (i = 0; i < avctx->nb_coded_side_data; i++)
-av_freep(&avctx->coded_side_data[i].data);
-av_freep(&avctx->coded_side_data);
-avctx->nb_coded_side_data = 0;
+if (av_codec_is_encoder(avctx->codec)) {
+for (i = 0; i < avctx->nb_coded_side_data; i++)
+av_freep(&avctx->coded_side_data[i].data);
+av_freep(&avctx->coded_side_data);
+avctx->nb_coded_side_data = 0;
+}
 
 av_buffer_unref(&avctx->hw_frames_ctx);
 av_buffer_unref(&avctx->hw_device_ctx);
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 0c3b40a186..7c32a71275 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -177,6 +177,10 @@ void avcodec_free_context(AVCodecContext **pavctx)
 av_freep(&avctx->inter_matrix);
 av_freep(&avctx->rc_override);
 av_channel_layout_uninit(&avctx->ch_layout);
+for (int i = 0; i < avctx->nb_coded_side_data; i++)
+av_freep(&avctx->coded_side_data[i].data);
+av_freep(&avctx->coded_side_data);
+avctx->nb_coded_side_data = 0;
 av_frame_side_data_free(
 &avctx->decoded_side_data, &avctx->nb_decoded_side_data);
 
-- 
2.44.0

___
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 3/3] avcodec/avcodec: free decoded_side_data in ff_codec_close() when decoding

2024-05-01 Thread James Almer
It's set by the library, so it should be freed when closing the context.

Signed-off-by: James Almer 
---
 libavcodec/avcodec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index e560efff6a..189a0a2193 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -463,7 +463,9 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
 av_freep(&avctx->coded_side_data[i].data);
 av_freep(&avctx->coded_side_data);
 avctx->nb_coded_side_data = 0;
-}
+} else if (av_codec_is_decoder(avctx->codec))
+av_frame_side_data_free(&avctx->decoded_side_data,
+&avctx->nb_decoded_side_data);
 
 av_buffer_unref(&avctx->hw_frames_ctx);
 av_buffer_unref(&avctx->hw_device_ctx);
-- 
2.44.0

___
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] Massive memory leak in 6.1.1 (fixed on master)

2024-05-01 Thread Dennis Mungai
On Wed, 1 May 2024, 21:40 James Almer,  wrote:

> On 5/1/2024 1:52 PM, Ville Syrjälä wrote:
> > Hi,
> >
> > I ran into a massive memory leak while transcoding some audio
> > books after upgrading to ffmpeg 6.1.1 from 6.0.1.
> >
> > Instead of the normal ~100 MiB rss it now exceeds 10 GiB in about
> > ten seconds and keeps on going up.
> >
> > Command line used was approximately this:
> > ffmpeg -activation_bytes XXX -i book.aax -map 0:a -map 0:v -c:a mp3 -c:v
> copy \
> > -ss 0.00 -to 909.038005 -metadata track="1/69" -metadata
> title="Chapter 1" book_01.mp3
> >
> > Bisect points to:
> > commit 90fba2774304 ("avfilter/trim: switch to activate")
> >
> > I then tried master and discovered that the leak is has been
> > fixed by these two commits:
> > commit 84e400ae37b1 ("avfilter/buffersrc: switch to activate")
> > commit d9e41ead8226 ("avfilter/avfilter: fix OOM case for default
> activate")
> >
> > So those should be cherry-picked to the next 6.1 release (assuming
> > there will be one). Both cherry-pick cleanly, and afterwards the
> > leak is gone from the 6.1 branch as well.
>
> Just backported both commits. Thanks.
>

Is this patchset available on FFmpeg 7.x?

>
___
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] Massive memory leak in 6.1.1 (fixed on master)

2024-05-01 Thread James Almer

On 5/1/2024 4:40 PM, Dennis Mungai wrote:

On Wed, 1 May 2024, 21:40 James Almer,  wrote:


On 5/1/2024 1:52 PM, Ville Syrjälä wrote:

Hi,

I ran into a massive memory leak while transcoding some audio
books after upgrading to ffmpeg 6.1.1 from 6.0.1.

Instead of the normal ~100 MiB rss it now exceeds 10 GiB in about
ten seconds and keeps on going up.

Command line used was approximately this:
ffmpeg -activation_bytes XXX -i book.aax -map 0:a -map 0:v -c:a mp3 -c:v

copy \

-ss 0.00 -to 909.038005 -metadata track="1/69" -metadata

title="Chapter 1" book_01.mp3


Bisect points to:
commit 90fba2774304 ("avfilter/trim: switch to activate")

I then tried master and discovered that the leak is has been
fixed by these two commits:
commit 84e400ae37b1 ("avfilter/buffersrc: switch to activate")
commit d9e41ead8226 ("avfilter/avfilter: fix OOM case for default

activate")


So those should be cherry-picked to the next 6.1 release (assuming
there will be one). Both cherry-pick cleanly, and afterwards the
leak is gone from the 6.1 branch as well.


Just backported both commits. Thanks.



Is this patchset available on FFmpeg 7.x?


Yes.
___
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] Massive memory leak in 6.1.1 (fixed on master)

2024-05-01 Thread Dennis Mungai
On Wed, 1 May 2024, 22:44 James Almer,  wrote:

> On 5/1/2024 4:40 PM, Dennis Mungai wrote:
> > On Wed, 1 May 2024, 21:40 James Almer,  wrote:
> >
> >> On 5/1/2024 1:52 PM, Ville Syrjälä wrote:
> >>> Hi,
> >>>
> >>> I ran into a massive memory leak while transcoding some audio
> >>> books after upgrading to ffmpeg 6.1.1 from 6.0.1.
> >>>
> >>> Instead of the normal ~100 MiB rss it now exceeds 10 GiB in about
> >>> ten seconds and keeps on going up.
> >>>
> >>> Command line used was approximately this:
> >>> ffmpeg -activation_bytes XXX -i book.aax -map 0:a -map 0:v -c:a mp3
> -c:v
> >> copy \
> >>> -ss 0.00 -to 909.038005 -metadata track="1/69" -metadata
> >> title="Chapter 1" book_01.mp3
> >>>
> >>> Bisect points to:
> >>> commit 90fba2774304 ("avfilter/trim: switch to activate")
> >>>
> >>> I then tried master and discovered that the leak is has been
> >>> fixed by these two commits:
> >>> commit 84e400ae37b1 ("avfilter/buffersrc: switch to activate")
> >>> commit d9e41ead8226 ("avfilter/avfilter: fix OOM case for default
> >> activate")
> >>>
> >>> So those should be cherry-picked to the next 6.1 release (assuming
> >>> there will be one). Both cherry-pick cleanly, and afterwards the
> >>> leak is gone from the 6.1 branch as well.
> >>
> >> Just backported both commits. Thanks.
> >>
> >
> > Is this patchset available on FFmpeg 7.x?
>
> Yes.
>

Perfect, thanks.

>
___
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 1/3] avcodec/avcodec: prevent ch_layout from being uninitialized in ff_codec_close()

2024-05-01 Thread Andreas Rheinhardt
James Almer:
> It's a user-set parameter shared with AVCodecParameters, so it should only
> be freed by avcodec_free_context().
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/avcodec.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index 888dd76228..fc8a40e4db 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -414,6 +414,7 @@ void avsubtitle_free(AVSubtitle *sub)
>  
>  av_cold void ff_codec_close(AVCodecContext *avctx)
>  {
> +AVChannelLayout ch_layout;
>  int i;
>  
>  if (!avctx)
> @@ -468,7 +469,13 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
>  
>  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
>  av_opt_free(avctx->priv_data);
> +
> +// Work around av_opt_free() unsetting ch_layout
> +ch_layout = avctx->ch_layout;
> +memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout));
>  av_opt_free(avctx);
> +avctx->ch_layout = ch_layout;
> +
>  av_freep(&avctx->priv_data);
>  if (av_codec_is_encoder(avctx->codec)) {
>  av_freep(&avctx->extradata);

This and the other patches will cause memleaks for users that use
allocated channel layouts and avcodec_close()+av_free() (this is
deprecated, not forbidden).

Furthermore, where does the rule "user-set parameters shared with
AVCodecParameters should only be freed by avcodec_free_context()" come
from? It is news to me.

- 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 2/3] avcodec/avcodec: don't free coded_side_data in ff_codec_close() when decoding

2024-05-01 Thread Andreas Rheinhardt
James Almer:
> It's a user-set parameter shared with AVCodecParameters, so it should only
> be freed by avcodec_free_context().
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/avcodec.c | 11 ++-
>  libavcodec/options.c |  4 
>  2 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index fc8a40e4db..e560efff6a 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -458,11 +458,12 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
>  
>  av_freep(&avctx->internal);
>  }
> -
> -for (i = 0; i < avctx->nb_coded_side_data; i++)
> -av_freep(&avctx->coded_side_data[i].data);
> -av_freep(&avctx->coded_side_data);
> -avctx->nb_coded_side_data = 0;
> +if (av_codec_is_encoder(avctx->codec)) {
> +for (i = 0; i < avctx->nb_coded_side_data; i++)
> +av_freep(&avctx->coded_side_data[i].data);
> +av_freep(&avctx->coded_side_data);
> +avctx->nb_coded_side_data = 0;
> +}
>  
>  av_buffer_unref(&avctx->hw_frames_ctx);
>  av_buffer_unref(&avctx->hw_device_ctx);
> diff --git a/libavcodec/options.c b/libavcodec/options.c
> index 0c3b40a186..7c32a71275 100644
> --- a/libavcodec/options.c
> +++ b/libavcodec/options.c
> @@ -177,6 +177,10 @@ void avcodec_free_context(AVCodecContext **pavctx)
>  av_freep(&avctx->inter_matrix);
>  av_freep(&avctx->rc_override);
>  av_channel_layout_uninit(&avctx->ch_layout);
> +for (int i = 0; i < avctx->nb_coded_side_data; i++)
> +av_freep(&avctx->coded_side_data[i].data);
> +av_freep(&avctx->coded_side_data);
> +avctx->nb_coded_side_data = 0;
>  av_frame_side_data_free(
>  &avctx->decoded_side_data, &avctx->nb_decoded_side_data);
>  

1. ff_codec_close() already has an "if is_encoder" branch, it does not
need another one.
2. The code in ff_codec_close() will be redundant as soon as
FF_API_AVCODEC_CLOSE is no more, so it should be inside
FF_API_AVCODEC_CLOSE.
3. The documentation of this field does not mention ownership, but given
that this field existed for a long time lavc's previous behaviour
established the implicit contract that lavc will free this in
avcodec_close(). You are breaking this implicit contract for no good
reason apart from this new principle that user-set stuff shared with
AVCodecParameters should not be freed in avcodec_close(). Which is crazy
given that the relevant AVCodecParameters field has only been added
recently.

- 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 3/3] avcodec/avcodec: free decoded_side_data in ff_codec_close() when decoding

2024-05-01 Thread Andreas Rheinhardt
James Almer:
> It's set by the library, so it should be freed when closing the context.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/avcodec.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index e560efff6a..189a0a2193 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -463,7 +463,9 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
>  av_freep(&avctx->coded_side_data[i].data);
>  av_freep(&avctx->coded_side_data);
>  avctx->nb_coded_side_data = 0;
> -}
> +} else if (av_codec_is_decoder(avctx->codec))
> +av_frame_side_data_free(&avctx->decoded_side_data,
> +&avctx->nb_decoded_side_data);
>  
>  av_buffer_unref(&avctx->hw_frames_ctx);
>  av_buffer_unref(&avctx->hw_device_ctx);

The documentation actually states that it is "owned and freed by the
encoder" for encoding, so your restriction to decoders is wrong. And
without it, the corresponding code in avcodec_free_context() is redundant.

- 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 3/3] avcodec/avcodec: free decoded_side_data in ff_codec_close() when decoding

2024-05-01 Thread James Almer

On 5/1/2024 5:43 PM, Andreas Rheinhardt wrote:

James Almer:

It's set by the library, so it should be freed when closing the context.

Signed-off-by: James Almer 
---
  libavcodec/avcodec.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index e560efff6a..189a0a2193 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -463,7 +463,9 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
  av_freep(&avctx->coded_side_data[i].data);
  av_freep(&avctx->coded_side_data);
  avctx->nb_coded_side_data = 0;
-}
+} else if (av_codec_is_decoder(avctx->codec))
+av_frame_side_data_free(&avctx->decoded_side_data,
+&avctx->nb_decoded_side_data);
  
  av_buffer_unref(&avctx->hw_frames_ctx);

  av_buffer_unref(&avctx->hw_device_ctx);


The documentation actually states that it is "owned and freed by the
encoder" for encoding, so your restriction to decoders is wrong. And
without it, the corresponding code in avcodec_free_context() is redundant.

- Andreas


Do you suggest freeing it in ff_codec_close() for both scenarios then?
___
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/3] avcodec/avcodec: don't free coded_side_data in ff_codec_close() when decoding

2024-05-01 Thread James Almer

On 5/1/2024 5:40 PM, Andreas Rheinhardt wrote:

James Almer:

It's a user-set parameter shared with AVCodecParameters, so it should only
be freed by avcodec_free_context().

Signed-off-by: James Almer 
---
  libavcodec/avcodec.c | 11 ++-
  libavcodec/options.c |  4 
  2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index fc8a40e4db..e560efff6a 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -458,11 +458,12 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
  
  av_freep(&avctx->internal);

  }
-
-for (i = 0; i < avctx->nb_coded_side_data; i++)
-av_freep(&avctx->coded_side_data[i].data);
-av_freep(&avctx->coded_side_data);
-avctx->nb_coded_side_data = 0;
+if (av_codec_is_encoder(avctx->codec)) {
+for (i = 0; i < avctx->nb_coded_side_data; i++)
+av_freep(&avctx->coded_side_data[i].data);
+av_freep(&avctx->coded_side_data);
+avctx->nb_coded_side_data = 0;
+}
  
  av_buffer_unref(&avctx->hw_frames_ctx);

  av_buffer_unref(&avctx->hw_device_ctx);
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 0c3b40a186..7c32a71275 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -177,6 +177,10 @@ void avcodec_free_context(AVCodecContext **pavctx)
  av_freep(&avctx->inter_matrix);
  av_freep(&avctx->rc_override);
  av_channel_layout_uninit(&avctx->ch_layout);
+for (int i = 0; i < avctx->nb_coded_side_data; i++)
+av_freep(&avctx->coded_side_data[i].data);
+av_freep(&avctx->coded_side_data);
+avctx->nb_coded_side_data = 0;
  av_frame_side_data_free(
  &avctx->decoded_side_data, &avctx->nb_decoded_side_data);
  


1. ff_codec_close() already has an "if is_encoder" branch, it does not
need another one.
2. The code in ff_codec_close() will be redundant as soon as
FF_API_AVCODEC_CLOSE is no more, so it should be inside
FF_API_AVCODEC_CLOSE.
3. The documentation of this field does not mention ownership, but given
that this field existed for a long time lavc's previous behaviour
established the implicit contract that lavc will free this in
avcodec_close(). You are breaking this implicit contract for no good


Yes, I wrote this set forgetting avcodec_close() was still a thing.


reason apart from this new principle that user-set stuff shared with
AVCodecParameters should not be freed in avcodec_close(). Which is crazy
given that the relevant AVCodecParameters field has only been added
recently.



___
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 1/3] avcodec/avcodec: prevent ch_layout from being uninitialized in ff_codec_close()

2024-05-01 Thread James Almer

On 5/1/2024 5:26 PM, Andreas Rheinhardt wrote:

James Almer:

It's a user-set parameter shared with AVCodecParameters, so it should only
be freed by avcodec_free_context().

Signed-off-by: James Almer 
---
  libavcodec/avcodec.c | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 888dd76228..fc8a40e4db 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -414,6 +414,7 @@ void avsubtitle_free(AVSubtitle *sub)
  
  av_cold void ff_codec_close(AVCodecContext *avctx)

  {
+AVChannelLayout ch_layout;
  int i;
  
  if (!avctx)

@@ -468,7 +469,13 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
  
  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)

  av_opt_free(avctx->priv_data);
+
+// Work around av_opt_free() unsetting ch_layout
+ch_layout = avctx->ch_layout;
+memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout));
  av_opt_free(avctx);
+avctx->ch_layout = ch_layout;
+
  av_freep(&avctx->priv_data);
  if (av_codec_is_encoder(avctx->codec)) {
  av_freep(&avctx->extradata);


This and the other patches will cause memleaks for users that use
allocated channel layouts and avcodec_close()+av_free() (this is
deprecated, not forbidden).


That's awful, but guess it needs to be supported until avcodec_close() 
is gone, so I'm withdrawing this patch.




Furthermore, where does the rule "user-set parameters shared with
AVCodecParameters should only be freed by avcodec_free_context()" come
from? It is news to me.


It's not a rule, it's the ideal/expected behavior seeing the crash 
Michael found, where the only shared field cleared during 
avcodec_close() was ch_layout because it may contain allocated data and 
can be set through an AVOption.
If you're copying params between codecpar and avctx, the latter should 
not have only one of the relevant fields nuked on an internal failure.

___
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 3/3] avcodec/avcodec: free decoded_side_data in ff_codec_close() when decoding

2024-05-01 Thread Andreas Rheinhardt
James Almer:
> On 5/1/2024 5:43 PM, Andreas Rheinhardt wrote:
>> James Almer:
>>> It's set by the library, so it should be freed when closing the context.
>>>
>>> Signed-off-by: James Almer 
>>> ---
>>>   libavcodec/avcodec.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
>>> index e560efff6a..189a0a2193 100644
>>> --- a/libavcodec/avcodec.c
>>> +++ b/libavcodec/avcodec.c
>>> @@ -463,7 +463,9 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
>>>   av_freep(&avctx->coded_side_data[i].data);
>>>   av_freep(&avctx->coded_side_data);
>>>   avctx->nb_coded_side_data = 0;
>>> -    }
>>> +    } else if (av_codec_is_decoder(avctx->codec))
>>> +    av_frame_side_data_free(&avctx->decoded_side_data,
>>> +    &avctx->nb_decoded_side_data);
>>>     av_buffer_unref(&avctx->hw_frames_ctx);
>>>   av_buffer_unref(&avctx->hw_device_ctx);
>>
>> The documentation actually states that it is "owned and freed by the
>> encoder" for encoding, so your restriction to decoders is wrong. And
>> without it, the corresponding code in avcodec_free_context() is
>> redundant.
>>
>> - Andreas
> 
> Do you suggest freeing it in ff_codec_close() for both scenarios then?

Yes.

- 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 01/10, v2] avutil: add hwcontext_amf.

2024-05-01 Thread Lynne
May 1, 2024, 20:38 by ovchinnikov.dmit...@gmail.com:

> Adds hwcontext_amf, which allows to use shared AMF
> context for the encoder, decoder and AMF-based filters,
> without copy to the host memory.
> It will also allow you to use some optimizations in
> the interaction of components (for example, SAV) and make a more
> manageable and optimal setup for using GPU devices with AMF
> in the case of a fully AMF pipeline.
> It will be a significant performance uplift when full AMF pipeline
> with filters is used.
>
> We also plan to add Compression artefact removal filter in near feature.
> v2: cleanup header files, fixed naming and formats
>

Vulkan encode is quite soon going to get all features needed to allow for
all vendor-specific optimizations to be exposed, though I think you should
already be in the loop.
Is there a reason to add this code in now? AMF is still hardly that used,
at least in the Linux world, as it isn't really packaged everywhere,
and on Windows, D3D12 is gaining more traction.

AMD has also already released all FSR-based code for upscaling.
___
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] FFMPEG support for x265 vbv-end and vbv-end-fr-adj

2024-05-01 Thread Tom Vaughan
When I attempt to pass vbv-end and vbv-end-fr-adj parameters to x265, FFMPEG 
fails.

x265 [error]: vbv-end-fr-adj cannot be enabled when total number of frames is 
unknown

x265 needs to know how many frames it is encoding so that it knows when the 
vbv-end logic needs to kick in. In this case it would be after 96% of the 
source video is encoded. Despite specifying a duration of 30 seconds ( -t 30 ) 
on both input and output (using a 60 second source video), x265 does not know 
the total number of frames (but FFMPEG surely does).

ffmpeg -i test_uhdsdr_1min.mov -t 30 -an -sn -dn -c:v libx265 -b:v 12000k 
-maxrate 8M -bufsize 18M -x265-params 
vbv-init=0.9:vbv-end=0.9:vbv-end-fr-adj=.96:rc-lookahead=48:qg-size=32:scenecut=0:no-open-gop=1:frame-threads=0:repeat-headers=1:nr-inter=400:nr-intra=100:psy-rd=0:cbqpoffs=0:crqpoffs=3
 -t 30 test_uhdsdr_96.mp4

ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.1.1_3 --enable-shared 
--enable-pthreads --enable-version3 --cc=clang --host-cflags= 
--host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl 
--enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d 
--enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus 
--enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy 
--enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract 
--enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis 
--enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 
--enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig 
--enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb 
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino 
--enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg 
--disable-libjack --disable-indev=jack --enable-video
 toolbox --enable-audiotoolbox --enable-neon
  libavutil  58. 29.100 / 58. 29.100
  libavcodec 60. 31.102 / 60. 31.102
  libavformat60. 16.100 / 60. 16.100
  libavdevice60.  3.100 / 60.  3.100
  libavfilter 9. 12.100 /  9. 12.100
  libswscale  7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_uhdsdr_1min.mov':
  Metadata:
major_brand : qt
minor_version   : 512
compatible_brands: qt
encoder : Lavf60.3.100
  Duration: 00:01:00.06, start: 0.00, bitrate: 693020 kb/s
  Stream #0:0[0x1]: Video: prores (HQ) (apch / 0x68637061), yuv422p10le(bt709, 
progressive), 3840x2160, 693017 kb/s, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 
24k tbn (default)
Metadata:
  handler_name: VideoHandler
  vendor_id   : FFMP
  encoder : Apple ProRes 422 (HQ)
  timecode: 00:00:00:00
  Stream #0:1[0x2](eng): Data: none (tmcd / 0x64636D74)
Metadata:
  handler_name: TimeCodeHandler
  timecode: 00:00:00:00
Stream mapping:
  Stream #0:0 -> #0:0 (prores (native) -> hevc (libx265))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.4+31-6722fce1f
x265 [info]: build info [Mac OS X][clang 14.0.0][32 bit][noasm] 10bit
x265 [info]: using cpu capabilities: none!
x265 [error]: vbv-end-fr-adj cannot be enabled when total number of frames is 
unknown
[libx265 @ 0x120706a30] Cannot open libx265 encoder.
[vost#0:0/libx265 @ 0x1207067c0] Error while opening encoder - maybe incorrect 
parameters such as bit_rate, rate, width or height.
Error while filtering: Invalid data found when processing input
[out#0/mp4 @ 0x62dc0240] Nothing was written into output file, because at 
least one of its streams received no packets.
frame=0 fps=0.0 q=0.0 Lsize=   0kB time=N/A bitrate=N/A speed=N/A
Conversion failed!

Running x265 directly (using the decoded YUV in a Y4M container as the source) 
with the same parameters works fine.
x265 --input test_uhdsdr_1min.Y4M --y4m --bitrate 12000 --profile main10 
--keyint 48 --no-open-gop --scenecut 0 --vbv-init 0.9 --vbv-maxrate 18000 
--vbv-bufsize 18000 --vbv-end 0.9 --vbv-end-fr-adj .96 --csv fr_adj_96.csv 
--csv-log-level 1 -o test_UHDSDR_12000_fr_adj_20.265
y4m  [info]: 3840x2160 fps 24000/1001 i420p10 sar 1:1 frames 0 - 1438 of 1439
raw  [info]: output file: test_UHDSDR_12000_fr_adj_20.265
x265 [info]: HEVC encoder version 3.6+7-53afbf5f5
x265 [info]: build info [Mac OS X][GCC 13.2.0][64 bit] 10bit
x265 [info]: using cpu capabilities: NEON
x265 [info]: Main 10 profile, Level-5 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices  : 1
x265 [info]: frame threads / pool features   : 3 / wpp(34 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range

[FFmpeg-devel] [PATCH 1/3][GSoC 2024] libavcodec/vvc: convert (*sad) to (*sad[6]) to prepare for AVX2 funcs

2024-05-01 Thread Stone Chen
To prepare for adding AVX2 functions for different block widths, change 
VVCInterDSPContext to contain (*sad[6]) instead of (*sad). This also default 
initializes the pointer array with the scalar function and the calling sites to 
jump to the correct function based on block width. There's no change in 
functionality.
---
 libavcodec/vvc/dsp.h| 2 +-
 libavcodec/vvc/inter.c  | 4 ++--
 libavcodec/vvc/inter_template.c | 5 -
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index 9810ac314c..b06a3ef10e 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -86,7 +86,7 @@ typedef struct VVCInterDSPContext {
 
 void (*apply_bdof)(uint8_t *dst, ptrdiff_t dst_stride, int16_t *src0, 
int16_t *src1, int block_w, int block_h);
 
-int (*sad)(const int16_t *src0, const int16_t *src1, int dx, int dy, int 
block_w, int block_h);
+int (*sad[6])(const int16_t *src0, const int16_t *src1, int dx, int dy, 
int block_w, int block_h);
 void (*dmvr[2][2])(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, 
int height,
 intptr_t mx, intptr_t my, int width);
 } VVCInterDSPContext;
diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
index 4a8d1d866a..a68f4f9452 100644
--- a/libavcodec/vvc/inter.c
+++ b/libavcodec/vvc/inter.c
@@ -742,7 +742,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
*mvf, MvField *orig_mv,
 fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, 
my, pred_w);
 }
 
-min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h);
+min_sad = fc->vvcdsp.inter.sad[av_log2(block_w) - 2](tmp[L0], tmp[L1], dx, 
dy, block_w, block_h);
 min_sad -= min_sad >> 2;
 sad[dy][dx] = min_sad;
 
@@ -752,7 +752,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
*mvf, MvField *orig_mv,
 for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
 for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
 if (dx != sr_range || dy != sr_range) {
-sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, 
dy, block_w, block_h);
+sad[dy][dx] = fc->vvcdsp.inter.sad[av_log2(block_w) - 
2](lc->tmp, lc->tmp1, dx, dy, block_w, block_h);
 if (sad[dy][dx] < min_sad) {
 min_sad = sad[dy][dx];
 min_dx = dx;
diff --git a/libavcodec/vvc/inter_template.c b/libavcodec/vvc/inter_template.c
index e2fbfd4fc0..545e8dd184 100644
--- a/libavcodec/vvc/inter_template.c
+++ b/libavcodec/vvc/inter_template.c
@@ -458,7 +458,10 @@ static void FUNC(ff_vvc_inter_dsp_init)(VVCInterDSPContext 
*const inter)
 inter->apply_prof_uni_w = FUNC(apply_prof_uni_w);
 inter->apply_bdof   = FUNC(apply_bdof);
 inter->prof_grad_filter = FUNC(prof_grad_filter);
-inter->sad  = vvc_sad;
+
+for (int i = 0; i < FF_ARRAY_ELEMS(inter->sad); i++) {
+inter->sad[i]   = vvc_sad;
+}
 }
 
 #undef FUNCS
-- 
2.44.0

___
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 2/3][GSoC 2024] libavcodec/x86/vvc: Add AVX2 DMVR SAD functions for VVC

2024-05-01 Thread Stone Chen
Implements AVX2 DMVR (decoder-side motion vector refinement) SAD functions. 
DMVR SAD is only calculated if w >= 8, h >= 8, and w * h > 128. To reduce 
complexity, SAD is only calculated on even rows. This is calculated for all 
video bitdepths, but the values passed to the function are always 16bit (even 
if the original video bitdepth is 8). The AVX2 implementation uses min/max/sub.

Before:
BQTerrace_1920x1080_60_10_420_22_RA.vvc | 80.7 |
Chimera_8bit_1080P_1000_frames.vvc | 158.0 |
NovosobornayaSquare_1920x1080.bin | 159.7 |
RitualDance_1920x1080_60_10_420_37_RA.266 | 146.3 |

After:
BQTerrace_1920x1080_60_10_420_22_RA.vvc | 82.7 |
Chimera_8bit_1080P_1000_frames.vvc | 167.0 |
NovosobornayaSquare_1920x1080.bin | 166.3 |
RitualDance_1920x1080_60_10_420_37_RA.266 | 154.0 |
---
 libavcodec/x86/vvc/Makefile  |   3 +-
 libavcodec/x86/vvc/vvc_sad.asm   | 193 +++
 libavcodec/x86/vvc/vvcdsp_init.c |  15 +++
 3 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/x86/vvc/vvc_sad.asm

diff --git a/libavcodec/x86/vvc/Makefile b/libavcodec/x86/vvc/Makefile
index d1623bd46a..9eb5f65c7c 100644
--- a/libavcodec/x86/vvc/Makefile
+++ b/libavcodec/x86/vvc/Makefile
@@ -4,4 +4,5 @@ clean::
 OBJS-$(CONFIG_VVC_DECODER) += x86/vvc/vvcdsp_init.o \
   x86/h26x/h2656dsp.o
 X86ASM-OBJS-$(CONFIG_VVC_DECODER)  += x86/vvc/vvc_mc.o   \
-  x86/h26x/h2656_inter.o
+  x86/h26x/h2656_inter.o \
+  x86/vvc/vvc_sad.o
diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
new file mode 100644
index 00..06be3a936a
--- /dev/null
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -0,0 +1,193 @@
+; /*
+; * Provide SIMD DMVR SAD functions for VVC decoding
+; *
+; * Copyright (c) 2024 Stone Chen
+; *
+; * 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/x86/x86util.asm"
+
+%define MAX_PB_SIZE 128
+%define ROWS 2  ; DMVR SAD is only calculated on even rows to reduce 
complexity
+
+SECTION .text
+
+%macro MIN_MAX_SAD 3 ; 
+vpminuw   %1, %2, %3
+vpmaxuw   %3, %2, %3
+vpsubusw  %3, %3, %1
+%endmacro
+
+%macro HORIZ_ADD 3  ; xm0, xm1, m1
+vextracti128  %1, %3, q0001  ;32  1  0
+vpaddd%1, %2 ; xm0 (7 + 3) (6 + 2) (5 + 1)   (4 + 0)
+vpshufd   %2, %1, q0032  ; xm1-  - (7 + 3)   (6 + 2)
+vpaddd%1, %1, %2 ; xm0_  _ (5 1 7 3) (4 0 6 2)
+vpshufd   %2, %1, q0001  ; xm1_  _ (5 1 7 3) (5 1 7 3)
+vpaddd%1, %1, %2 ;   (01234567)
+%endmacro
+
+%macro INIT_OFFSET 6 ; src1, src2, dxq, dyq, off1, off2
+sub %3, 2
+sub %4, 2
+
+mov %5, 2
+mov %6, 2
+
+add %5, %4   
+sub %6, %4
+
+imul%5, 128
+imul%6, 128
+
+add %5, 2
+add %6, 2
+
+add %5, %3
+sub %6, %3
+
+lea %1, [%1 + %5 * 2]
+lea %2, [%2 + %6 * 2]
+%endmacro
+
+%if ARCH_X86_64
+%if HAVE_AVX2_EXTERNAL
+
+INIT_YMM avx2
+
+cglobal vvc_sad_8, 6, 8, 13, src1, src2, dx, dy, block_w, block_h, off1, off2
+
+INIT_OFFSET src1q, src2q, dxq, dyq, off1q, off2q
+pxor   m3, m3
+
+.loop_height:
+movu  xm0, [src1q]
+movu  xm1, [src2q]
+MIN_MAX_SAD   xm2, xm0, xm1
+vpmovzxwd  m1, xm1
+vpaddd m3, m1
+
+movu  xm5, [src1q + MAX_PB_SIZE * ROWS * 2]
+movu  xm6, [src2q + MAX_PB_SIZE * ROWS * 2]
+MIN_MAX_SAD   xm7, xm5, xm6
+vpmovzxwd  m6, xm6
+vpaddd m3, m6
+
+movu  xm8, [src1q + MAX_PB_SIZE * 2 * ROWS * 2]
+movu  xm9, [src2q + MAX_PB_SIZE * 2 * ROWS * 2]
+MIN_MAX_SAD xm10, xm8, xm9
+vpmovzxwd  m9, xm9
+vpaddd m3

[FFmpeg-devel] [PATCH 3/3][GSoC 2024] tests/checkasm: Add check_vvc_sad to vvc_mc.c

2024-05-01 Thread Stone Chen
Adds checkasm for DMVR SAD AVX2 implementation.

Benchmarks ( AMD 7940HS )
vvc_sad_8_16bpc_c: 112.5
vvc_sad_8_16bpc_avx2: 2.5
vvc_sad_16_16bpc_c: 232.5
vvc_sad_16_16bpc_avx2: 22.5
vvc_sad_32_16bpc_c: 912.5
vvc_sad_32_16bpc_avx2: 82.5
vvc_sad_64_16bpc_c: 3582.5
vvc_sad_64_16bpc_avx2: 392.5
vvc_sad_128_16bpc_c: 16702.5
vvc_sad_128_16bpc_avx2: 1912.5

Before:
BQTerrace_1920x1080_60_10_420_22_RA.vvc | 80.7 |
Chimera_8bit_1080P_1000_frames.vvc | 158.0 |
NovosobornayaSquare_1920x1080.bin | 159.7 |
RitualDance_1920x1080_60_10_420_37_RA.266 | 146.3 |

After:
BQTerrace_1920x1080_60_10_420_22_RA.vvc | 82.7 |
Chimera_8bit_1080P_1000_frames.vvc | 167.0 |
NovosobornayaSquare_1920x1080.bin | 166.3 |
RitualDance_1920x1080_60_10_420_37_RA.266 | 154.0 |
---
 tests/checkasm/vvc_mc.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
index 97f57cb401..77dd32fbbb 100644
--- a/tests/checkasm/vvc_mc.c
+++ b/tests/checkasm/vvc_mc.c
@@ -322,8 +322,46 @@ static void check_avg(void)
 report("avg");
 }
 
+static void check_vvc_sad(void)
+{
+const int bit_depth = 10;
+VVCDSPContext c;
+LOCAL_ALIGNED_32(uint16_t, src0, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
+LOCAL_ALIGNED_32(uint16_t, src1, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
+declare_func(int, const int16_t *src0, const int16_t *src1, int dx, int 
dy, int block_w, int block_h);
+
+ff_vvc_dsp_init(&c, bit_depth);
+memset(src0, 0, MAX_CTU_SIZE * MAX_CTU_SIZE * 2);
+memset(src1, 0, MAX_CTU_SIZE * MAX_CTU_SIZE * 2);
+
+randomize_pixels(src0, src1, MAX_CTU_SIZE * MAX_CTU_SIZE * 2);
+ for (int h = 8; h <= MAX_CTU_SIZE; h *= 2) {
+for (int w = 8; w <= MAX_CTU_SIZE; w *= 2) {
+for(int offy = 0; offy <= 4; offy++) {
+for(int offx = 0; offx <= 4; offx++) {
+if(check_func(c.inter.sad[av_log2(w)-2], "vvc_sad_%dx%d", 
w, h)) {
+int result0;
+int result1;
+
+result0 =  call_ref(src0 + PIXEL_STRIDE * 2 + 2, src1 
+ PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
+result1 =  call_new(src0 + PIXEL_STRIDE * 2 + 2, src1 
+ PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
+
+if (result1 != result0)
+fail();
+if(w == h && offx == 0 && offy == 0)
+bench_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + 
PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
+}
+}
+}
+}
+ }
+
+report("check_vvc_sad");
+}
+
 void checkasm_check_vvc_mc(void)
 {
+check_vvc_sad();
 check_put_vvc_luma();
 check_put_vvc_luma_uni();
 check_put_vvc_chroma();
-- 
2.44.0

___
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 1/3][GSoC 2024] libavcodec/vvc: convert (*sad) to (*sad[6]) to prepare for AVX2 funcs

2024-05-01 Thread Andreas Rheinhardt
Stone Chen:
> To prepare for adding AVX2 functions for different block widths, change 
> VVCInterDSPContext to contain (*sad[6]) instead of (*sad). This also default 
> initializes the pointer array with the scalar function and the calling sites 
> to jump to the correct function based on block width. There's no change in 
> functionality.
> ---
>  libavcodec/vvc/dsp.h| 2 +-
>  libavcodec/vvc/inter.c  | 4 ++--
>  libavcodec/vvc/inter_template.c | 5 -
>  3 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
> index 9810ac314c..b06a3ef10e 100644
> --- a/libavcodec/vvc/dsp.h
> +++ b/libavcodec/vvc/dsp.h
> @@ -86,7 +86,7 @@ typedef struct VVCInterDSPContext {
>  
>  void (*apply_bdof)(uint8_t *dst, ptrdiff_t dst_stride, int16_t *src0, 
> int16_t *src1, int block_w, int block_h);
>  
> -int (*sad)(const int16_t *src0, const int16_t *src1, int dx, int dy, int 
> block_w, int block_h);
> +int (*sad[6])(const int16_t *src0, const int16_t *src1, int dx, int dy, 
> int block_w, int block_h);
>  void (*dmvr[2][2])(int16_t *dst, const uint8_t *src, ptrdiff_t 
> src_stride, int height,
>  intptr_t mx, intptr_t my, int width);
>  } VVCInterDSPContext;
> diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
> index 4a8d1d866a..a68f4f9452 100644
> --- a/libavcodec/vvc/inter.c
> +++ b/libavcodec/vvc/inter.c
> @@ -742,7 +742,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
> *mvf, MvField *orig_mv,
>  fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, 
> mx, my, pred_w);
>  }
>  
> -min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, 
> block_h);
> +min_sad = fc->vvcdsp.inter.sad[av_log2(block_w) - 2](tmp[L0], tmp[L1], 
> dx, dy, block_w, block_h);
>  min_sad -= min_sad >> 2;
>  sad[dy][dx] = min_sad;
>  
> @@ -752,7 +752,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
> *mvf, MvField *orig_mv,
>  for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
>  for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
>  if (dx != sr_range || dy != sr_range) {
> -sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, 
> dx, dy, block_w, block_h);
> +sad[dy][dx] = fc->vvcdsp.inter.sad[av_log2(block_w) - 
> 2](lc->tmp, lc->tmp1, dx, dy, block_w, block_h);
>  if (sad[dy][dx] < min_sad) {
>  min_sad = sad[dy][dx];
>  min_dx = dx;
> diff --git a/libavcodec/vvc/inter_template.c b/libavcodec/vvc/inter_template.c
> index e2fbfd4fc0..545e8dd184 100644
> --- a/libavcodec/vvc/inter_template.c
> +++ b/libavcodec/vvc/inter_template.c
> @@ -458,7 +458,10 @@ static void 
> FUNC(ff_vvc_inter_dsp_init)(VVCInterDSPContext *const inter)
>  inter->apply_prof_uni_w = FUNC(apply_prof_uni_w);
>  inter->apply_bdof   = FUNC(apply_bdof);
>  inter->prof_grad_filter = FUNC(prof_grad_filter);
> -inter->sad  = vvc_sad;
> +
> +for (int i = 0; i < FF_ARRAY_ELEMS(inter->sad); i++) {
> +inter->sad[i]   = vvc_sad;
> +}
>  }
>  
>  #undef FUNCS

Why is the jump depending upon block width not performed inside your
avx2 implementation?

- 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] Added alpha layer support for smartblur

2024-05-01 Thread Cosmin Stejerean via ffmpeg-devel


> On Mar 25, 2024, at 1:49 AM, Andrea Mastroberti via ffmpeg-devel 
>  wrote:
> 
> Signed-off-by: Andrea Mastroberti <10736...@polimi.it>
> ---
> doc/filters.texi   | 20 -
> libavfilter/version.h  |  2 +-
> libavfilter/vf_smartblur.c | 44 ++
> 3 files changed, 55 insertions(+), 11 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 913365671d..30b3627724 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -22688,9 +22688,27 @@ whether a pixel should be blurred or not. The option 
> value must be an
> integer in the range [-30,30]. A value of 0 will filter all the image,
> a value included in [0,30] will filter flat areas and a value included
> in [-30,0] will filter edges. Default value is @option{luma_threshold}.
> +
> +@item alpha_radius, ar
> +Set the alpha radius. The option value must be a float number in
> +the range [0.1,5.0] that specifies the variance of the gaussian filter
> +used to blur the image (slower if larger). Default value is 1.0.


Default value should be @option{luma_radius}.

> +
> +@item alpha_strength, as
> +Set the alpha strength. The option value must be a float number
> +in the range [-1.0,1.0] that configures the blurring. A value included
> +in [0.0,1.0] will blur the image whereas a value included in
> +[-1.0,0.0] will sharpen the image. Default value is 1.0.

Default value should be @option{luma_strength}.

> +
> +@item alpha_threshold, at
> +Set the alpha threshold used as a coefficient to determine
> +whether a pixel should be blurred or not. The option value must be an
> +integer in the range [-30,30]. A value of 0 will filter all the image,
> +a value included in [0,30] will filter flat areas and a value included
> +in [-30,0] will filter edges. Default value is 0.

Default value should be @option{luma_threshold}.

> @end table
> -If a chroma option is not explicitly set, the corresponding luma value
> +If a chroma or alpha option is not explicitly set, the corresponding luma 
> value
> is set.
>  @section sobel
> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index d5a6bc143a..f01b3f8e91 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -32,7 +32,7 @@
> #include "version_major.h"
>  #define LIBAVFILTER_VERSION_MINOR   0
> -#define LIBAVFILTER_VERSION_MICRO 100
> +#define LIBAVFILTER_VERSION_MICRO 101
>   #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> diff --git a/libavfilter/vf_smartblur.c b/libavfilter/vf_smartblur.c
> index ae0ec05b2d..bc377d0b92 100644
> --- a/libavfilter/vf_smartblur.c
> +++ b/libavfilter/vf_smartblur.c
> @@ -54,6 +54,7 @@ typedef struct SmartblurContext {
> const AVClass *class;
> FilterParam  luma;
> FilterParam  chroma;
> +FilterParam  alpha;
> int  hsub;
> int  vsub;
> unsigned int sws_flags;
> @@ -77,6 +78,13 @@ static const AVOption smartblur_options[] = {
> { "chroma_threshold", "set chroma threshold", OFFSET(chroma.threshold), 
> AV_OPT_TYPE_INT,   {.i64=THRESHOLD_MIN-1}, THRESHOLD_MIN-1, THRESHOLD_MAX, 
> .flags=FLAGS },
> { "ct",   "set chroma threshold", OFFSET(chroma.threshold), 
> AV_OPT_TYPE_INT,   {.i64=THRESHOLD_MIN-1}, THRESHOLD_MIN-1, THRESHOLD_MAX, 
> .flags=FLAGS },

Probably add a line break in here for visual separation as there is between 
chroma and luma parameters.

> +{ "alpha_radius","set alpha radius",OFFSET(alpha.radius),
> AV_OPT_TYPE_FLOAT, {.dbl=1.0}, RADIUS_MIN, RADIUS_MAX, .flags=FLAGS },
> +{ "ar" ,"set alpha radius",OFFSET(alpha.radius), 
> AV_OPT_TYPE_FLOAT, {.dbl=1.0}, RADIUS_MIN, RADIUS_MAX, .flags=FLAGS },

The default value for both of those should be RADIUS_MIN-1 not 1.0, and the 
minimum value  RADIUS_MIN-1.

> +{ "alpha_strength",  "set alpha strength",  OFFSET(alpha.strength),  
> AV_OPT_TYPE_FLOAT, {.dbl=1.0}, STRENGTH_MIN, STRENGTH_MAX, .flags=FLAGS },
> +{ "as", "set alpha strength",  OFFSET(alpha.strength), 
> AV_OPT_TYPE_FLOAT, {.dbl=1.0}, STRENGTH_MIN, STRENGTH_MAX, .flags=FLAGS },


The default value should be STRENGTH_MIN-1, likewise for the minimum value.

> +{ "alpha_threshold", "set alpha threshold", OFFSET(alpha.threshold), 
> AV_OPT_TYPE_INT,   {.i64=0}, THRESHOLD_MIN, THRESHOLD_MAX, .flags=FLAGS },
> +{ "at", "set alpha threshold", OFFSET(alpha.threshold), 
> AV_OPT_TYPE_INT,   {.i64=0}, THRESHOLD_MIN, THRESHOLD_MAX, .flags=FLAGS },

The default value should be THRESHOLD_MIN-1, likewise for the minimum value.

> +
> { NULL }
> };
> @@ -86,7 +94,7 @@ static av_cold int init(AVFilterContext *ctx)
> {
> SmartblurContext *s = ctx->priv;
> -/* make chroma default to luma values, if not explicitly set */
> +/* make chroma and alpha default to luma values, if not explicitly set */


Rather than change this comment I think you can add a similar comment above the 
alpha defaulting belo

[FFmpeg-devel] [PATCH 1/7] avcodec/av1dec: bit_depth cannot be another values than 8, 10, 12

2024-05-01 Thread Michael Niedermayer
Fixes: CID1544265 Logically dead code

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/av1dec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 79a30a114da..4f9222cca27 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -493,7 +493,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
 else if (bit_depth == 12)
 pix_fmt = AV_PIX_FMT_YUV444P12;
 else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
 } else if (seq->color_config.subsampling_x == 1 &&
seq->color_config.subsampling_y == 0) {
 if (bit_depth == 8)
@@ -503,7 +503,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
 else if (bit_depth == 12)
 pix_fmt = AV_PIX_FMT_YUV422P12;
 else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
 } else if (seq->color_config.subsampling_x == 1 &&
seq->color_config.subsampling_y == 1) {
 if (bit_depth == 8)
@@ -513,7 +513,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
 else if (bit_depth == 12)
 pix_fmt = AV_PIX_FMT_YUV420P12;
 else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
 }
 } else {
 if (bit_depth == 8)
@@ -523,7 +523,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
 else if (bit_depth == 12)
 pix_fmt = AV_PIX_FMT_GRAY12;
 else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
 }
 
 return pix_fmt;
-- 
2.43.2

___
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 2/7] avcodec/av1dec: initialize ret in av1_receive_frame_internal()

2024-05-01 Thread Michael Niedermayer
Fixes: CID1596605 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/av1dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4f9222cca27..93ab04eb378 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 {
 AV1DecContext *s = avctx->priv_data;
 AV1RawTileGroup *raw_tile_group = NULL;
-int i = 0, ret;
+int i = 0, ret = 0;
 
 for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
 CodedBitstreamUnit *unit = &s->current_obu.units[i];
-- 
2.43.2

___
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 3/7] avcodec/avfft: Remove dead code

2024-05-01 Thread Michael Niedermayer
Fixes: CID1543204 Logically dead code

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/avfft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index f6787937f67..0f43f30b776 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -158,7 +158,7 @@ RDFTContext *av_rdft_init(int nbits, enum RDFTransformType 
trans)
 return NULL;
 }
 
-s->stride = (trans == DFT_C2R) ? sizeof(AVComplexFloat) : sizeof(float);
+s->stride = sizeof(float);
 s->len = 1 << nbits;
 s->inv = trans == IDFT_C2R;
 
-- 
2.43.2

___
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 4/7] avcodec/avs2_parser: Assert init_get_bits8() success with const size 15

2024-05-01 Thread Michael Niedermayer
Fixes: CID1506708 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/avs2_parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
index 200134f91db..8d4bc3cee0d 100644
--- a/libavcodec/avs2_parser.c
+++ b/libavcodec/avs2_parser.c
@@ -72,13 +72,15 @@ static void parse_avs2_seq_header(AVCodecParserContext *s, 
const uint8_t *buf,
 unsigned aspect_ratio;
 unsigned frame_rate_code;
 int low_delay;
+int ret;
 // update buf_size_min if parse more deeper
 const int buf_size_min = 15;
 
 if (buf_size < buf_size_min)
 return;
 
-init_get_bits8(&gb, buf, buf_size_min);
+ret = init_get_bits8(&gb, buf, buf_size_min);
+av_assert2(ret >= 0);
 
 s->key_frame = 1;
 s->pict_type = AV_PICTURE_TYPE_I;
-- 
2.43.2

___
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 5/7] avcodec/avs3_parser: Check the return value of init_get_bits8()

2024-05-01 Thread Michael Niedermayer
Fixes: CID1492867 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/avs3_parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avs3_parser.c b/libavcodec/avs3_parser.c
index a819b5783d6..0f9076befe1 100644
--- a/libavcodec/avs3_parser.c
+++ b/libavcodec/avs3_parser.c
@@ -73,7 +73,9 @@ static void parse_avs3_nal_units(AVCodecParserContext *s, 
const uint8_t *buf,
 GetBitContext gb;
 int profile, ratecode, low_delay;
 
-init_get_bits8(&gb, buf + 4, buf_size - 4);
+int ret = init_get_bits8(&gb, buf + 4, buf_size - 4);
+if (ret < 0)
+return;
 
 s->key_frame = 1;
 s->pict_type = AV_PICTURE_TYPE_I;
-- 
2.43.2

___
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 6/7] avcodec/cbs_av1: Avoid shift overflow

2024-05-01 Thread Michael Niedermayer
Fixes: CID1465488 Unintentional integer overflow

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/cbs_av1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 1d9ac5ab449..fb829960220 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -301,7 +301,7 @@ static int cbs_av1_write_increment(CodedBitstreamContext 
*ctx, PutBitContext *pb
 return AVERROR(ENOSPC);
 
 if (len > 0)
-put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
+put_bits(pbc, len, (1U << len) - 1 - (value != range_max));
 
 CBS_TRACE_WRITE_END_NO_SUBSCRIPTS();
 
-- 
2.43.2

___
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 7/7] avcodec/cbs_jpeg: Try to move the read entity to one side in a test

2024-05-01 Thread Michael Niedermayer
Fixes: CID1439654 Untrusted pointer read

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/cbs_jpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index b1b58dcd65e..406147c082c 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -146,13 +146,13 @@ static int cbs_jpeg_split_fragment(CodedBitstreamContext 
*ctx,
 }
 } else {
 i = start;
-if (i + 2 > frag->data_size) {
+if (i > frag->data_size - 2) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: "
"truncated at %02x marker.\n", marker);
 return AVERROR_INVALIDDATA;
 }
 length = AV_RB16(frag->data + i);
-if (i + length > frag->data_size) {
+if (length > frag->data_size - i) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: "
"truncated at %02x marker segment.\n", marker);
 return AVERROR_INVALIDDATA;
-- 
2.43.2

___
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/7] avcodec/av1dec: initialize ret in av1_receive_frame_internal()

2024-05-01 Thread James Almer

On 5/1/2024 9:41 PM, Michael Niedermayer wrote:

Fixes: CID1596605 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
  libavcodec/av1dec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4f9222cca27..93ab04eb378 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1262,7 +1262,7 @@ static int av1_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
  {
  AV1DecContext *s = avctx->priv_data;
  AV1RawTileGroup *raw_tile_group = NULL;
-int i = 0, ret;
+int i = 0, ret = 0;
  
  for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {

  CodedBitstreamUnit *unit = &s->current_obu.units[i];


Should be ok. Alternatively, we could set ret to AVERROR_BUG here and to 
0 in the places where it's missing (and that triggered coverity).

___
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 1/7] avcodec/av1dec: bit_depth cannot be another values than 8, 10, 12

2024-05-01 Thread James Almer

On 5/1/2024 9:41 PM, Michael Niedermayer wrote:

Fixes: CID1544265 Logically dead code

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
  libavcodec/av1dec.c | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 79a30a114da..4f9222cca27 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -493,7 +493,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
  else if (bit_depth == 12)
  pix_fmt = AV_PIX_FMT_YUV444P12;
  else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
  } else if (seq->color_config.subsampling_x == 1 &&
 seq->color_config.subsampling_y == 0) {
  if (bit_depth == 8)
@@ -503,7 +503,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
  else if (bit_depth == 12)
  pix_fmt = AV_PIX_FMT_YUV422P12;
  else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
  } else if (seq->color_config.subsampling_x == 1 &&
 seq->color_config.subsampling_y == 1) {
  if (bit_depth == 8)
@@ -513,7 +513,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
  else if (bit_depth == 12)
  pix_fmt = AV_PIX_FMT_YUV420P12;
  else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
  }
  } else {
  if (bit_depth == 8)
@@ -523,7 +523,7 @@ static enum AVPixelFormat get_sw_pixel_format(void *logctx,
  else if (bit_depth == 12)
  pix_fmt = AV_PIX_FMT_GRAY12;
  else
-av_log(logctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
+av_assert0(0);
  }
  
  return pix_fmt;


LGTM.

Can you change bit_depth into an int while at it? no reason for it to be 
uint8_t as a scalar.

___
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 3/7] avcodec/avfft: Remove dead code

2024-05-01 Thread Lynne
May 2, 2024, 02:42 by mich...@niedermayer.cc:

> Fixes: CID1543204 Logically dead code
>
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/avfft.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
> index f6787937f67..0f43f30b776 100644
> --- a/libavcodec/avfft.c
> +++ b/libavcodec/avfft.c
> @@ -158,7 +158,7 @@ RDFTContext *av_rdft_init(int nbits, enum 
> RDFTransformType trans)
>  return NULL;
>  }
>  
> -s->stride = (trans == DFT_C2R) ? sizeof(AVComplexFloat) : sizeof(float);
> +s->stride = sizeof(float);
>  s->len = 1 << nbits;
>  s->inv = trans == IDFT_C2R; 
>

That's not right.
While it's true that currently the stride parameter in av_tx_fn
is unused for RDFTs, that may not always be the case, and the
documentation requires that the stride is valid and set to the
value that the current implementation assumes, so that nothing
breaks once that is implemented.
___
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 3/7] avcodec/avfft: Remove dead code

2024-05-01 Thread Michael Niedermayer
On Thu, May 02, 2024 at 03:21:11AM +0200, Lynne wrote:
> May 2, 2024, 02:42 by mich...@niedermayer.cc:
> 
> > Fixes: CID1543204 Logically dead code
> >
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/avfft.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
> > index f6787937f67..0f43f30b776 100644
> > --- a/libavcodec/avfft.c
> > +++ b/libavcodec/avfft.c
> > @@ -158,7 +158,7 @@ RDFTContext *av_rdft_init(int nbits, enum 
> > RDFTransformType trans)
> >  return NULL;
> >  }
> >  
> > -s->stride = (trans == DFT_C2R) ? sizeof(AVComplexFloat) : 
> > sizeof(float);
> > +s->stride = sizeof(float);
> >  s->len = 1 << nbits;
> >  s->inv = trans == IDFT_C2R; 
> >
> 
> That's not right.
> While it's true that currently the stride parameter in av_tx_fn
> is unused for RDFTs, that may not always be the case, and the
> documentation requires that the stride is valid and set to the
> value that the current implementation assumes, so that nothing
> breaks once that is implemented.

i kind of had the same feeling but wanted to post it anyway.
so patch withdrawn, ill mark the issue as "intentional" in coverity

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


signature.asc
Description: PGP signature
___
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 7/7] avcodec/cbs_jpeg: Try to move the read entity to one side in a test

2024-05-01 Thread Andreas Rheinhardt
Michael Niedermayer:
> Fixes: CID1439654 Untrusted pointer read
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cbs_jpeg.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> index b1b58dcd65e..406147c082c 100644
> --- a/libavcodec/cbs_jpeg.c
> +++ b/libavcodec/cbs_jpeg.c
> @@ -146,13 +146,13 @@ static int 
> cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
>  }
>  } else {
>  i = start;
> -if (i + 2 > frag->data_size) {
> +if (i > frag->data_size - 2) {
>  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: "
> "truncated at %02x marker.\n", marker);
>  return AVERROR_INVALIDDATA;
>  }
>  length = AV_RB16(frag->data + i);
> -if (i + length > frag->data_size) {
> +if (length > frag->data_size - i) {
>  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid JPEG image: "
> "truncated at %02x marker segment.\n", marker);
>  return AVERROR_INVALIDDATA;

You should always mention when you are not fixing bugs in our code, but
rather intend to apply workaround for coverity crazyness (i.e. the
requirement that reading values in non-native endianness needs to be
sanitized).

- 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".