Re: [FFmpeg-devel] [PATCH 01/10, v3] avutil: add hwcontext_amf.

2024-05-30 Thread Dmitrii Ovchinnikov
I would appreciate your review.
Just to clarify: The information I provided is coming from AMF and driver
developers.
___
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, v3] avutil: add hwcontext_amf.

2024-05-30 Thread Dmitrii Ovchinnikov
DX12 and Vulkan native encoders will expose less features compare to AMF,

at least in foreseeable feature. The missing features include low latency,

PreAnalysis including look-ahead etc. AMF context on Windows allows fully

enable SAV - ability to utilize VCNs in dGPU and APU in a single session.

AMF components including encoder and decoder has some internal optimizations

in the area of memory access for APUs that are not available in standard

3D APIs.

Eventually specialized multimedia AMD cards could be added seamlessly to

FFmpeg with AMF integration.

AMF FSR(VSR) includes YUV version with focus on videos which is not

available in AMD FSR aimed for gaming.

More advanced filters that are not available in standard 3D APIs are coming.
___
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 02/10, v2] avcodec: add amfdec.

2024-05-30 Thread Dmitrii Ovchinnikov
>>I do not see a configure dependency of your AMF decoders on AMF
Thanks, apparently I always put it together with the encoder and therefore
did not get such an error. I'll fix the dependencies and check the options
without AMF.
___
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-30 Thread Dmitrii Ovchinnikov
>>This seems to have forgotten to actually allocate anything?
I made an empty allocation here, since in fact all allocation
takes place in the decoder.

>>This makes it look like you really wanted to implement map_from,
not transfer_data_from.
These functions were conceived specifically for transferring data
to and from the host memory. Memory mapping functions will probably
be added in the future.
>>libavutil cannot depend on libavformat, that would be circular.
In the new version, I have removed this and some other unnecessary includes.
(https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11968)

>>Some of these details look like they should be in the public
hwcontext so that a user can create one.
In the new version, I removed the additional class and put the
functions that the user might need in the header.
I hope everything is better now.
___
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 02/10, v2] avcodec: add amfdec.

2024-05-30 Thread Dmitrii Ovchinnikov
In the new version, I removed unnecessary includes and cleaned up the code
(https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11968).
It didn't seem to help. On my local computer build is successful in all
configurations that I have tried.
The file mentioned in the error is also already used in the encoder.
Could you share the log and output of the configure command?
I will try to understand the difference from my case.
___
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 08/10, v3] avcodec/amfenc: redesign to use hwcontext_amf.

2024-05-30 Thread Dmitrii Ovchinnikov
Co-authored-by: Evgeny Pavlov 
v3: cleanup code
---
 libavcodec/amfenc.c  | 573 +++
 libavcodec/amfenc.h  |  32 +--
 libavcodec/amfenc_av1.c  |   8 +-
 libavcodec/amfenc_h264.c |   8 +-
 libavcodec/amfenc_hevc.c |  14 +-
 5 files changed, 176 insertions(+), 459 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 510050e282..c57fa1b980 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(>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, >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, >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, >debug);
-

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

2024-05-30 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 f5bf475d13..78e87ff5f7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22791,6 +22791,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.
@@ -25528,6 +25598,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.39.3 (Apple 

[FFmpeg-devel] [PATCH 07/10, v3] avcodec/amfenc: add smart access video option

2024-05-30 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
--- 

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

2024-05-30 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 |  73 +
 libavfilter/vf_sr_amf.c | 189 +
 libavfilter/vf_vpp_amf.c| 264 ++
 7 files changed, 1047 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 96b181fd21..56d9bad3ee 100755
--- a/configure
+++ b/configure
@@ -3916,6 +3916,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 5992fd161f..8c8a9466a8 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -500,6 +500,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
@@ -553,6 +554,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..b842aae77a
--- /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 

[FFmpeg-devel] [PATCH 06/10, v3] avcodec/amfenc: GPU driver version check

2024-05-30 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.39.3 (Apple Git-146)

___
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 05/10, v3] avcodec/amfenc: add 10 bit encoding in av1_amf

2024-05-30 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.39.3 (Apple Git-146)

___
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 04/10, v3] avcodec/amfenc: HDR metadata.

2024-05-30 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), _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 03/10, v3] avcodec/amfenc: Fixes the color information in the output.

2024-05-30 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 

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

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

Added AMF based h264, hevc, av1 decoders.
Co-authored-by: Dmitrii Ovchinnikov 
v2: added encoder reinitialisation
v3: use AMF_SURFACE_UNKNOWN to int decoder(ctx->output_format before)
---
 libavcodec/Makefile|   7 +-
 libavcodec/allcodecs.c |   3 +
 libavcodec/amfdec.c| 696 +
 libavcodec/amfdec.h|  63 
 4 files changed, 767 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/amfdec.c
 create mode 100644 libavcodec/amfdec.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2443d2c6fd..69918903ff 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
@@ -409,6 +410,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
@@ -435,6 +437,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
@@ -1263,7 +1266,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 b102a8069e..d215c9f0d4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -834,10 +834,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;
@@ -847,6 +849,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..f365d3084c
--- /dev/null
+++ b/libavcodec/amfdec.c
@@ -0,0 +1,696 @@
+/*
+ * 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 warra

[FFmpeg-devel] [PATCH 01/10, v3] avutil: add hwcontext_amf.

2024-05-30 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 optimisations 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
v3: an unnecessary class has been removed.
---
 libavutil/Makefile |   4 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 585 +
 libavutil/hwcontext_amf.h  |  64 
 libavutil/hwcontext_amf_internal.h |  44 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   5 +
 9 files changed, 712 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
 _hwcontext_type_vulkan,
+#endif
+#if CONFIG_AMF
+_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..1c589669e1
--- /dev/null
+++ b/libavutil/hwcontext_amf.c
@@ -0,0 +1,585 @@
+/*
+ * 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

Re: [FFmpeg-devel] [PATCH 01/10, v2] avutil: add hwcontext_amf.

2024-05-02 Thread Dmitrii Ovchinnikov
>>Is there a reason to add this code in now?
DX12 and Vulkan native encoders will expose less features compare to AMF,
at least in foreseeable feature. The missing features include low latency,
PreAnalysis including look-ahead etc. AMF context on Windows allows fully
enable SAV - ability to utilize VCNs in dGPU and APU in a single session.
Eventually specialized multimedia AMD cards could be added seamlessly to
FFmpeg with AMF integration.
AMF FSR(VSR) includes YUV version with focus on videos which is not
available in AMD FSR aimed for gaming.

-- 
Sincerely, Ovchinnikov D.A.
___
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 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.
-- 

[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 

[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(>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, >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, >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, >debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static 

[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
--- 

[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 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 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), _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 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 

[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

[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
 _hwcontext_type_vulkan,
+#endif
+#if CONFIG_AMF
+_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
+ */
+
+#include 

Re: [FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf.

2024-02-14 Thread Dmitrii Ovchinnikov
>>AVAMFDeviceContextInternal *internal. Can't say if this is needed here
>>at all or not.
I have separated AVAMFDeviceContextInternal into a separate structure,
since it is also used in the decoder and encoder, even when
hwaccel amf is not used

>>These should probably take a AVAMFDeviceContext pointer.
they are also used from the decoder and encoder for initialization,
even when hwaccel amf is not used
I did this to avoid massive code duplication.

If you have any thoughts on how to improve this, it would be great.
For the rest of the comments, everything is clear,
I will correct and send an updated version.


-- 
Sincerely, Ovchinnikov D.A.
___
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 9/9] doc/filters: Add documentation for AMF filters

2024-02-13 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 e0436a5755..4c5b9c1f63 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21330,6 +21330,244 @@ If the specified expression is not valid, it is kept 
at its current
 value.
 @end table
 
+@anchor{scale_amf}
+@section scale_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
+scale_amf=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K and change color profile to bt2020.
+@example
+scale_amf=4096:2160:color_profile=bt2020
+@end example
+@end itemize
+
+@anchor{scale_amf_hq}
+@section scale_amf_hq
+
+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
+scale_amf_hq=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K with algorithm video SR1.1.
+@example
+scale_amf_hq=4096:2160:algorithm=sr1-1
+@end example
+@end itemize
+
 @anchor{scale_cuda}
 @section scale_cuda
 
-- 
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 8/9] avfilter/scale_amf: Add AMF HW scaler & color converter

2024-02-13 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

This commit adds two AMF filters: scale_amf & scale_amf_hq.
Both filters are using AMF hardware acceleration.
scale_amf supports simple scaling algorithms & color conversion.
scale_amf_hq supports advanced scaling algorithms & might be used
for upscaling only.

Signed-off-by: Evgeny Pavlov 
---
 configure |   1 +
 libavfilter/Makefile  |   2 +
 libavfilter/allfilters.c  |   2 +
 libavfilter/vf_scale_amf.c| 266 +++
 libavfilter/vf_scale_amf_common.c | 515 ++
 libavfilter/vf_scale_amf_common.h |  71 
 libavfilter/vf_scale_amf_hq.c | 191 +++
 7 files changed, 1048 insertions(+)
 create mode 100644 libavfilter/vf_scale_amf.c
 create mode 100644 libavfilter/vf_scale_amf_common.c
 create mode 100644 libavfilter/vf_scale_amf_common.h
 create mode 100644 libavfilter/vf_scale_amf_hq.c

diff --git a/configure b/configure
index f72533b7d2..3d1c44d7ae 100755
--- a/configure
+++ b/configure
@@ -3826,6 +3826,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 f6c1d641d6..a87e519b85 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -456,6 +456,8 @@ OBJS-$(CONFIG_ROBERTS_OPENCL_FILTER) += 
vf_convolution_opencl.o opencl.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
 OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale_eval.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf.o scale_eval.o 
vf_scale_amf_common.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf_hq.o scale_eval.o 
vf_scale_amf_common.o
 OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o scale_eval.o \
 vf_scale_cuda.ptx.o 
cuda/load_helper.o
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale_eval.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 149bf50997..299cfb148b 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_scale_amf;
+extern const AVFilter ff_vf_scale_amf_hq;
 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_scale_amf.c b/libavfilter/vf_scale_amf.c
new file mode 100644
index 00..6d2c211d83
--- /dev/null
+++ b/libavfilter/vf_scale_amf.c
@@ -0,0 +1,266 @@
+/*
+ * 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
+ */
+
+/**
+ * @file
+ * scale video filter - AMF
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_amf.h"
+
+#include "AMF/components/VideoConverter.h"
+#include "vf_scale_amf_common.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "video.h"
+#include "scale_eval.h"
+#include "internal.h"
+
+#if CONFIG_DXVA2
+#include 
+#endif
+
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+static int amf_scale_query_formats(AVFilterContext *avctx)
+{
+const enum AVPixelFormat *output_pix_fmts;
+static const enum AVPixelFormat input_pix_fmts[] = {
+AV_PIX_FMT_NV12,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_0RGB,
+AV_PIX_FMT_BGR0,
+AV_PIX_FMT_BGRA,
+AV_PIX_FMT_RGB0,
+AV_PIX_FMT_RGBA,
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_YUV420P,
+AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUYV422,
+AV_PIX_FMT_AMF,
+AV_PIX_FMT_NONE,
+};
+static const enum AVPixelFormat output_pix_fmts_default[] = {
+AV_PIX_FMT_AMF,
+AV_PIX_FMT_D3D11,
+AV_PIX_FMT_DXVA2_VLD,
+AV_PIX_FMT_NV12,
+

[FFmpeg-devel] [PATCH 7/9] libavcodec/amfenc: redesign to use hwcontext_amf.

2024-02-13 Thread Dmitrii Ovchinnikov
Co-authored-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c | 560 
 libavcodec/amfenc.h |  23 +-
 2 files changed, 158 insertions(+), 425 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index f1b76bd6aa..e6e5302cca 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -29,6 +29,7 @@
 #define COBJMACROS
 #include "libavutil/hwcontext_dxva2.h"
 #endif
+#include "libavutil/hwcontext_amf.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -38,6 +39,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 +101,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 +110,18 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_AMF,
 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(>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, >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, >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, >debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 

[FFmpeg-devel] [PATCH 6/9] avcodec/amfenc: add smart access video option

2024-02-13 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 9b32616aa8..109533fb2d 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 f785e091c9..f83a9fcaa7 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 8c6401c646..f3caa7cb29 100644
--- 

[FFmpeg-devel] [PATCH 5/9] avcodec/amfenc: add 10 bit encoding in av1_amf

2024-02-13 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

v2: refactored after review

Signed-off-by: Evgeny Pavlov 
Co-authored-by: Dmitrii Ovchinnikov 
---
 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..f1b76bd6aa 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -826,6 +826,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;
 }
 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
 }
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 3f164ccc59..9b32616aa8 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 4/9] avcodec/amfenc: HDR metadata.

2024-02-13 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), _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 3/9] avcodec/amfenc: Fixes the color information in the output.

2024-02-13 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 
---
 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 bd544d12df..f785e091c9 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 (Partial/TV/MPEG or Full/PC/JPEG)
- 

[FFmpeg-devel] [PATCH 2/9] libavcodec: add amfdec.

2024-02-13 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

Added AMF based h264, hevc, av1 decoders.
Co-authored-by: Dmitrii Ovchinnikov 
---
 libavcodec/Makefile |   4 +-
 libavcodec/allcodecs.c  |   3 +
 libavcodec/amfdec.c | 667 
 libavcodec/amfdec.h |  75 +
 libavcodec/h264_slice.c |   3 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwconfig.h   |   2 +
 7 files changed, 755 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/amfdec.c
 create mode 100644 libavcodec/amfdec.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 470d7cb9b1..c2e4715f4b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -69,7 +69,7 @@ include $(SRC_PATH)/libavcodec/x86/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
@@ -1265,7 +1265,7 @@ SKIPHEADERS+= %_tablegen.h
  \
   vulkan_video_codec_av1std.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 ef8c3a6d7d..c344c70e00 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -851,10 +851,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;
@@ -864,6 +866,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..9d618ff442
--- /dev/null
+++ b/libavcodec/amfdec.c
@@ -0,0 +1,667 @@
+/*
+ * 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 
+#include 
+#include 
+#include "libavutil/hwcontext_amf.h"
+#include "amfdec.h"
+#include "codec_internal.h"
+#include "hwconfig.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/time.h"
+#include "decode.h"
+#include "libavutil/mastering_display_metadata.h"
+
+#if CONFIG_D3D11VA
+#include "libavutil/hwcontext_d3d11va.h"
+#endif
+#if CONFIG_DXVA2
+#define COBJMACROS
+#include "libavutil/hwcontext_dxva2.h"
+#endif
+
+#ifdef _WIN32
+#include "compat/w32dlfcn.h"
+#else
+#include 
+#endif
+
+#define propNotFound 0
+
+const enum AVPixelFormat amf_dec_pix_fmts[] = {
+AV_PIX_FMT_YUV420P,
+AV_PIX_FMT_NV12,
+AV_PIX_FMT_BGRA,
+AV_PIX_FMT_ARGB,
+AV_PIX_FMT_RGBA,
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_BGR0,
+AV_PIX_FMT_YUYV422,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_P012,
+AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUV420P12,
+AV_PIX_FMT_YUV420P16,
+#if CONFIG_D3D11VA
+AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
+#endif
+AV_PIX_FMT_

[FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf.

2024-02-13 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.
---
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 580 +
 libavutil/hwcontext_amf.h  | 105 ++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   4 +
 8 files changed, 702 insertions(+)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e7709b97d0..785af8e926 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\
@@ -195,6 +196,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
@@ -219,6 +221,7 @@ 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
 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 e23bad230f..8c53fc1862 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -65,6 +65,9 @@ static const HWContextType * const hw_table[] = {
 #endif
 #if CONFIG_VULKAN
 _hwcontext_type_vulkan,
+#endif
+#if CONFIG_AMF
+_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",
 };
 
 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 2b33721a97..53292ea67f 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,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
new file mode 100644
index 00..6f43780dc5
--- /dev/null
+++ b/libavutil/hwcontext_amf.c
@@ -0,0 +1,580 @@
+/*
+ * 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 "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_amf.h"
+#include "hwcontext_internal.h"
+#if CONFIG_VULKAN
+#include "hwcontext_vulkan.h"
+#endif

Re: [FFmpeg-devel] [PATCH 7/7] fftools/ffplay: support applying container level cropping

2024-01-17 Thread Dmitrii Ovchinnikov
I tested these patches with the AMF AV1 encoder(by adding
AV_PKT_DATA_FRAME_CROPPING)
It works fine.

I suggest a small change to the code for better safety. Change this part:
>>if (sd->data && sd->size == sizeof(uint32_t) * 4) {
to:
if (sd && sd->data && sd->size == sizeof(uint32_t) * 4) {

This change helps avoid crashes when the cropping data isn't filled in.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/amd: fix pict_type, match it with amf & ffmpeg. add sps pps when frame->keyframe

2023-11-30 Thread Dmitrii Ovchinnikov
The idea itself looks good to me, but the patch is corrupted.

Regarding the patch:
1)
>>// Keyframe overrides previous assignment.
It might be better instead of:
setting the frame type -> if key frame then overwrite
to do:
check for key frame and if it's not, set other PICTURE_TYPE
to avoid unnecessary overwriting
(use AV_FRAME_FLAG_KEY instead of deprecated key_frame,
as already noted under the second patch)
2) The patch includes logic for AV_CODEC_ID_H264 and AV_CODEC_ID_HEVC,
but not for AV_CODEC_ID_AV1.( FORCE_INSERT_SEQUENCE_HEADER
 AMF_VIDEO_ENCODER_AV1_FORCE_FRAME_TYPE )
___
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] avcodec/amfenc: add smart access video option

2023-11-26 Thread Dmitrii Ovchinnikov
>> The code looks significantly duplicated.

This is not moved to amfenc.c since the property has different names
 for different encoders, and many other properties (also common to
different encoders, but with different names) are separated in this way.
___
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] avcodec/amfenc: add smart access video option

2023-11-24 Thread Dmitrii Ovchinnikov
 If there are no objections, I would like to merge it in 2-3 days
___
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] libavcodec/amfenc: Fix issue with missing headers in AV1 encoder

2023-10-31 Thread Dmitrii Ovchinnikov
This is a trivial patch that fixes the bug. If there are no objections, I
would like to merge it in 2-3 days
___
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, v3] libavcodec/amfenc: add PreAnalysis support

2023-05-17 Thread Dmitrii Ovchinnikov
Additional information about the work of preanalysis can be found here:
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/wiki/PreProcessing%20and%20PreAnalysis
---
 libavcodec/amfenc.c  | 101 +++--
 libavcodec/amfenc.h  |  27 +-
 libavcodec/amfenc_av1.c  | 133 ++--
 libavcodec/amfenc_h264.c | 187 ++-
 libavcodec/amfenc_hevc.c | 144 +++---
 5 files changed, 503 insertions(+), 89 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index c487fc48aa..cb48f8c273 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -481,7 +481,7 @@ static int amf_copy_buffer(AVCodecContext *avctx, AVPacket 
*pkt, AMFBuffer *buff
 AVERROR_UNKNOWN, "timestamp_list is empty\n");
 
 // calc dts shift if max_b_frames > 0
-if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
+if ((ctx->max_b_frames > 0 || ((ctx->pa_adaptive_mini_gop == 1) ? true : 
false)) && ctx->dts_delay == 0) {
 int64_t timestamp_last = AV_NOPTS_VALUE;
 size_t can_read = av_fifo_can_read(ctx->timestamp_list);
 
@@ -593,6 +593,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMFData*data = NULL;
 AVFrame*frame = ctx->delayed_frame;
 int block_and_wait;
+int query_output_data_flag = 0;
+AMF_RESULT  res_resubmit;
 
 if (!ctx->encoder)
 return AVERROR(EINVAL);
@@ -715,56 +717,61 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 do {
 block_and_wait = 0;
 // poll data
-res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, );
-if (data) {
-// copy data to packet
-AMFBuffer* buffer;
-AMFGuid guid = IID_AMFBuffer();
-data->pVtbl->QueryInterface(data, , (void**)); // 
query for buffer interface
-ret = amf_copy_buffer(avctx, avpkt, buffer);
-
-buffer->pVtbl->Release(buffer);
-
-if (data->pVtbl->HasProperty(data, L"av_frame_ref")) {
-AMFBuffer *frame_ref_storage_buffer;
-res = amf_get_property_buffer(data, L"av_frame_ref", 
_ref_storage_buffer);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"GetProperty failed for \"av_frame_ref\" with error %d\n", res);
-amf_release_buffer_with_frame_ref(frame_ref_storage_buffer);
-ctx->hwsurfaces_in_queue--;
-}
-
-data->pVtbl->Release(data);
+if (!avpkt->data && !avpkt->buf) {
+res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder, );
+if (data) {
+query_output_data_flag = 1;
+// copy data to packet
+AMFBuffer *buffer;
+AMFGuid guid = IID_AMFBuffer();
+data->pVtbl->QueryInterface(data, , (void**)); // 
query for buffer interface
+ret = amf_copy_buffer(avctx, avpkt, buffer);
+
+buffer->pVtbl->Release(buffer);
+
+if (data->pVtbl->HasProperty(data, L"av_frame_ref")) {
+AMFBuffer* frame_ref_storage_buffer;
+res = amf_get_property_buffer(data, L"av_frame_ref", 
_ref_storage_buffer);
+AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"GetProperty failed for \"av_frame_ref\" with error %d\n", res);
+
amf_release_buffer_with_frame_ref(frame_ref_storage_buffer);
+ctx->hwsurfaces_in_queue--;
+}
 
-AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret, "amf_copy_buffer() failed 
with error %d\n", ret);
+data->pVtbl->Release(data);
 
-if (ctx->delayed_surface != NULL) { // try to resubmit frame
-res = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, 
(AMFData*)ctx->delayed_surface);
-if (res != AMF_INPUT_FULL) {
-int64_t pts = 
ctx->delayed_surface->pVtbl->GetPts(ctx->delayed_surface);
-ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
-ctx->delayed_surface = NULL;
-av_frame_unref(ctx->delayed_frame);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"Repeated SubmitInput() failed with error %d\n", res);
+AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret, "amf_copy_buffer() 
failed with error %d\n", ret);
+}
+}
+res_resubmit = AMF_OK;
+if (ctx->delayed_surface != NULL) { // try to resubmit frame
+res_resubmit = ctx->encoder->pVtbl->SubmitInput(ctx->encoder, 
(AMFData*)ctx->delayed_surface);
+if (res_resubmit != AMF_INPUT_FULL) {
+int64_t pts = 
ctx->delayed_surface->pVtbl->GetPts(ctx->delayed_surface);
+ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
+

[FFmpeg-devel] [PATCH 1/2, v3] amfenc: Update the min version to 1.4.29.0 for AMF SDK.

2023-05-17 Thread Dmitrii Ovchinnikov
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index bb7be67676..937be943a4 100755
--- a/configure
+++ b/configure
@@ -7082,7 +7082,7 @@ fi
 
 enabled amf &&
 check_cpp_condition amf "AMF/core/Version.h" \
-"(AMF_VERSION_MAJOR << 48 | AMF_VERSION_MINOR << 32 | 
AMF_VERSION_RELEASE << 16 | AMF_VERSION_BUILD_NUM) >= 0x00010004001c"
+"(AMF_VERSION_MAJOR << 48 | AMF_VERSION_MINOR << 32 | 
AMF_VERSION_RELEASE << 16 | AMF_VERSION_BUILD_NUM) >= 0x00010004001d"
 
 # Funny iconv installations are not unusual, so check it after all flags have 
been set
 if enabled libc_iconv; then
-- 
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".


Re: [FFmpeg-devel] I have an issue when try to using h264_amf encoding rtsp stream

2023-04-29 Thread Dmitrii Ovchinnikov
could you also try adding one more parameter and try again?

*  -header_spacing 30*it should have the same value as  -g in commandline.
For example:  *ffmpeg -i input.mkv  -c:v h264_amf  -g 30 -header_spacing 30
output.mp4*

ср, 19 апр. 2023 г. в 07:15, 罗勇刚(Yonggang Luo) :

> thanks, I have already tried the top size 1 and 10 before on the enconder,
> I assume you are talking about the encoder, as the decoder can not config
> the gop size, I think it's should be a bug of and encoder or decoder,
> because if I start the decoder before amf encoder, it's working fine, it is
> either because the encoder only encode the first I frame properly or the
> decoder can not recognize the I frame generated by amf encoder.
>
> Dmitrii Ovchinnikov  于 2023年4月19日周三
> 01:55写道:
>
> > For libx264 the default gop size is 10, while for amf the default gop
> size
> > is 250. I suspect this is the reason.
> > Try adding the following parameter  “* -g 10* ” when using amf encoder.
> > This parameter will set gop size to 10.
> >
> > вт, 11 апр. 2023 г. в 09:42, 罗勇刚(Yonggang Luo) :
> >
> > > When using libx264:
> > > The pull result is:
> > > ```
> > > C:\work\xtal\xtal-video\ffmpeg-6.0-full_build-shared\bin>ffplay
> > -max_delay
> > > 0 -max_probe_packets 1 -analyzeduration 0 -flags +low_delay -fflags
> > > +nobuffer -protocol_whitelist file,udp,rtp rtp_h264_30003.sdp
> > > ffplay version 6.0-full_build-www.gyan.dev Copyright (c) 2003-2023 the
> > > FFmpeg developers
> > >   built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
> > >   configuration: --enable-gpl --enable-version3 --enable-shared
> > > --disable-w32threads --disable-autodetect --enable-fontconfig
> > > --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp
> > --enable-bzlib
> > > --enable-lzma --enable-libsnappy --enable-zlib --enable-librist
> > > --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
> > > --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24
> > > --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi
> > > --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264
> > > --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom
> > > --enable-libjxl --enable-libopenjpeg --enable-libvpx
> > > --enable-mediafoundation --enable-libass --enable-frei0r
> > > --enable-libfreetype --enable-libfribidi --enable-liblensfun
> > > --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf
> > > --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec
> > > --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl
> > > --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl
> > > --enable-libcdio --enable-libgme --enable-libmodplug
> --enable-libopenmpt
> > > --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine
> > > --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc
> > > --enable-libilbc --enable-libgsm --enable-libopencore-amrnb
> > > --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa
> > > --enable-libbs2b --enable-libflite --enable-libmysofa
> > > --enable-librubberband --enable-libsoxr --enable-chromaprint
> > >   libavutil  58.  2.100 / 58.  2.100
> > >   libavcodec 60.  3.100 / 60.  3.100
> > >   libavformat60.  3.100 / 60.  3.100
> > >   libavdevice60.  1.100 / 60.  1.100
> > >   libavfilter 9.  3.100 /  9.  3.100
> > >   libswscale  7.  1.100 /  7.  1.100
> > >   libswresample   4. 10.100 /  4. 10.100
> > >   libpostproc57.  1.100 / 57.  1.100
> > > Input #0, sdp, from 'rtp_h264_30003.sdp':=0KB sq=0B f=0/0
> > >   Duration: N/A, start: -0.017911, bitrate: N/A
> > >   Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1060, 50
> > fps,
> > > 50 tbr, 90k tbn
> > >3.79 M-V:  3.731 fd=   0 aq=0KB vq=0KB sq=0B f=0/0
> > > ```
> > >
> > > But when using h264_amf:
> > > ```
> > >
> > > C:\work\xtal\xtal-video\ffmpeg-6.0-full_build-shared\bin>ffplay
> > -max_delay
> > > 0 -max_probe_packets 1 -analyzeduration 0 -flags +low_delay -fflags
> > > +nobuffer -protocol_whitelist file,udp,rtp rtp_h264_30003.sdp
> > > ffplay version 6.0-full_build-www.gyan.dev Copyright (c) 2003-2023 the
> > > FFmpeg developers
> > >   built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
> > >   configuration: --enable-gpl --enable-version3 --enable-s

[FFmpeg-devel] [PATCH v3] lavc/libvpx: remove thread limit

2023-01-05 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

This change improves the performance and multicore
 scalability of the vp9 codec for streaming single-pass encoded videos. The
 current thread limit for ffmpeg codecs is 16 (MAX_AUTO_THREADS in
 pthread_internal.h) due to a limitation in H.264 codec that prevents more
 than 16 threads being used.

Increasing the thread limit to 64 for vp9 improves
the performance for encoding 4K raw videos for streaming by up to 47%
compared to 16 threads, and from 20-30% for 32 threads, with the same quality
as measured by the VMAF score.

Did not need to add a check for limit in libvpx as it is already present 
in libvpx/vp9/vp9_cx_iface.c:
  RANGE_CHECK_HI(cfg, g_threads, 64);
As demonstrated by following message when -threads is set to anything more than 
64
[libvpx-vp9 @ 0x30ed380]   Additional information: g_threads out of range [..64]

---
 libavcodec/libvpxdec.c | 2 +-
 libavcodec/libvpxenc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
index 9cd2c56caf..19407092d0 100644
--- a/libavcodec/libvpxdec.c
+++ b/libavcodec/libvpxdec.c
@@ -88,7 +88,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 const struct vpx_codec_iface *iface)
 {
 struct vpx_codec_dec_cfg deccfg = {
-.threads = FFMIN(avctx->thread_count ? avctx->thread_count : 
av_cpu_count(), 16)
+.threads = avctx->thread_count ? avctx->thread_count : av_cpu_count()
 };
 
 av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 9aa5510c28..0627e13973 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 enccfg.g_timebase.num = avctx->time_base.num;
 enccfg.g_timebase.den = avctx->time_base.den;
 enccfg.g_threads  =
-FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16);
+avctx->thread_count ? avctx->thread_count : av_cpu_count();
 enccfg.g_lag_in_frames= ctx->lag_in_frames;
 
 if (avctx->flags & AV_CODEC_FLAG_PASS1)
-- 
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".


Re: [FFmpeg-devel] [PATCH 1/2] amfenc: Update the min version to 1.4.28.0 for AMF SDK.

2022-12-20 Thread Dmitrii Ovchinnikov
Hi,

>>When was this release released?
The release was 13.12.2022
>> Is it headers only or is it runtime too?
it still supports old drivers, but to use the av1 encoder, you need an
up-to-date driver version and a supported graphics card.
___
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] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer.

2022-12-20 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

In webm specification, it supports cropping information. 
(https://www.webmproject.org/docs/container/)
In ffmpeg, the implementation of webm is a subset of matroska. In 
matroskadec.c, those cropping related four fields are forced to 0.

for the sample file with crop (crop_bottom =8, crop_top=crop_left=crop_right=0.)
ffmpeg.exe -i  test_with_container_crop.webm -pix_fmt yuv420p -y output.yuv

original ffmpeg code - the output.yuv resolution is 1920x1088
changed code - the output.yuv resolution is 1920x1080

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..2023fd4977 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -210,6 +210,10 @@ typedef struct MatroskaTrackVideo {
 uint64_t pixel_width;
 uint64_t pixel_height;
 EbmlBin  color_space;
+uint64_t pixel_cropt;
+uint64_t pixel_cropl;
+uint64_t pixel_cropb;
+uint64_t pixel_cropr;
 uint64_t display_unit;
 uint64_t interlaced;
 uint64_t field_order;
@@ -517,10 +521,10 @@ static EbmlSyntax matroska_track_video[] = {
 { MATROSKA_ID_VIDEOALPHAMODE,  EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } },
 { MATROSKA_ID_VIDEOCOLOR,  EBML_NEST,  0, 
sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = 
matroska_track_video_color } },
 { MATROSKA_ID_VIDEOPROJECTION, EBML_NEST,  0, 0, 
offsetof(MatroskaTrackVideo, projection), { .n = 
matroska_track_video_projection } },
-{ MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
-{ MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
+{ MATROSKA_ID_VIDEOPIXELCROPT, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPL, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPB, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+{ MATROSKA_ID_VIDEOPIXELCROPR, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } },
 { MATROSKA_ID_VIDEODISPLAYUNIT,EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, display_unit), { .u= 
MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
 { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, interlaced),  { .u = 
MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
 { MATROSKA_ID_VIDEOFIELDORDER, EBML_UINT,  0, 0, 
offsetof(MatroskaTrackVideo, field_order), { .u = 
MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
@@ -2879,6 +2883,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
 st->codecpar->width  = track->video.pixel_width;
 st->codecpar->height = track->video.pixel_height;
 
+st->codecpar->container_crop_top= track->video.pixel_cropt;
+st->codecpar->container_crop_left   = track->video.pixel_cropl;
+st->codecpar->container_crop_bottom = track->video.pixel_cropb;
+st->codecpar->container_crop_right  = track->video.pixel_cropr;
+
 if (track->video.interlaced == 
MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
 st->codecpar->field_order = mkv_field_order(matroska, 
track->video.field_order);
 else if (track->video.interlaced == 
MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
-- 
2.30.0.windows.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] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop

2022-12-20 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

Support both simple and receive_frame api
The container crop information is applied additional to frame crop information
---
 libavcodec/codec_par.c | 30 ++-
 libavcodec/decode.c| 54 ++
 2 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index abda649aa8..9738402434 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -115,17 +115,21 @@ int avcodec_parameters_from_context(AVCodecParameters 
*par,
 
 switch (par->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
-par->format  = codec->pix_fmt;
-par->width   = codec->width;
-par->height  = codec->height;
-par->field_order = codec->field_order;
-par->color_range = codec->color_range;
-par->color_primaries = codec->color_primaries;
-par->color_trc   = codec->color_trc;
-par->color_space = codec->colorspace;
-par->chroma_location = codec->chroma_sample_location;
-par->sample_aspect_ratio = codec->sample_aspect_ratio;
-par->video_delay = codec->has_b_frames;
+par->format= codec->pix_fmt;
+par->width = codec->width;
+par->height= codec->height;
+par->container_crop_top= codec->container_crop_top;
+par->container_crop_left   = codec->container_crop_left;
+par->container_crop_bottom = codec->container_crop_bottom;
+par->container_crop_right  = codec->container_crop_right;
+par->field_order   = codec->field_order;
+par->color_range   = codec->color_range;
+par->color_primaries   = codec->color_primaries;
+par->color_trc = codec->color_trc;
+par->color_space   = codec->colorspace;
+par->chroma_location   = codec->chroma_sample_location;
+par->sample_aspect_ratio   = codec->sample_aspect_ratio;
+par->video_delay   = codec->has_b_frames;
 break;
 case AVMEDIA_TYPE_AUDIO:
 par->format   = codec->sample_fmt;
@@ -199,6 +203,10 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
 codec->pix_fmt= par->format;
 codec->width  = par->width;
 codec->height = par->height;
+codec->container_crop_top = par->container_crop_top;
+codec->container_crop_left= par->container_crop_left;
+codec->container_crop_bottom  = par->container_crop_bottom;
+codec->container_crop_right   = par->container_crop_right;
 codec->field_order= par->field_order;
 codec->color_range= par->color_range;
 codec->color_primaries= par->color_primaries;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..9e44fcb293 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -693,6 +693,60 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame 
*frame)
 if (!avctx->apply_cropping)
 return 0;
 
+if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_ADDITION)
+{
+/*check if container parameter and elementary streaming cropping 
parameters are saft for apploying  */
+if (avctx->container_crop_left + frame->crop_left >= INT_MAX - 
(avctx->container_crop_right + frame->crop_right) ||
+avctx->container_crop_top + frame->crop_top >= INT_MAX - 
(avctx->container_crop_bottom + frame->crop_bottom) ||
+(avctx->container_crop_left + frame->crop_left + 
avctx->container_crop_right + frame->crop_right) >= frame->width ||
+(avctx->container_crop_top + frame->crop_top + 
avctx->container_crop_bottom + frame->crop_bottom) >= frame->height) {
+av_log(avctx, AV_LOG_WARNING,
+"Apply container and elementary stream corpping parametes 
error: "
+"container cropping paramters "
+"%d/%d/%d/%d "
+"elementary stream croping paramters "
+
"%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
+"(frame size %dx%d). This is a bug, please report it\n",
+avctx->container_crop_left, avctx->container_crop_right, 
avctx->container_crop_top, avctx->container_crop_bottom,
+frame->crop_left, frame->crop_right, frame->crop

[FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

2022-12-20 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

---
 libavcodec/avcodec.h   | 35 +++
 libavcodec/codec_par.h |  8 
 libavcodec/options_table.h |  4 
 3 files changed, 47 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..57b340c24d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -380,6 +380,19 @@ typedef struct RcOverride{
  */
 #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
 
+/**
+* Video decoding only. Certain container support cropping, meaning that
+* only a sub-rectangle of the decoded frame is intended for display.
+* Certain codec supports cropping as well.This option controls how
+* cropping is handled by libavcodec when  container cropping and
+* codec cropping exist.
+*/
+enum CONTAINER_CROPPING_POLICY_TYPE {
+FF_CONTAINER_CROPPING_IGNORE = 0,
+FF_CONTAINER_CROPPING_ADDITION,
+FF_CONTAINER_CROPPING_OVERWRITE
+};
+
 struct AVCodecInternal;
 
 /**
@@ -2057,6 +2070,28 @@ typedef struct AVCodecContext {
  * The decoder can then override during decoding as needed.
  */
 AVChannelLayout ch_layout;
+
+/* When set to 1 (the default), libavcodec will apply container cropping
+ * to codec cropping additionally.
+ *
+ * When set to 2, libavcodec will use container cropping to overwrite
+ * codec cropping (the final cropping uses container cropping parameters)
+ *
+ * When set to 0, libavcodec will ignore container cropping parameters
+ * (the final cropping uses codec cropping parameters)
+ *
+ * This field works with "apply_cropping". Only if apply_cropping is 1, 
this
+ * field works
+ */
+enum CONTAINER_CROPPING_POLICY_TYPE container_apply_cropping;
+
+/**
+ * The cropping parameters from container.
+ */
+int container_crop_top;
+int container_crop_left;
+int container_crop_bottom;
+int container_crop_right;
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index f51d27c590..cc0695689c 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -211,6 +211,14 @@ typedef struct AVCodecParameters {
  * Audio only. The channel layout and number of channels.
  */
 AVChannelLayout ch_layout;
+
+/**
+ * The cropping parameters from container.
+ */
+int container_crop_top;
+int container_crop_left;
+int container_crop_bottom;
+int container_crop_right;
 } AVCodecParameters;
 
 /**
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index cd02f5096f..fd1ef21f90 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -401,6 +401,10 @@ static const AVOption avcodec_options[] = {
 {"allow_profile_mismatch", "attempt to decode anyway if HW accelerated 
decoder's supported profiles do not exactly match the stream", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, 
INT_MAX, V | D, "hwaccel_flags"},
 {"extra_hw_frames", "Number of extra hardware frames to allocate for the 
user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
V|D },
 {"discard_damaged_percentage", "Percentage of damaged samples to discard a 
frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 
100, V|D },
+{ "container_apply_cropping", "ploicy using container cropping parameters", 
OFFSET(container_apply_cropping), AV_OPT_TYPE_INT64, {.i64 = 
FF_CONTAINER_CROPPING_ADDITION }, 0, 2, V | D, "container_apply_cropping" },
+{ "ignore","ignore container cropping",
   0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_IGNORE },0, 0, V 
| D, "container_apply_cropping" },
+{ "addition",  "apply container cropping additionally to elementary stream 
cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_ADDITION },  0, 
0, V | D, "container_apply_cropping" },
+{ "overwrite", "use container cropping to overwrite elementary stream 
cropping",  0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_OVERWRITE 
}, 0, 0, V | D, "container_apply_cropping" },
 {NULL},
 };
 
-- 
2.30.0.windows.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/2] libavcodec/amfenc: add AV1 encoding support

2022-12-20 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

---
 configure   |   1 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/amfenc.c |   9 +
 libavcodec/amfenc.h |   6 +
 libavcodec/amfenc_av1.c | 361 
 6 files changed, 379 insertions(+)
 create mode 100644 libavcodec/amfenc_av1.c

diff --git a/configure b/configure
index 8a20d67612..56c959012e 100755
--- a/configure
+++ b/configure
@@ -3255,6 +3255,7 @@ wmv3_crystalhd_decoder_select="crystalhd"
 av1_qsv_decoder_select="qsvdec"
 av1_qsv_encoder_select="qsvenc"
 av1_qsv_encoder_deps="libvpl"
+av1_amf_encoder_deps="amf"
 
 # parsers
 aac_parser_select="adts_header mpeg4audio"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 98841ed07c..25686c2991 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -163,6 +163,7 @@ OBJS-$(CONFIG_TEXTUREDSP)  += texturedsp.o
 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_VC1DSP)  += vc1dsp.o
 OBJS-$(CONFIG_VIDEODSP)+= videodsp.o
 OBJS-$(CONFIG_VP3DSP)  += vp3dsp.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d5a6c427e1..d7d83be293 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -831,6 +831,7 @@ extern const FFCodec ff_av1_cuvid_decoder;
 extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
+extern const FFCodec ff_av1_amf_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index a033e1220e..c487fc48aa 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -349,6 +349,9 @@ static int amf_init_encoder(AVCodecContext *avctx)
 case AV_CODEC_ID_HEVC:
 codec_id = AMFVideoEncoder_HEVC;
 break;
+case AV_CODEC_ID_AV1 :
+codec_id = AMFVideoEncoder_AV1;
+break;
 default:
 break;
 }
@@ -460,6 +463,11 @@ static int amf_copy_buffer(AVCodecContext *avctx, AVPacket 
*pkt, AMFBuffer *buff
 pkt->flags = AV_PKT_FLAG_KEY;
 }
 break;
+case AV_CODEC_ID_AV1:
+buffer->pVtbl->GetProperty(buffer, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE, );
+if (var.int64Value == AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE_KEY) 
{
+pkt->flags = AV_PKT_FLAG_KEY;
+}
 default:
 break;
 }
@@ -681,6 +689,7 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 case AV_CODEC_ID_HEVC:
 AMF_ASSIGN_PROPERTY_INT64(res, surface, 
AMF_VIDEO_ENCODER_HEVC_INSERT_AUD, !!ctx->aud);
 break;
+//case AV_CODEC_ID_AV1 not supported
 default:
 break;
 }
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 1ab98d2f78..66e0680719 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -23,6 +23,7 @@
 
 #include 
 #include 
+#include 
 
 #include "libavutil/fifo.h"
 
@@ -116,6 +117,11 @@ typedef struct AmfContext {
 int min_qp_p;
 int max_qp_p;
 int tier;
+
+// AV1 - specific options
+
+enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align;
+
 } AmfContext;
 
 extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
new file mode 100644
index 00..6065ce43d9
--- /dev/null
+++ b/libavcodec/amfenc_av1.c
@@ -0,0 +1,361 @@
+/*
+ * 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/internal.h"
+#include "libavutil/opt.h"
+#include "amfenc.h"
+#include "codec_internal.h"
+#include "internal.h"
+
+#define OFFSET(x) offsetof(AmfContext, x)
+#define VE AV_OPT_FLAG

[FFmpeg-devel] [PATCH 1/2] amfenc: Update the min version to 1.4.28.0 for AMF SDK.

2022-12-20 Thread Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov 

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 2180ebb4f1..8a20d67612 100755
--- a/configure
+++ b/configure
@@ -7034,7 +7034,7 @@ fi
 
 enabled amf &&
 check_cpp_condition amf "AMF/core/Version.h" \
-"(AMF_VERSION_MAJOR << 48 | AMF_VERSION_MINOR << 32 | 
AMF_VERSION_RELEASE << 16 | AMF_VERSION_BUILD_NUM) >= 0x000100040009"
+"(AMF_VERSION_MAJOR << 48 | AMF_VERSION_MINOR << 32 | 
AMF_VERSION_RELEASE << 16 | AMF_VERSION_BUILD_NUM) >= 0x00010004001c"
 
 # Funny iconv installations are not unusual, so check it after all flags have 
been set
 if enabled libc_iconv; then
-- 
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".


Re: [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop

2022-11-23 Thread Dmitrii Ovchinnikov
>>The types seems mismatching

The reason for the mismatch of types is that I left the
int type according to the comments :
"
James Almer
IMO the AVFrame ones should have not been size_t to begin with, not just
because the actual dimensions you'll apply them to are int, but because
these fields are not arch dependent or meant for the size of some object
in memory.
"

 It seems that performing casts would not be a good idea.
 Should I make crop fields size_t type as in AVFrame?
 Or is there a more correct way?
___
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] lavc/libvpx: increase thread limit to 64

2022-11-23 Thread Dmitrii Ovchinnikov
Thanks for the answer and comment! I will think about how best to
rework the patch and then send a new version.
___
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] [avcodec/amfenc: 10 bit support v2 1/3] amf: Update the min version to 1.4.23.0 for AMF SDK.

2022-10-25 Thread Dmitrii Ovchinnikov
Hi! These patches have already been tested and accepted into the  HandBrake
  (https://github.com/HandBrake/HandBrake/pull/4538 ). Could you take a
look?
___
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] lavc/libvpx: increase thread limit to 64

2022-10-25 Thread Dmitrii Ovchinnikov
>> Why do you still impose an upper limit unconditionally even if the
>>user has set his preferred number of threads?
Libvpx-vp9 does not support number of threads greater than 64, so we impose
an upper limit of 64.
E.g. if we set it any higher we get the following execution error:
[libvpx-vp9 @ 0x2f631c0] Failed to initialize encoder: Invalid parameter
[libvpx-vp9 @ 0x2f631c0]   Additional information: g_threads out of range
[..64]
Error initializing output stream 0:0 -- Error while opening encoder for
output stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
width or height

>>According to
https://ffmpeg.org/pipermail/ffmpeg-devel/2018-November/236406.html the
>>maximum of 16 has not been chosen because of H.264, but because there
>>was some form of restriction in libvpx. Or at least there was belief in
>>the existence of such a restriction.
There is a restriction of maximum 64 threads, not 16.

>>This code potentially calls av_cpu_count() twice.
Can you please clarify how it calls it twice? 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] [crop support for matroska demuxer, V3 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

2022-10-12 Thread Dmitrii Ovchinnikov
>>Why does an encoder or decoder need to care about this, given it's
>>container level information?
>>Do you plan on implementing cropping support into all the encoders?



This implementation takes a reference of the h.264 supporting cropping. In
h264, if width (stored in ACCodecContext) parsed from container is
different from width parsed from elementary, it will trigger cropping. This
is essentially a kind of cropping that related with container. It will
infer parameters cb(crop bottom), cr(crop right), and then finally assigned
them to AVFrame.

This gives the inspiration when we get direct cropping parameters from
container. We can us the same methodology.

Parser cropping parameters from container in demuxer -> stored container
cropping parameters in AVCodec -> pass container cropping parameters to
AVFrame-> Apply Crop in frame.c of libavutil.



Container cropping can both be implemented in libavutil, or libavfilter.
The as-is implementation of H.264 gave a detailed implement reference that
we can put cropping in libavcode and libavutil. My implementation just
follows that methodology.



From the another point of view, there are some benefit as well: cropping is
a light weight process (only copy yuv data), comparing with some module
such as edge_common,  colorspacedsp etc. in libavfilter. Put container
cropping in libavcodec and libavutil is very concise.



Currently we are supporting the matroska codec. Matroska will be the first
one that use submitted code in decoder.c and AVCodecContext to support
container cropping. Because container cropping parameters I added are 0 by
default, it will not affect any existing container or future container
which don’t support crop. If other developers plan to add container crop
supporting for certain container, those codes in public section (such as
codes in in decoder.c and AVCodecContext ) are possible shared by them.
___
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] [crop support for matroska demuxer, V3 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

2022-10-12 Thread Dmitrii Ovchinnikov
>> I don't see why should a decoder deal with this at all?
>>This can be just as well done by the caller.

This implementation takes a reference of the h.264 supporting cropping. In
h264, if width (stored in ACCodecContext) parsed from container is
different from width parsed from elementary, it will trigger cropping. This
is essentially a kind of cropping that related with container. It will
infer parameters cb(crop bottom), cr(crop right), and then finally assigned
them to AVFrame.

This gives the inspiration when we get direct cropping parameters from
container. We can us the same methodology.

Parser cropping parameters from container in demuxer -> stored container
cropping parameters in AVCodec -> pass container cropping parameters to
AVFrame-> Apply Crop in frame.c of libavutil.



I agree that the caller decide container cropping. To support caller decide
the behaviors of cropping,I declare a new field “container_apply_cropping”.
The value of this fields container_apply_cropping is decided by caller.
This field is by default 1.



   - When set to 1 (the default), libavcodec will apply container cropping
   to codec cropping additionally.



   - When set to 2, libavcodec will use container cropping to overwrite
   codec cropping (the final cropping uses container cropping parameters)



   - When set to 0, libavcodec will ignore container cropping parameters
   (the final cropping uses codec cropping parameters)



Caller can total decide the behaviors of container cropping.



This field “container_apply_cropping”  subject the value of
“apply_cropping" (an existing field ). Only apply_cropping is 1, this field
works.  This make sure the container cropping parameters supporting is
consistent with the current cropping mechanism.
___
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] [crop support for matroska demuxer 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

2022-10-07 Thread Dmitrii Ovchinnikov
Sent an updated version:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7707.
1)
>>All of these should be size_t
The field type is still "int" according to James Almer's comment.
2) I placed the fields at the very end, according to a message from Timo
Rothenpieler.
3)
>>The semantics of these new fields definitely need to be defined more
precisely
Added a flag responsible for the behavior(enum
CONTAINER_CROPPING_POLICY_TYPE container_apply_cropping;).
When set to 1 (the default), libavcodec will apply container cropping
to codec cropping additionally.
When set to 2, libavcodec will use container cropping to overwrite
codec cropping (the final cropping uses container cropping parameters)
When set to 0, libavcodec will ignore container cropping parameters
(the final cropping uses codec cropping parameters)This field works with
"apply_cropping".
Only if apply_cropping is 1, this field works
___
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] lavc/libvpx: increase thread limit to 64

2022-10-06 Thread Dmitrii Ovchinnikov
Removed unnecessary comment as requested by Ronald S. Bultje.

some more thoughts about the patch:

This is my deduction from what I could find - There was a hard limit of 16
threads in libvpx as there was no benefit to adding more threads based upon
the parallelism  available in the the codec. This was based upon
resolutions upto 3840x2160 (more details below). For 4k/8K videos this
restriction does not allow enough parallelism to be exploited. Adding more
threads improves performance for higher resolution videos.

Details:
Tiling and Threading Recommendations
Tiling splits the video frame into multiple columns, which slightly reduces
quality but speeds up encoding performance. Tiles must be at least 256
pixels wide, so there is a limit to how many tiles can be used. Depending
upon the number of tiles and the resolution of the output frame, more CPU
threads may be useful. There is limited value to multiple threads when the
output frame size is very small.

The following settings are recommended for tiling and threading at various
resolutions. The number of threads is doubled as there is an option row-mt
when set allows row-based multithreading within the tiles.

Frame Size | Number of tile-columns | Number of threads
320x240 | 1 (-tile-columns 0) | 2
640x360 | 2 (-tile-columns 1) | 4
640x480 | 2 (-tile-columns 1) | 4
1280x720 | 4 (-tile-columns 2) | 8
1920x1080 | 4 (-tile-columns 2) | 8
2560x1440 | 8 (-tile-columns 3) | 16
3840x2160 | 8 (-tile-columns 3) | 16

In ffmpeg, the number of tiles is controlled with the -tile-columns
parameter and the number of threads by -threads. For example, a 640x480
encode would use the command-line -tile-columns 2 -threads 4.
___
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] libavformat\matroskadec.c: crop support for matroska demuxer.

2022-10-01 Thread Dmitrii Ovchinnikov
I fixed issues1-4 and sent an updated version:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7668
___
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] libavformat\matroskadec.c: crop support for matroska demuxer.

2022-09-26 Thread Dmitrii Ovchinnikov
Hi Andreas,

Thanks for your quick and direct feedback about the patch. Your feedback
about the displayWidth, displayHeight and the display aspect ratio shows
that you have deep thinking in this area.

I have several questions and comments about your feedback.

1. Yes, i will get this change, and put the added fields at the rear part
of AVCodecParameters
2. I will split these changes into different commits. Should I also split
the edits in the AVCodecContext and codec_pack.c files into different
commits?
3. Yes, I will apply the container cropping info additionally to the
bitstream cropping.
4. Yes, I will apply the cropping for receive_frame API as well.
5. I'm also working on “clean aperture” for MP4 container. mov is a part of
the subset of MP4. I will submit that patch to ffmpeg after i finished it.
Maybe one month later.
6. Thanks for a good reference.
7. Yes, there are many problems in the MKVToolNix. MKVToolNix may result in
some inconsistent of display aspect ratio when editing crop information.
There are two part of work(for support of Matroska cropping), one part is
matroska encoder, another is matroska decoder. This time i submit the
matroska decoder patch. In the matroska encoder, i have already taken the
inconsistent into consideration, and did some work to make sure it keeps
consistent. Do you want me to put the matroska encoder and matroska decode
together in the same patch to submit ffmpeg, or do you want I put them in
two separate patch and submit seperately?
___
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] [avcodec/amfenc: 10 bit support v2 1/3] amf: Update the min version to 1.4.23.0 for AMF SDK.

2022-09-07 Thread Dmitrii Ovchinnikov
 >>Isn't that a bit too recent? Or does it not matter because it still
supports old drivers?

Old drivers are fully supported.
___
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/5] lavu/hwcontext_amf: HWContext for AMF based components

2020-10-28 Thread Dmitrii Ovchinnikov
This part of the code is also planned to be used in AMF decorer.
___
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 4/5] lavu/hwcontext_amf: Engine selection support for AMF context

2020-10-28 Thread Dmitrii Ovchinnikov
>Why?  Given that you are already initialising from a specific device when
one is given, what does this actually change?
This code was created quite a long time ago in order to allow the user to
use the vulkan encoder on Windows.
For now, it looks like you can use AVVulkanDeviceContext instead.I will
make the appropriate patch and send it later, instead of this patch. Thank
you for the review!
___
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/5] lavc/amfenc: HWConfig for amf encoder.

2020-10-28 Thread Dmitrii Ovchinnikov
>
>
> This looks right, but can you clarify the intent behind the hw config
> cases?  (Do you have an ffmpeg command line or other example which is
> improved by them?)
>
> Hi! This ticket describes the problem.
https://trac.ffmpeg.org/ticket/8953#ticket
___
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".