Re: [FFmpeg-devel] [PATCH v2] avcodec/amfenc: increase precision of Sleep() on Windows

2024-02-19 Thread Evgeny Pavlov
On Mon, Nov 27, 2023 at 3:05 PM Henrik Gramner via ffmpeg-devel
 wrote:
>
> On Mon, Nov 27, 2023 at 2:42 PM Mark Thompson  wrote:
> > Is it reasonable to set this global state from a library without the parent 
> > program knowing?  We'd really prefer not to affect the global state 
> > unexpectedly.
>
> CreateWaitableTimerExW() with the
> CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag might be an alternative?
>

We evaluated CreateWaitableTimerExW with
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag. In fact, this function has
the same precision level as the Sleep() function.

Usually changing the time resolution will only affect the current
process and will not impact other processes, thus it will not cause a
global effect on the current system. Here is an info from
documentation on timeBeginPeriod
https://learn.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timebeginperiod

"Prior to Windows 10, version 2004, this function affects a global
Windows setting. For all processes Windows uses the lowest value (that
is, highest resolution) requested by any process. Starting with
Windows 10, version 2004, this function no longer affects global timer
resolution. For processes which call this function, Windows uses the
lowest value (that is, highest resolution) requested by any process.
For processes which have not called this function, Windows does not
guarantee a higher resolution than the default system resolution."

We provide the following measurement to show performance improvements
with this patch.

1. Performance tests show that this high precision sleep will improve
performance, especially for low resolution sequences, it can get about
20% improvement.

Frames Per Second (FPS) being encoded by the hardware encoder (Navi 31
RX7900XT ):

Source Type: H.264 ,  Output Type: H.264
(Sorry for bad formatting)
No. |   Sequence Resolution | No. of Frames|FPS Before patch|
FPS after patch   | Difference| Improvement %
|---|--||---|---|--
1   |   480x360 | 8290 |2030|
 2365| 335   | 16.5%
2   |   720x576 | 8290 |1440|
 1790| 350   | 24.3%
3 | 1280x720| 8290 |1120|
 1190| 70| 6.3%
4   |   1920x1080   | 8290 |692 |
 714 | 22| 3.2%
5   |   3840x2160   | 8290 |200 |
 200 | 0 | 0.0%

The sample ffmpeg command line:
$ ffmpeg.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i
input.mp4 -c:v h264_amf out.mp4
where input.mp4 should be changed to corresponding resolution input
H.264 format bitstream.

2. The power tests show an increase in power is within limit scope.

The purpose of the power test is to examine the increase in CPU power
consumption due to the improvement in CPU time resolution after using
this patch. We were testing a product from AMD called Phoenix, which
we refer to as an APU. It combines a general-purpose AMD CPU and a 3D
integrated graphics processing unit (IGPU) on a single die. Only the
APU has a DAP connector to the board's power rails.

We got the power test data shown below:

|| 480x360   |  720x576   | 1280x720 |
1920x1080 | 3840x2160 | average
||---||--|---|---|
|CPU  power change   |  1.93%|  2.43% | -1.69%   | 3.49%
  | 2.92% | 1.82%
|APU power total change  |  0.86%|  1.34% | -0.62%   | 1.54%
  | -0.58%| 0.51

When using a high precision clock by applying the patch, the average
power consumption for CPU increases 1.82%, and the APU total increases
0.51%. We can see the power increase in power not very significant.
___
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 8/9] avfilter/scale_amf: Add AMF HW scaler & color converter

2024-02-19 Thread Evgeny Pavlov
On Wed, Feb 14, 2024 at 5:26 PM Dennis Mungai  wrote:

> On Wed, 14 Feb 2024, 18:28 Evgeny Pavlov,  wrote:
>
> > On Wed, Feb 14, 2024 at 4:08 PM Timo Rothenpieler  >
> > wrote:
> >
> > > On 14/02/2024 02:55, Dmitrii Ovchinnikov wrote:
> > > > 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.
> > >
> > > Haven't looked at the patch yet, but can't this be one filter, and it
> > > picks the best possible method depending on options/inputs/whatever?
> > > ___
> > > 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".
> > >
> >
> > AMF has 2 separate components for color conversion + simple scaling
> > (VideoConverter)  and for advanced scaling (HQScaler).
> > We've got a recommendation from the AMD AMF team to implement these
> > components as separate ffmpeg filters.
> >
>
>
> Still, this should be a single VIdeo Post-Processing (VPP) -style filter,
> exposing these scaling and video post processing options as tunables
> therein.
>
> A perfect example of such an implementation that excels in such an
> abstraction is intel's vpp_qsv filter, from which multiple compute, color
> space conversion methods, tonemapping, etc are made available through
> tunables.
>
> Another benefit of such an abstraction would be that re-using this filter
> on other GPU derivatives of the discrete silicon, eg in smaller IGPs
> sharing these offload blocks would be auto-detecting logic to ensure that
> even with defaults, the filter chains run.
>
> Taking another example from Intel, they have a full H/W path for low power
> encode and Post-Processing that can be automatically toggled on by specific
> filter options without user intervention, guaranteeing runtime safety for
> the same command(s) even on newer GPUs.
>
> Food for thought.
>
> >
> ___
> 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".
>

AMF Video Converter (which is used in scale_amf) is the full analog of
Intel's VPP. And in the future, it may have an option for dedicated HW
block in GPU. It has scaling, color conversion, tonemapping, HDR <> SDR
conversion features.
But HQ Scaler brings advanced scaling algorithms that are similar to AMD
FSR (https://www.amd.com/en/technologies/fidelityfx-super-resolution ) and
don’t have color conversion and cannot be mapped to HW blocks.
Do you think that it would be better to rename scale_amf to vpp_amf or some
other name? Maybe we should rename scale_amf_hq as well for better
usability (e.g. sr_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 8/9] avfilter/scale_amf: Add AMF HW scaler & color converter

2024-02-14 Thread Evgeny Pavlov
On Wed, Feb 14, 2024 at 4:08 PM Timo Rothenpieler 
wrote:

> On 14/02/2024 02:55, Dmitrii Ovchinnikov wrote:
> > 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.
>
> Haven't looked at the patch yet, but can't this be one filter, and it
> picks the best possible method depending on options/inputs/whatever?
> ___
> 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".
>

AMF has 2 separate components for color conversion + simple scaling
(VideoConverter)  and for advanced scaling (HQScaler).
We've got a recommendation from the AMD AMF team to implement these
components as separate ffmpeg filters.
___
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 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-12-15 Thread Evgeny Pavlov
On Mon, Dec 11, 2023 at 10:21 PM Mark Thompson  wrote:

>
> Not the same, but here is a freely-available test video which has the same
> effect: .  Output below.
>
> It doesn't seem like this should be dependent on the underlying hardware
> since (I hope) it won't go to the hardware for header information.  Still,
> just in case: it's a 5850U APU running driver version 23.11.1 on Windows 10.
>
> (Seems like it might be a good idea for the debug output to print the
> driver and hardware versions at least?)
>
> The VPS out-of-order is also a weird effect - it makes it look like the
> two headers are generated by separate processes, which doesn't seem like a
> good idea when you want them to be identical.
>

I've  tested the video on 5700U APU with 23.11.1 on Windows 11 & confirmed
that there is an issue with missing color information in the header. It
seems that for 5xxxU APU drivers 23.11.1 doesn't contain a fix for this bug
in AMF.
I've checked with the latest AMF library on  5700 U APU and the issue was
fixed, so I believe future driver releases will include the updated version
of AMF library.
This issue with missing color information isn't related with ffmpeg code
itself, we need to wait for updated AMD drivers for APU
___
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 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-12-08 Thread Evgeny Pavlov
On Wed, Nov 29, 2023 at 11:57 AM Evgeny Pavlov  wrote:

> On Tue, Nov 28, 2023 at 8:13 PM Mark Thompson  wrote:
>
>> I upgraded to 23.11.1 and see no change - the colour information is still
>> missing in the header but not the stream, and the two different sequence
>> parameter sets are identical to what they were before the change.
>>
>> Can you share what your trace_headers output looks like for the
>> out-of-band and in-band parameter sets?  Are they identical for you?
>>
> Yes, it seems that they are identical for me and both have colour
> information (please find my output below).
> Is it possible to provide a video you tested? Probably I need to
> test the patch on your video input.
>
> Hi Mark, could you share which AMD hardware you use for testing? Your
hardware might use older driver version without the fix for missing color
information in the header
___
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 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-11-29 Thread Evgeny Pavlov
On Tue, Nov 28, 2023 at 8:13 PM Mark Thompson  wrote:

> I upgraded to 23.11.1 and see no change - the colour information is still
> missing in the header but not the stream, and the two different sequence
> parameter sets are identical to what they were before the change.
>
> Can you share what your trace_headers output looks like for the
> out-of-band and in-band parameter sets?  Are they identical for you?
>
Yes, it seems that they are identical for me and both have colour
information (please find my output below).
Is it possible to provide a video you tested? Probably I need to
test the patch on your video input.

 Stream #0:0[0x1](und): Video: hevc (Main 10) (hvc1 / 0x31637668),
yuv420p10le(tv, bt2020nc/bt2020/smpte2084, progressive), 3840x2160 [SAR 1:1
DAR 16:9], 2158 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
Metadata:
  creation_time   : 2018-11-26T22:40:26.00Z
  handler_name: Core Media Video
  vendor_id   : [0][0][0][0]
Side data:
  Mastering Display Metadata, has_primaries:1 has_luminance:1
r(0.7080,0.2920) g(0.1700,0.7970) b(0.1310 0.0460) wp(0.3127, 0.3290)
min_luminance=0.00, max_luminance=1000.00
  Content Light Level Metadata, MaxCLL=1000, MaxFALL=300
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> hevc (hevc_amf))
[trace_headers @ 0226a49c4a80] Extradata
[trace_headers @ 0226a49c4a80] Sequence Parameter Set
[trace_headers @ 0226a49c4a80] 0   forbidden_zero_bit
   0 = 0
[trace_headers @ 0226a49c4a80] 1   nal_unit_type
   11 = 33
[trace_headers @ 0226a49c4a80] 7   nuh_layer_id
  00 = 0
[trace_headers @ 0226a49c4a80] 13  nuh_temporal_id_plus1
  001 = 1
[trace_headers @ 0226a49c4a80] 16  sps_video_parameter_set_id
 = 0
[trace_headers @ 0226a49c4a80] 20  sps_max_sub_layers_minus1
  000 = 0
[trace_headers @ 0226a49c4a80] 23  sps_temporal_id_nesting_flag
   1 = 1
[trace_headers @ 0226a49c4a80] 24  general_profile_space
   00 = 0
[trace_headers @ 0226a49c4a80] 26  general_tier_flag
0 = 0
[trace_headers @ 0226a49c4a80] 27  general_profile_idc
1 = 1
[trace_headers @ 0226a49c4a80] 32
 general_profile_compatibility_flag[0]   0 = 0
[trace_headers @ 0226a49c4a80] 33
 general_profile_compatibility_flag[1]   1 = 1
[trace_headers @ 0226a49c4a80] 34
 general_profile_compatibility_flag[2]   1 = 1
[trace_headers @ 0226a49c4a80] 35
 general_profile_compatibility_flag[3]   0 = 0
[trace_headers @ 0226a49c4a80] 36
 general_profile_compatibility_flag[4]   0 = 0
[trace_headers @ 0226a49c4a80] 37
 general_profile_compatibility_flag[5]   0 = 0
[trace_headers @ 0226a49c4a80] 38
 general_profile_compatibility_flag[6]   0 = 0
[trace_headers @ 0226a49c4a80] 39
 general_profile_compatibility_flag[7]   0 = 0
[trace_headers @ 0226a49c4a80] 40
 general_profile_compatibility_flag[8]   0 = 0
[trace_headers @ 0226a49c4a80] 41
 general_profile_compatibility_flag[9]   0 = 0
[trace_headers @ 0226a49c4a80] 42
 general_profile_compatibility_flag[10]  0 = 0
[trace_headers @ 0226a49c4a80] 43
 general_profile_compatibility_flag[11]  0 = 0
[trace_headers @ 0226a49c4a80] 44
 general_profile_compatibility_flag[12]  0 = 0
[trace_headers @ 0226a49c4a80] 45
 general_profile_compatibility_flag[13]  0 = 0
[trace_headers @ 0226a49c4a80] 46
 general_profile_compatibility_flag[14]  0 = 0
[trace_headers @ 0226a49c4a80] 47
 general_profile_compatibility_flag[15]  0 = 0
[trace_headers @ 0226a49c4a80] 48
 general_profile_compatibility_flag[16]  0 = 0
[trace_headers @ 0226a49c4a80] 49
 general_profile_compatibility_flag[17]  0 = 0
[trace_headers @ 0226a49c4a80] 50
 general_profile_compatibility_flag[18]  0 = 0
[trace_headers @ 0226a49c4a80] 51
 general_profile_compatibility_flag[19]  0 = 0
[trace_headers @ 0226a49c4a80] 52
 general_profile_compatibility_flag[20]  0 = 0
[trace_headers @ 0226a49c4a80] 53
 general_profile_compatibility_flag[21]  0 = 0
[trace_headers @ 0226a49c4a80] 54
 general_profile_compatibility_flag[22]  0 = 0
[trace_headers @ 0226a49c4a80] 55
 general_profile_compatibility_flag[23]  0 = 0
[trace_he

Re: [FFmpeg-devel] [PATCH 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-11-28 Thread Evgeny Pavlov
On Mon, Nov 27, 2023 at 8:47 PM Mark Thompson  wrote:

> There is something very wrong with how the header information is working
> here.
>
> With this series applied, I ran:
>
> ffmpeg_g.exe -report -y -i in.mp4 -an -c:v hevc_amf -bsf:v trace_headers
> -frames:v 1 out.mp4
>
> My input file is:
>
>Stream #0:0[0x1](und), 60, 1/6: Video: hevc (Main 10) (hvc1 /
> 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160 [SAR 1:1
> DAR 16:9], 74462 kb/s, 59.94 fps, 59.94 tbr, 60k tbn (default)
>
> [trace_headers @ 023184c753c0] Extradata
> [trace_headers @ 023184c753c0] Sequence Parameter Set
> ...
> [trace_headers @ 023184c753c0] 222
>  vui_parameters_present_flag 0 = 0
>
> So no colour information at all in the headers, and the output file indeed
> says:
>
>Stream #0:0[0x1](und): Video: hevc (Main 10) (hev1 / 0x31766568),
> yuv420p10le(tv, progressive), 3840x2160, 977 kb/s, SAR 1:1 DAR 16:9, 59.94
> fps, 59.94 tbr, 60k tbn (default)
>
> However!  Reading further:
>
> [trace_headers @ 023184c753c0] Packet: 2039 bytes, key frame, pts 0,
> dts 0.
> ...
> [trace_headers @ 023184c753c0] Sequence Parameter Set
> ...
> [trace_headers @ 023184c753c0] 222
>  vui_parameters_present_flag 1 = 1
> [trace_headers @ 023184c753c0] 223
>  aspect_ratio_info_present_flag  1 = 1
> [trace_headers @ 023184c753c0] 224 aspect_ratio_idc
>   = 255
> [trace_headers @ 023184c753c0] 232 sar_width
>   0001 = 1
> [trace_headers @ 023184c753c0] 248 sar_height
>  0001 = 1
> [trace_headers @ 023184c753c0] 264 overscan_info_present_flag
> 0 = 0
> [trace_headers @ 023184c753c0] 265
>  video_signal_type_present_flag  1 = 1
> [trace_headers @ 023184c753c0] 266 video_format
>   101 = 5
> [trace_headers @ 023184c753c0] 269 video_full_range_flag
>  0 = 0
> [trace_headers @ 023184c753c0] 270
>  colour_description_present_flag 1 = 1
> [trace_headers @ 023184c753c0] 271 colour_primaries
>  1001 = 9
> [trace_headers @ 023184c753c0] 279 transfer_characteristics
>  0001 = 16
> [trace_headers @ 023184c753c0] 287 matrix_coefficients
>   1001 = 9
> [trace_headers @ 023184c753c0] 295
>  chroma_loc_info_present_flag0 = 0
> [trace_headers @ 023184c753c0] 296
>  neutral_chroma_indication_flag  0 = 0
> [trace_headers @ 023184c753c0] 297 field_seq_flag
> 0 = 0
> [trace_headers @ 023184c753c0] 298
>  frame_field_info_present_flag   0 = 0
> [trace_headers @ 023184c753c0] 299
>  default_display_window_flag 0 = 0
> [trace_headers @ 023184c753c0] 300
>  vui_timing_info_present_flag1 = 1
> [trace_headers @ 023184c753c0] 301 vui_num_units_in_tick
>   00101001 = 1001
> [trace_headers @ 023184c753c0] 333 vui_time_scale
>  111010100110 = 6
> [trace_headers @ 023184c753c0] 365
>  vui_poc_proportional_to_timing_flag 1 = 1
> [trace_headers @ 023184c753c0] 366
>  vui_num_ticks_poc_diff_one_minus1   1 = 0
>
> Comparing the to the original, the chroma sample location (collocated
> top-left in the original, so the implied default is wrong) has been lost
> but the colours are otherwise correct in the extraneous headers embedded in
> the first packet.
>
> So the colour information has kindof been passed through, except not in
> the place in the headers which matters so it is mostly useless.  (I guess
> it maybe works for raw streams with no headers?)
>
> I think you need to fix whatever is making the headers not match the
> actual stream content (which creates invalid files, mp4 and similar
> containers with global headers need them to match).
>
> Thanks,
>
> - Mark
>

Could you test this issue with the latest AMD 23.11.1 driver? This issue
looks similar to issue #9195 in OBS Studio
https://github.com/obsproject/obs-studio/issues/9195. It was fixed in the
latest AMD driver.
___
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-28 Thread Evgeny Pavlov
>
>
> Seems like we could template this to avoid the duplication, something like:
>
> #define PER_CODEC_OPTION(name) \
>(ctx->codec == AV1  ? AMF_VIDEO_ENCODER_AV1_  ## name : \
> ctx->codec == HEVC ? AMF_VIDEO_ENCODER_HEVC_ ## name : \
>  AMF_VIDEO_ENCODER_  ## name)
>

Thanks for the suggestion, I've extracted duplicated code to amfenc.c file,
but can't extract the whole smart_access_video option, because there are
some differences between av1 & hevc/h264 encoders while set low latency
mode.
In addition, I've added a more detailed description for SAV option, I hope
it will be enough for understanding.
Here is an updated version of this patch:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20231128135347.892-2-lucenti...@gmail.com/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


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

2023-11-28 Thread 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.c  | 11 +++
 libavcodec/amfenc.h  |  6 ++
 libavcodec/amfenc_av1.c  |  8 
 libavcodec/amfenc_h264.c |  8 
 libavcodec/amfenc_hevc.c |  8 
 5 files changed, 41 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..c48eb27056 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -369,6 +369,17 @@ static int amf_init_encoder(AVCodecContext *avctx)
 res = ctx->factory->pVtbl->CreateComponent(ctx->factory, ctx->context, 
codec_id, &ctx->encoder);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_ENCODER_NOT_FOUND, 
"CreateComponent(%ls) failed with error %d\n", codec_id, res);
 
+if (ctx->smart_access_video != -1) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_PER_CODEC_OPTION(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);
+}
+}
+
 return 0;
 }
 
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..9bb3278bc5 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -89,6 +89,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
 
@@ -179,4 +180,9 @@ extern const enum AVPixelFormat ff_amf_pix_fmts[];
 return ret_value; \
 }
 
+#define AMF_PER_CODEC_OPTION(name) \
+   (avctx->codec->id == AV_CODEC_ID_AV1  ? AMF_VIDEO_ENCODER_AV1_  ## name : \
+avctx->codec->id == AV_CODEC_ID_HEVC ? AMF_VIDEO_ENCODER_HEVC_ ## name : \
+   AMF_VIDEO_ENCODER_  ## name)
+
 #endif //AVCODEC_AMFENC_H
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 3f164ccc59..06ce566f39 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 parallelization of encode and decode 
streams across multiple VCN hardware instances",  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 },
 
@@ -243,6 +245,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+// Set low latency mode if Smart Access Video is enabled
+if (ctx->smart_access_video == 1) {
+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 bd544d12df..9b36a8b088 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 parallelization of encode and decode 
streams across multiple VCN hardware instances",  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 },
 
@@ -353,6 +355,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_log(ctx, AV_LOG_WARNING, "rate control mode is PEAK_CONSTRAINED_VBR 
but rc_max_

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

2023-11-23 Thread 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 2dbd378ef8..e8d66164ed 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -89,6 +89,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 3f164ccc59..912d6bf020 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 },
 
@@ -243,6 +245,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 bd544d12df..b0b47645fc 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 },
 
@@ -353,6 +355,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_PR

Re: [FFmpeg-devel] [PATCH v2] avcodec/amfenc: increase precision of Sleep() on Windows

2023-11-20 Thread Evgeny Pavlov
On Mon, Nov 13, 2023 at 3:41 PM Evgeny Pavlov  wrote:

> This commit increase precision of Sleep() function on Windows.
> This fix reduces the sleep time on Windows to improve AMF encoding
> performance on low resolution input videos.
>
> Fix for issue #10622
>
> v2: use timeBeginPeriod/timeEndPeriod for increasing precision of Sleep()
>
> Signed-off-by: Evgeny Pavlov 
> ---
>  libavcodec/amfenc.c | 31 +++
>  libavcodec/amfenc.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index 061859f85c..55e24856e8 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -42,7 +42,12 @@
>  #endif
>
>  #ifdef _WIN32
> +#include 
>  #include "compat/w32dlfcn.h"
> +
> +typedef MMRESULT (*timeapi_fun)(UINT uPeriod);
> +#define WINMM_DLL "winmm.dll"
> +
>  #else
>  #include 
>  #endif
> @@ -113,6 +118,9 @@ static int amf_load_library(AVCodecContext *avctx)
>  AMFInit_Fn init_fun;
>  AMFQueryVersion_Fn version_fun;
>  AMF_RESULT res;
> +#ifdef _WIN32
> +timeapi_fun time_begin_fun;
> +#endif
>
>  ctx->delayed_frame = av_frame_alloc();
>  if (!ctx->delayed_frame) {
> @@ -145,6 +153,16 @@ static int amf_load_library(AVCodecContext *avctx)
>  AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace()
> failed with error %d\n", res);
>  res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
>  AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug()
> failed with error %d\n", res);
> +
> +#ifdef _WIN32
> +// Increase precision of Sleep() function on Windows platform
> +ctx->winmm_lib = dlopen(WINMM_DLL, RTLD_NOW | RTLD_LOCAL);
> +AMF_RETURN_IF_FALSE(ctx, ctx->winmm_lib != NULL, 0, "DLL %s failed to
> open\n", WINMM_DLL);
> +time_begin_fun = (timeapi_fun)dlsym(ctx->winmm_lib,
> "timeBeginPeriod");
> +AMF_RETURN_IF_FALSE(ctx, time_begin_fun != NULL, 0, "DLL %s failed to
> find function %s\n", WINMM_DLL, "timeBeginPeriod");
> +time_begin_fun(1);
> +#endif //_WIN32
> +
>  return 0;
>  }
>
> @@ -375,6 +393,9 @@ static int amf_init_encoder(AVCodecContext *avctx)
>  int av_cold ff_amf_encode_close(AVCodecContext *avctx)
>  {
>  AmfContext *ctx = avctx->priv_data;
> +#ifdef _WIN32
> +timeapi_fun time_end_fun;
> +#endif //_WIN32
>
>  if (ctx->delayed_surface) {
>  ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
> @@ -410,6 +431,16 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
>  av_frame_free(&ctx->delayed_frame);
>  av_fifo_freep2(&ctx->timestamp_list);
>
> +#ifdef _WIN32
> +if (ctx->winmm_lib) {
> +time_end_fun = (timeapi_fun)dlsym(ctx->winmm_lib,
> "timeEndPeriod");
> +AMF_RETURN_IF_FALSE(ctx, time_end_fun != NULL, 0, "DLL %s failed
> to find function %s\n", WINMM_DLL, "timeEndPeriod");
> +time_end_fun(1);
> +dlclose(ctx->winmm_lib);
> +ctx->winmm_lib = NULL;
> +}
> +#endif //_WIN32
> +
>  return 0;
>  }
>
> diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
> index 2dbd378ef8..35bcf1dfe3 100644
> --- a/libavcodec/amfenc.h
> +++ b/libavcodec/amfenc.h
> @@ -50,6 +50,9 @@ typedef struct AmfContext {
>  AVClass*avclass;
>  // access to AMF runtime
>  amf_handle  library; ///< handle to DLL library
> +#ifdef _WIN32
> +amf_handle  winmm_lib; ///< handle to winmm DLL library
> +#endif //_WIN32
>  AMFFactory *factory; ///< pointer to AMF factory
>  AMFDebug   *debug;   ///< pointer to AMF debug interface
>  AMFTrace   *trace;   ///< pointer to AMF trace interface
> --
> 2.42.0
>
>
Please take a look on this patch, it helps to improve AMF encoding
performance on small resolution video on Windows platform by using more
precise Sleep()
___
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-20 Thread Evgeny Pavlov
On Mon, Jul 24, 2023 at 1:25 PM Evgeny Pavlov  wrote:

> 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 
> ---
> Changes in v2:
>  - Enable low latency mode when smart access video explicitly enabled
>  - Set default value for SAV to -1 (auto)
>
>  libavcodec/amfenc.h  |  1 +
>  libavcodec/amfenc_av1.c  | 17 +
>  libavcodec/amfenc_h264.c | 17 +
>  libavcodec/amfenc_hevc.c | 17 +
>  4 files changed, 52 insertions(+)
>
> diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
> index 2dbd378ef8..e8d66164ed 100644
> --- a/libavcodec/amfenc.h
> +++ b/libavcodec/amfenc.h
> @@ -89,6 +89,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 30c0a9fad2..d22d86ccd7 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 },
>
> @@ -241,6 +243,21 @@ 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");
> +return AVERROR(EINVAL);
> +} 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 2380aa4e90..de08d9a7cc 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 },
>
> @@ -353,6 +355,21 @@ 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");
> +return AVERROR(EINVAL);
> +}else {
> +av_log(avctx, AV_LOG_INFO, &

Re: [FFmpeg-devel] [PATCH 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-11-13 Thread Evgeny Pavlov
On Tue, Oct 31, 2023 at 7:13 PM Evgeny Pavlov  wrote:

> 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 

[FFmpeg-devel] [PATCH v2] avcodec/amfenc: increase precision of Sleep() on Windows

2023-11-13 Thread Evgeny Pavlov
This commit increase precision of Sleep() function on Windows.
This fix reduces the sleep time on Windows to improve AMF encoding
performance on low resolution input videos.

Fix for issue #10622

v2: use timeBeginPeriod/timeEndPeriod for increasing precision of Sleep()

Signed-off-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c | 31 +++
 libavcodec/amfenc.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..55e24856e8 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -42,7 +42,12 @@
 #endif
 
 #ifdef _WIN32
+#include 
 #include "compat/w32dlfcn.h"
+
+typedef MMRESULT (*timeapi_fun)(UINT uPeriod);
+#define WINMM_DLL "winmm.dll"
+
 #else
 #include 
 #endif
@@ -113,6 +118,9 @@ static int amf_load_library(AVCodecContext *avctx)
 AMFInit_Fn init_fun;
 AMFQueryVersion_Fn version_fun;
 AMF_RESULT res;
+#ifdef _WIN32
+timeapi_fun time_begin_fun;
+#endif
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
@@ -145,6 +153,16 @@ static int amf_load_library(AVCodecContext *avctx)
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
 res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
+
+#ifdef _WIN32
+// Increase precision of Sleep() function on Windows platform
+ctx->winmm_lib = dlopen(WINMM_DLL, RTLD_NOW | RTLD_LOCAL);
+AMF_RETURN_IF_FALSE(ctx, ctx->winmm_lib != NULL, 0, "DLL %s failed to 
open\n", WINMM_DLL);
+time_begin_fun = (timeapi_fun)dlsym(ctx->winmm_lib, "timeBeginPeriod");
+AMF_RETURN_IF_FALSE(ctx, time_begin_fun != NULL, 0, "DLL %s failed to find 
function %s\n", WINMM_DLL, "timeBeginPeriod");
+time_begin_fun(1);
+#endif //_WIN32
+
 return 0;
 }
 
@@ -375,6 +393,9 @@ static int amf_init_encoder(AVCodecContext *avctx)
 int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 {
 AmfContext *ctx = avctx->priv_data;
+#ifdef _WIN32
+timeapi_fun time_end_fun;
+#endif //_WIN32
 
 if (ctx->delayed_surface) {
 ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface);
@@ -410,6 +431,16 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 av_frame_free(&ctx->delayed_frame);
 av_fifo_freep2(&ctx->timestamp_list);
 
+#ifdef _WIN32
+if (ctx->winmm_lib) {
+time_end_fun = (timeapi_fun)dlsym(ctx->winmm_lib, "timeEndPeriod");
+AMF_RETURN_IF_FALSE(ctx, time_end_fun != NULL, 0, "DLL %s failed to 
find function %s\n", WINMM_DLL, "timeEndPeriod");
+time_end_fun(1);
+dlclose(ctx->winmm_lib);
+ctx->winmm_lib = NULL;
+}
+#endif //_WIN32
+
 return 0;
 }
 
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..35bcf1dfe3 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -50,6 +50,9 @@ typedef struct AmfContext {
 AVClass*avclass;
 // access to AMF runtime
 amf_handle  library; ///< handle to DLL library
+#ifdef _WIN32
+amf_handle  winmm_lib; ///< handle to winmm DLL library
+#endif //_WIN32
 AMFFactory *factory; ///< pointer to AMF factory
 AMFDebug   *debug;   ///< pointer to AMF debug interface
 AMFTrace   *trace;   ///< pointer to AMF trace interface
-- 
2.42.0

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

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


[FFmpeg-devel] [PATCH 10bit support v5 3/3] avcodec/amfenc: add 10 bit encoding in av1_amf

2023-10-31 Thread 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 8f13aea29e..634eeea48f 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.41.0

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

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


[FFmpeg-devel] [PATCH 10 bit support v5 2/3] avcodec/amfenc: HDR metadata.

2023-10-31 Thread Evgeny Pavlov
From: nyanmisaka 

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

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

[FFmpeg-devel] [PATCH 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-31 Thread Evgeny Pavlov
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);
 

[FFmpeg-devel] [PATCH 10bit support v5 3/3] avcodec/amfenc: add 10 bit encoding in av1_amf

2023-10-31 Thread 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 8f13aea29e..634eeea48f 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.41.0

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

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


[FFmpeg-devel] [PATCH 10 bit support v5 2/3] avcodec/amfenc: HDR metadata.

2023-10-31 Thread Evgeny Pavlov
From: nyanmisaka 

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

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

[FFmpeg-devel] [PATCH 10 bit support v5 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-31 Thread Evgeny Pavlov
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);
 

[FFmpeg-devel] [PATCH avcodec/amfenc: 10-bit support, v5, 3/3] avcodec/amfenc: add 10 bit encoding in av1_amf

2023-10-23 Thread 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 8f13aea29e..634eeea48f 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.41.0

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

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


[FFmpeg-devel] [PATCH avcodec/amfenc: 10-bit support, v5, 2/3] avcodec/amfenc: HDR metadata.

2023-10-23 Thread Evgeny Pavlov
From: nyanmisaka 

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

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

[FFmpeg-devel] [PATCH avcodec/amfenc: 10-bit support, v5, 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-23 Thread Evgeny Pavlov
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);
 

Re: [FFmpeg-devel] [PATCH] libavcodec/amfenc: Add more pixel formats support

2023-10-23 Thread Evgeny Pavlov
On Sun, Oct 22, 2023 at 5:01 PM Mark Thompson  wrote:

> On 20/10/2023 09:13, Evgeny Pavlov wrote:
> > On Tue, Jul 18, 2023 at 10:32 AM Evgeny Pavlov 
> wrote:
> >
> >> This commit adds BGRA, RGBA and ARGB pixel formats for AMF encoders
> >>
> >> Signed-off-by: Evgeny Pavlov 
> >> ---
> >>   libavcodec/amfenc.c | 3 +++
> >>   1 file changed, 3 insertions(+)
> >>
> >> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> >> index cb48f8c273..234cd012ef 100644
> >> --- a/libavcodec/amfenc.c
> >> +++ b/libavcodec/amfenc.c
> >> @@ -74,6 +74,9 @@ static const FormatMap format_map[] =
> >>   { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
> >>   { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
> >>   { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
> >> +{ AV_PIX_FMT_BGRA,   AMF_SURFACE_BGRA },
> >> +{ AV_PIX_FMT_RGBA,   AMF_SURFACE_RGBA },
> >> +{ AV_PIX_FMT_ARGB,   AMF_SURFACE_ARGB },
> >>   { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
> >>   { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
> >>   { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
> >> --
> >> 2.37.3.windows.1
> >>
> >> The purpose of this patch is to fix an issue with feeding ddagrab output
> > to AMF directly. The output of ddagrab might be BGRA, AMF supports this
> > input, but failed to encode due to missing mapping from AV_PIX_BGRA to
> > AMF_SURFACE_BGRA in amfenc.c
> > DXGI isn't firm to distinguish between RGBA & RGBX, so it is safer to
> > support both to avoid failures like with ddagrab.
>
> See patch just sent to fix the bug in ddagrab that it incorrectly
> advertises an alpha channel.
>
> Do you have ddagrab->amfenc working with just something to fix the alpha
> channel?  To make it work I also need to mess with the bind flags because
> amfenc wants to use the textures as shader resources.
>
> This has been noted as a problem before, where a proper fix would require
> large changes in the format negotiation setup and so it hasn't been done.
> I'm wondering whether adding "-bind_flags shader_resource" option to
> ddagrab would be a plausible hack for these cases, or whether that's a bit
> too obscure for an actual user?
>
> Thanks,
>
> - Mark
> ___
> 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".>
>
>
Yes, I have ddagrab->amfenc working with just fixing alpha channel, but AMF
encoders sometimes use shader, sometimes VCN for color conversion - it
depends on HW capabilities. I would suggest to always set bind in ddgrab to
D3D11_BIND_SHADER_RESOURCE, because this is no reason not to do it.

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

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


Re: [FFmpeg-devel] [PATCH avcodec/amfenc: 10 bit support, v4, 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-20 Thread Evgeny Pavlov
On Wed, Oct 18, 2023 at 10:48 PM Mark Thompson  wrote:

> On 17/10/2023 19:00, Evgeny Pavlov wrote:
> > On Mon, Oct 16, 2023 at 11:41 PM Mark Thompson  wrote:
> > ...
> >>> @@ -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;
> >>
> >> Can you explain what this CONVERTER_COLOR_PROFILE option is actually
> doing?
> >>
> >> You've passed the primaries and transfer function to AMF options later
> on,
> >> but this seems to then only consider a subset of possible matrices
> rather
> >> than just passing that through as well to write into the VUI metadata.
> Why?
> >>
> >> (If this isn't supported by AMF then a more correct solution might be to
> >> insert a metadata BSF to edit the correct values into the output stream
> >> after it has been encoded.)
> >>
> >> When RGB surface is submitted, AMF encoder not only writes VUI header
> but
> > also does color conversion. In this case CONVERTER_COLOR_PROFILE defines
> > color conversion matrix. This conversion may happen with shaders or
> inside
> > VCN if it is capable to do so.
> >
> > These are input parameters for conversion – if conversion is involved:
> > AMF_VIDEO_ENCODER_INPUT_COLOR_PROFILE – for color conversion: limited
> > number of color spaces is supported.
> > AMF_VIDEO_ENCODER_INPUT_TRANSFER_CHARACTERISTIC
> > AMF_VIDEO_ENCODER_INPUT_COLOR_PRIMARIES
> > AMF_VIDEO_ENCODER_INPUT_HDR_METADATA
> >
> > These are output parameters for conversion and data for VUI:
> > AMF_VIDEO_ENCODER_OUTPUT_COLOR_PROFILE – for VUI only, used if color
> > conversion is done outside of AMF
> > AMF_VIDEO_ENCODER_OUTPUT_TRANSFER_CHARACTERISTIC
> > AMF_VIDEO_ENCODER_OUTPUT_COLOR_PRIMARIES
> > AMF_VIDEO_ENCODER_OUTPUT_HDR_METADATA
> >
> > It would be possible to add unsupported color matrices via editing VUI in
> > the output stream but it is better to do it via a separate patch as
> > supported covers most common use cases.
>
> How does the setup you have here support the most common case, where that
> the user has the input in the right format and just wants the colour
> properties that they have set (primaries/transfer/matrix/range/chroma
> location) to be written directly into the encoded stream?
>
Full set of matrices is not currently supported in AMF, only what is in
enum in AMF headers. Makes sense to request all from AMF development team.
Primaries, transfer, range and chroma are fully supported from <>_OUTPUT_<>
parameters.
>
>
> (In most encoders this is the only case, since ad-hoc conversion of the
> input like this is generally considered out-of-scope and done separately.)
>
> >>> +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_

Re: [FFmpeg-devel] [PATCH] libavcodec/amfenc: Add more pixel formats support

2023-10-20 Thread Evgeny Pavlov
On Tue, Jul 18, 2023 at 10:32 AM Evgeny Pavlov  wrote:

> This commit adds BGRA, RGBA and ARGB pixel formats for AMF encoders
>
> Signed-off-by: Evgeny Pavlov 
> ---
>  libavcodec/amfenc.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index cb48f8c273..234cd012ef 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -74,6 +74,9 @@ static const FormatMap format_map[] =
>  { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
>  { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
>  { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
> +{ AV_PIX_FMT_BGRA,   AMF_SURFACE_BGRA },
> +{ AV_PIX_FMT_RGBA,   AMF_SURFACE_RGBA },
> +{ AV_PIX_FMT_ARGB,   AMF_SURFACE_ARGB },
>  { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
>  { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
>  { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
> --
> 2.37.3.windows.1
>
> The purpose of this patch is to fix an issue with feeding ddagrab output
to AMF directly. The output of ddagrab might be BGRA, AMF supports this
input, but failed to encode due to missing mapping from AV_PIX_BGRA to
AMF_SURFACE_BGRA in amfenc.c
DXGI isn't firm to distinguish between RGBA & RGBX, so it is safer to
support both to avoid failures like with ddagrab.
___
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] amfenc: Use a blocking call instead of sleeping and polling

2023-10-19 Thread Evgeny Pavlov
On Wed, Oct 18, 2023 at 10:36 PM Mark Thompson  wrote:

> ---
> On 17/10/2023 18:11, Evgeny Pavlov wrote:
> > The reason for using av_usleep() here is that AMF API doesn’t provide an
> > API for explicit wait. There are two modes to get output from encoder:
> >
> > 1. Polling with some sleep to avoid CPU thrashing – currently used in
> FFmpeg
> >
> > 2. Set timeout parameter on AMF encoder and QueryOutput call will block
> > till output is available or the timeout happens.
> >
> > #2 is the preferable way but it is designed more to be used with a
> separate
> > polling thread. With a single-thread approach in FFmpeg, the use of
> timeout
> > can block input submission making things slower.  This is even more
> > pronounced when B-frames are enabled and several inputs are needed to
> produce
> > the first output.
>
> This approach seems like it should work here?  Run non-blocking until the
> queue is full, then switch to blocking when you need to wait for some
> output.
>
> I tried the patch enclosing (H.264 only, different proprties needed for
> other codecs), but it doesn't seem to work - the test assert always hits
> immediately and timing shows that QueryOutput didn't block even though the
> timeout should be set?  I'm probably doing something incorrect, maybe you
> would know how to fix it.
>
> > The condition of this sleep is in special events (primarily when amf
> input
> > queue is full), not the core loop part. During the experiments the cpu
> > increasing is about 2-4% or so, not a burst.
>
> What cases are you experimenting with?
>
> The most problematic case I can think of is multiple encodes running
> simultaneously sharing the same instance so that each one has to wait for
> others to complete and therefore all queues fill up.
>
> The busy wait will end up being the only place where it can block (since
> everything else runs asynchronously), so you will peg one CPU at close to
> 100% per encode running.
>
> Thanks,
>
> - Mark
>
>   libavcodec/amfenc.c | 22 +++---
>   libavcodec/amfenc.h |  1 +
>   2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index 061859f85c..db7ddbb083 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -713,13 +713,22 @@ int ff_amf_receive_packet(AVCodecContext *avctx,
> AVPacket *avpkt)
>   }
>   }
>
> -
> +block_and_wait = 0;
>   do {
> -block_and_wait = 0;
>   // poll data
>   if (!avpkt->data && !avpkt->buf) {
> +int64_t timeout = block_and_wait ? 100 : 0;
> +if (timeout != ctx->output_query_timeout) {
> +av_log(avctx, AV_LOG_INFO, "Set output query timeout to
> %"PRId64"\n", timeout);
> +AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder,
> AMF_VIDEO_ENCODER_QUERY_TIMEOUT, timeout);
> +AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN,
> "Failed to set output query timeout\n");
> +ctx->output_query_timeout = timeout;
> +}
> +
>   res_query = ctx->encoder->pVtbl->QueryOutput(ctx->encoder,
> &data);
>   if (data) {
> +av_log(avctx, AV_LOG_INFO, "QueryOutput returned with
> data\n");
> +
>   // copy data to packet
>   AMFBuffer *buffer;
>   AMFGuid guid = IID_AMFBuffer();
> @@ -740,7 +749,13 @@ int ff_amf_receive_packet(AVCodecContext *avctx,
> AVPacket *avpkt)
>   data->pVtbl->Release(data);
>
>   AMF_RETURN_IF_FALSE(ctx, ret >= 0, ret,
> "amf_copy_buffer() failed with error %d\n", ret);
> +} else {
> +av_log(avctx, AV_LOG_INFO, "QueryOutput returned with
> nothing (%d)\n", res_query);
> +// For testing, shouldn't hit this unless machine is
> otherwise very loaded.
> +av_assert0(!block_and_wait);
>   }
> +
> +block_and_wait = 0;
>   }
>   res_resubmit = AMF_OK;
>   if (ctx->delayed_surface != NULL) { // try to resubmit frame
> @@ -769,8 +784,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx,
> AVPacket *avpkt)
>
>   if (query_output_data_flag == 0) {
>   if (res_resubmit == AMF_INPUT_FULL || ctx->delayed_drain ||
> (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >=
> ctx->hwsurfaces_in_queue_max)) {
> +av_log(avctx, AV_LOG_

Re: [FFmpeg-devel] [PATCH] avcodec/amfenc: Fix for windows imprecise sleep

2023-10-18 Thread Evgeny Pavlov
On Tue, Oct 17, 2023 at 9:45 PM Kacper Michajlow  wrote:

> On Tue, 17 Oct 2023 at 19:34, Evgeny Pavlov  wrote:
> >
> > The reason for using av_usleep() here is that AMF API doesn’t provide an
> > API for explicit wait. There are two modes to get output from encoder:
> >
> > 1. Polling with some sleep to avoid CPU thrashing – currently used in
> FFmpeg
> >
> > 2. Set timeout parameter on AMF encoder and QueryOutput call will block
> > till output is available or the timeout happens.
> >
> > #2 is the preferable way but it is designed more to be used with a
> separate
> > polling thread. With a single-thread approach in FFmpeg, the use of
> timeout
> > can block input submission making things slower.  This is even more
> > pronounced when B-frames are enabled and several inputs are needed to
> produce
> > the first output.
> >
> > The condition of this sleep is in special events (primarily when amf
> input
> > queue is full), not the core loop part. During the experiments the cpu
> > increasing is about 2-4% or so, not a burst.
> >
> > For low resolution encoding,  these changes bring significant performance
> > improvement (about 15%). It will not bring improvement for high
> resolution
> > such as 4K.
> >
> >
> > Thanks,
> >
> > Evgeny
> >
> > вт, 17 окт. 2023 г. в 03:26, Zhao Zhili :
> >
> > >
> > > > 在 2023年10月17日,上午5:24,Mark Thompson  写道:
> > > >
> > > > On 16/10/2023 10:13, Evgeny Pavlov wrote:
> > > >> This commit reduces the sleep time on Windows to improve AMF
> encoding
> > > >> performance on low resolution input videos.
> > > >> This fix is for Windows only, because sleep() function isn't
> > > >> very accurate on Windows OS.
> > > >> Fix for issue #10622
> > > >> Signed-off-by: Evgeny Pavlov 
> > > >> ---
> > > >>  libavcodec/amfenc.c | 4 
> > > >>  1 file changed, 4 insertions(+)
> > > >> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> > > >> index 061859f85c..0c95465d6e 100644
> > > >> --- a/libavcodec/amfenc.c
> > > >> +++ b/libavcodec/amfenc.c
> > > >> @@ -770,7 +770,11 @@ int ff_amf_receive_packet(AVCodecContext
> *avctx,
> > > AVPacket *avpkt)
> > > >>  if (query_output_data_flag == 0) {
> > > >>  if (res_resubmit == AMF_INPUT_FULL ||
> ctx->delayed_drain
> > > || (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >=
> > > ctx->hwsurfaces_in_queue_max)) {
> > > >>  block_and_wait = 1;
> > > >> +#ifdef _WIN32
> > > >> +av_usleep(0); //Sleep() is not precise on Windows
> OS.
> > > >> +#else
> > > >>  av_usleep(1000);
> > > >> +#endif
> > > >>  }
> > > >>  }
> > > >>  } while (block_and_wait);
> > > >
> > > > Wasting lots of power by spinning on a CPU core does not seem like a
> > > good answer to this problem.  (I mean, presumably that is why Windows
> isn't
> > > honouring your request for a short sleep, because it wants timers to
> have
> > > larger gaps to avoid wasting power.)
> > >
> > > If av_usleep is implemented via Sleep like current case, sleep 0 means
> > > yield current thread, so it’s not busy wait in normal case (but it can
> be
> > > busy wait).
> > >
> > > av_usleep(500) may looks better and do the same job by depending
> 500/1000
> > > = 0.
> > >
> > > I agree use sleep without real async is like a bug.
> > >
> > > >
> > > > Why is there a sleep here at all, anyway?  An API for hardware
> encoding
> > > should be providing a way for the caller to wait for an outstanding
> > > operation to complete.
> > > >
> > > > Thanks,
> > > >
> > > > - Mark
> > > > ___
> > > > ffmpeg-devel mailing list
> > > > ffmpeg-devel@ffmpeg.org
> > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > >
> > > > To unsubscribe, visit link above, or email
> > >
> > > ___
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.o

Re: [FFmpeg-devel] [PATCH avcodec/amfenc: 10 bit support, v4, 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-17 Thread Evgeny Pavlov
On Mon, Oct 16, 2023 at 11:41 PM Mark Thompson  wrote:

> On 09/10/2023 10:52, Evgeny Pavlov wrote:
> > 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
> >
> > 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;
>
> Can you explain what this CONVERTER_COLOR_PROFILE option is actually doing?
>
> You've passed the primaries and transfer function to AMF options later on,
> but this seems to then only consider a subset of possible matrices rather
> than just passing that through as well to write into the VUI metadata.  Why?
>
> (If this isn't supported by AMF then a more correct solution might be to
> insert a metadata BSF to edit the correct values into the output stream
> after it has been encoded.)
>
> When RGB surface is submitted, AMF encoder not only writes VUI header but
also does color conversion. In this case CONVERTER_COLOR_PROFILE defines
color conversion matrix. This conversion may happen with shaders or inside
VCN if it is capable to do so.

These are input parameters for conversion – if conversion is involved:
AMF_VIDEO_ENCODER_INPUT_COLOR_PROFILE – for color conversion: limited
number of color spaces is supported.
AMF_VIDEO_ENCODER_INPUT_TRANSFER_CHARACTERISTIC
AMF_VIDEO_ENCODER_INPUT_COLOR_PRIMARIES
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA

These are output parameters for conversion and data for VUI:
AMF_VIDEO_ENCODER_OUTPUT_COLOR_PROFILE – for VUI only, used if color
conversion is done outside of AMF
AMF_VIDEO_ENCODER_OUTPUT_TRANSFER_CHARACTERISTIC
AMF_VIDEO_ENCODER_OUTPUT_COLOR_PRIMARIES
AMF_VIDEO_ENCODER_OUTPUT_HDR_METADATA

It would be possible to add unsupported color matrices via editing VUI in
the output stream but it is better to do it via a separate patch as
supported covers most common use cases.


> > +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_profil

Re: [FFmpeg-devel] [PATCH] avcodec/amfenc: Fix for windows imprecise sleep

2023-10-17 Thread Evgeny Pavlov
The reason for using av_usleep() here is that AMF API doesn’t provide an
API for explicit wait. There are two modes to get output from encoder:

1. Polling with some sleep to avoid CPU thrashing – currently used in FFmpeg

2. Set timeout parameter on AMF encoder and QueryOutput call will block
till output is available or the timeout happens.

#2 is the preferable way but it is designed more to be used with a separate
polling thread. With a single-thread approach in FFmpeg, the use of timeout
can block input submission making things slower.  This is even more
pronounced when B-frames are enabled and several inputs are needed to produce
the first output.

The condition of this sleep is in special events (primarily when amf input
queue is full), not the core loop part. During the experiments the cpu
increasing is about 2-4% or so, not a burst.

For low resolution encoding,  these changes bring significant performance
improvement (about 15%). It will not bring improvement for high resolution
such as 4K.


Thanks,

Evgeny

вт, 17 окт. 2023 г. в 03:26, Zhao Zhili :

>
> > 在 2023年10月17日,上午5:24,Mark Thompson  写道:
> >
> > On 16/10/2023 10:13, Evgeny Pavlov wrote:
> >> This commit reduces the sleep time on Windows to improve AMF encoding
> >> performance on low resolution input videos.
> >> This fix is for Windows only, because sleep() function isn't
> >> very accurate on Windows OS.
> >> Fix for issue #10622
> >> Signed-off-by: Evgeny Pavlov 
> >> ---
> >>  libavcodec/amfenc.c | 4 
> >>  1 file changed, 4 insertions(+)
> >> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> >> index 061859f85c..0c95465d6e 100644
> >> --- a/libavcodec/amfenc.c
> >> +++ b/libavcodec/amfenc.c
> >> @@ -770,7 +770,11 @@ int ff_amf_receive_packet(AVCodecContext *avctx,
> AVPacket *avpkt)
> >>  if (query_output_data_flag == 0) {
> >>  if (res_resubmit == AMF_INPUT_FULL || ctx->delayed_drain
> || (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >=
> ctx->hwsurfaces_in_queue_max)) {
> >>  block_and_wait = 1;
> >> +#ifdef _WIN32
> >> +av_usleep(0); //Sleep() is not precise on Windows OS.
> >> +#else
> >>  av_usleep(1000);
> >> +#endif
> >>  }
> >>  }
> >>  } while (block_and_wait);
> >
> > Wasting lots of power by spinning on a CPU core does not seem like a
> good answer to this problem.  (I mean, presumably that is why Windows isn't
> honouring your request for a short sleep, because it wants timers to have
> larger gaps to avoid wasting power.)
>
> If av_usleep is implemented via Sleep like current case, sleep 0 means
> yield current thread, so it’s not busy wait in normal case (but it can be
> busy wait).
>
> av_usleep(500) may looks better and do the same job by depending 500/1000
> = 0.
>
> I agree use sleep without real async is like a bug.
>
> >
> > Why is there a sleep here at all, anyway?  An API for hardware encoding
> should be providing a way for the caller to wait for an outstanding
> operation to complete.
> >
> > Thanks,
> >
> > - Mark
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] avcodec/amfenc: Fix for windows imprecise sleep

2023-10-16 Thread Evgeny Pavlov
This commit reduces the sleep time on Windows to improve AMF encoding
performance on low resolution input videos.
This fix is for Windows only, because sleep() function isn't
very accurate on Windows OS.

Fix for issue #10622

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

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..0c95465d6e 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -770,7 +770,11 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 if (query_output_data_flag == 0) {
 if (res_resubmit == AMF_INPUT_FULL || ctx->delayed_drain || 
(ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >= 
ctx->hwsurfaces_in_queue_max)) {
 block_and_wait = 1;
+#ifdef _WIN32
+av_usleep(0); //Sleep() is not precise on Windows OS.
+#else
 av_usleep(1000);
+#endif
 }
 }
 } while (block_and_wait);
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH 10 bit support, v4, 3/3] avcodec/amfenc: add 10 bit encoding in av1_amf

2023-10-09 Thread 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 8f13aea29e..634eeea48f 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.41.0

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

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


[FFmpeg-devel] [PATCH 10 bit support, v4, 2/3] avcodec/amfenc: HDR metadata.

2023-10-09 Thread Evgeny Pavlov
From: nyanmisaka 

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

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

[FFmpeg-devel] [PATCH avcodec/amfenc: 10 bit support, v4, 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-10-09 Thread Evgeny Pavlov
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

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 

[FFmpeg-devel] [PATCH] avfilter/vf_ssim: Fix x86 assembly code for SSIM calculation

2023-07-31 Thread Evgeny Pavlov
This commit fixes bug #10495

The code had several bugs related to post-loop compensation code:
- test assembly instruction performs bitwise AND operation and
generate flags used by jz branch instruction. Wrong test condition
leads to incorrect branching
- Incorrect compensation code for some branches

Signed-off-by: Evgeny Pavlov 
---
 libavfilter/x86/vf_ssim.asm | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/libavfilter/x86/vf_ssim.asm b/libavfilter/x86/vf_ssim.asm
index 78809305de..e3e0c8104b 100644
--- a/libavfilter/x86/vf_ssim.asm
+++ b/libavfilter/x86/vf_ssim.asm
@@ -228,25 +228,22 @@ cglobal ssim_end_line, 3, 3, 7, sum0, sum1, w
 
 ; subpd the ones we added too much
 test  wd, wd
-jz .end
+jz   .end
 add   wd, 4
-test  wd, 3
-jz .skip3
-test  wd, 2
-jz .skip2
-test  wd, 1
-jz .skip1
-.skip3:
+cmp   wd, 1
+jz   .skip3
+cmp   wd, 2
+jz   .skip2
+.skip1:   ; 3 valid => skip 1 invalid
 psrldqm5, 8
 subpd m6, m5
-jmp .end
-.skip2:
-psrldqm5, 8
+jmp  .end
+.skip2:   ; 2 valid => skip 2 invalid
 subpd m6, m5
+jmp  .end
+.skip3:   ; 1 valid => skip 3 invalid
+psrldqm3, 8
 subpd m0, m3
-jmp .end
-.skip1:
-psrldqm3, 16
 subpd m6, m5
 
 .end:
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH avcodec/amfenc:, 10, bit, support, v3, 3/3] avcodec/amfenc: add 10 bit encoding in av1_amf

2023-07-26 Thread Evgeny Pavlov
Signed-off-by: Evgeny Pavlov 
Co-authored-by: Dmitrii Ovchinnikov 
---
 libavcodec/amfenc_av1.c | 47 +
 1 file changed, 47 insertions(+)

diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 30c0a9fad2..5c5313001d 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,50 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_PROFILE, profile);
 
+// Color Metadata
+/// Color Space & 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;
+}
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
+
+if (avctx->color_range == AVCOL_RANGE_JPEG) {
+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 {
+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;
+}
+}
+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 == FF_LEVEL_UNKNOWN) {
 profile_level = ctx->level;
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH avcodec/amfenc:, 10, bit, support, v3, 2/3] avcodec/amfenc: HDR metadata.

2023-07-26 Thread Evgeny Pavlov
From: nyanmisaka 

---
 libavcodec/amfenc.c | 83 +
 1 file changed, 83 insertions(+)

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

[FFmpeg-devel] [PATCH avcodec/amfenc:, 10, bit, support, v3, 1/3] avcodec/amfenc: Fixes the color information in the output.

2023-07-26 Thread Evgeny Pavlov
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 -  8bit file
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
---
 libavcodec/amfenc.c  |  2 ++
 libavcodec/amfenc.h  |  1 +
 libavcodec/amfenc_h264.c | 49 -
 libavcodec/amfenc_hevc.c | 58 +++-
 4 files changed, 108 insertions(+), 2 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index cb48f8c273..1d863afdc4 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 },
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..267eb593a2 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -21,6 +21,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index 2380aa4e90..4b6708ca8f 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -199,6 +199,9 @@ 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_depth;
+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 +265,54 @@ 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)
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
+// Color Metadata
+/// Color Range (Support for older Drivers)
 if (avctx->color_range == AVCOL_RANGE_JPEG) {
 AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, 1);
+/// 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 {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_FULL_RANGE_COLOR, 0);
+/// 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;
+}
 }
+/// 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_COLOR_BIT_DEPTH, color_depth);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_OU

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

2023-07-24 Thread 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 
---
Changes in v2:
 - Enable low latency mode when smart access video explicitly enabled 
 - Set default value for SAV to -1 (auto)

 libavcodec/amfenc.h  |  1 +
 libavcodec/amfenc_av1.c  | 17 +
 libavcodec/amfenc_h264.c | 17 +
 libavcodec/amfenc_hevc.c | 17 +
 4 files changed, 52 insertions(+)

diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..e8d66164ed 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -89,6 +89,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 30c0a9fad2..d22d86ccd7 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 },
 
@@ -241,6 +243,21 @@ 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");
+return AVERROR(EINVAL);
+} 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 2380aa4e90..de08d9a7cc 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 },
 
@@ -353,6 +355,21 @@ 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");
+return AVERROR(EINVAL);
+}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) {
 AM

[FFmpeg-devel] [PATCH] libavcodec/amfenc: add smart access video option

2023-07-20 Thread 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  | 4 
 libavcodec/amfenc_h264.c | 4 
 libavcodec/amfenc_hevc.c | 4 
 4 files changed, 13 insertions(+)

diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..e8d66164ed 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -89,6 +89,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 30c0a9fad2..c2c6f75266 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 = 0  }, 0, 1, 
VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -241,6 +243,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 // 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 2380aa4e90..c0836b4ec2 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 = 0  }, 0, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -353,6 +355,8 @@ 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");
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 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 dd232cc8ac..5436583403 100644
--- a/libavcodec/amfenc_hevc.c
+++ b/libavcodec/amfenc_hevc.c
@@ -99,6 +99,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 = 0  }, 0, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -241,6 +243,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 // Pre-Pass, Pre-Analysis, Two-Pass
 if (ctx->rate_control_mode == 
AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH] libavcodec/amfenc: add smart access video option

2023-07-20 Thread Evgeny Pavlov
This commit adds option for enabling SmartAccess Video (SAV) in AMF encoders.
SmartAccess video - 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  | 4 
 libavcodec/amfenc_h264.c | 4 
 libavcodec/amfenc_hevc.c | 4 
 4 files changed, 13 insertions(+)

diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..e8d66164ed 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -89,6 +89,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 30c0a9fad2..c2c6f75266 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 = 0  }, 0, 1, 
VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -241,6 +243,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 // 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 2380aa4e90..c0836b4ec2 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 = 0  }, 0, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -353,6 +355,8 @@ 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");
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 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 dd232cc8ac..5436583403 100644
--- a/libavcodec/amfenc_hevc.c
+++ b/libavcodec/amfenc_hevc.c
@@ -99,6 +99,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 = 0  }, 0, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -241,6 +243,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video);
+
 // Pre-Pass, Pre-Analysis, Two-Pass
 if (ctx->rate_control_mode == 
AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);
-- 
2.41.0

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

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


[FFmpeg-devel] [PATCH] libavcodec/amfenc: Add more pixel formats support

2023-07-18 Thread Evgeny Pavlov
This commit adds BGRA, RGBA and ARGB pixel formats for AMF encoders

Signed-off-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index cb48f8c273..234cd012ef 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -74,6 +74,9 @@ static const FormatMap format_map[] =
 { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
 { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
 { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_BGRA,   AMF_SURFACE_BGRA },
+{ AV_PIX_FMT_RGBA,   AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_ARGB,   AMF_SURFACE_ARGB },
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
 { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
 { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
-- 
2.37.3.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] libavcodec/amfenc: Fix issue with missing headers in AV1 encoder

2023-07-12 Thread Evgeny Pavlov
This commit fixes issue with missing SPS/PPS headers in video
encoded by AMF AV1 encoder.
Missing headers leads to broken seek in MPV video player.
Default value for property AV1_HEADER_INSERTION_MODE shouldn't be setup
to NONE (no headers insertion). We need to skip definition of this property,
because default value depends on USAGE property.

Signed-off-by: Evgeny Pavlov 
---
 libavcodec/amfenc_av1.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 30c0a9fad2..0a58a0808a 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -77,7 +77,7 @@ static const AVOption options[] = {
 { "qvbr_quality_level", "Sets the QVBR quality level",  
OFFSET(qvbr_quality_level), AV_OPT_TYPE_INT,   {.i64 = -1 }, -1, 
51, VE },
 
 
-{ "header_insertion_mode",  "Set header insertion mode",
OFFSET(header_insertion_mode),  AV_OPT_TYPE_INT,{.i64 = 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE }, 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE, 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED, VE, "hdrmode" },
+{ "header_insertion_mode",  "Set header insertion mode",
OFFSET(header_insertion_mode),  AV_OPT_TYPE_INT,{.i64 = -1 }, -1, 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED, VE, "hdrmode" },
 { "none",   "", 0, AV_OPT_TYPE_CONST, {.i64 = 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE  }, 0, 0, VE, 
"hdrmode" },
 { "gop","", 0, AV_OPT_TYPE_CONST, {.i64 = 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_GOP_ALIGNED   }, 0, 0, VE, 
"hdrmode" },
 { "frame",  "", 0, AV_OPT_TYPE_CONST, {.i64 = 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED }, 0, 0, VE, 
"hdrmode" },
@@ -220,7 +220,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 // Picture control properties
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_GOP_SIZE, avctx->gop_size);
 
-AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE, ctx->header_insertion_mode);
+// Setup header insertion mode only if this option was defined explicitly
+if (ctx->header_insertion_mode != -1)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE, ctx->header_insertion_mode);
 
 // Rate control
 // autodetect rate control method
-- 
2.39.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] libavcodec/amfenc: Fix issue with missing headers in AV1 encoder

2023-07-12 Thread Evgeny Pavlov
This commit fixes issue with missing SPS/PPS headers in video

encoded by AMF AV1 encoder.

Missing headers leads to broken seek in MPV video player.

Default value for property AV1_HEADER_INSERTION_MODE shouldn't be setup

to NONE (no headers insertion). We need to skip definition of this property,

because default value depends on USAGE property.



Signed-off-by: Evgeny Pavlov 

---

 libavcodec/amfenc_av1.c | 6 --

 1 file changed, 4 insertions(+), 2 deletions(-)



diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c

index 30c0a9fad2..0a58a0808a 100644

--- a/libavcodec/amfenc_av1.c

+++ b/libavcodec/amfenc_av1.c

@@ -77,7 +77,7 @@ static const AVOption options[] = {

 { "qvbr_quality_level", "Sets the QVBR quality
level",  OFFSET(qvbr_quality_level),
AV_OPT_TYPE_INT,   {.i64 = -1 }, -1, 51, VE },





-{ "header_insertion_mode",  "Set header insertion
mode",OFFSET(header_insertion_mode),
AV_OPT_TYPE_INT,{.i64 = AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE },
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE,
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED, VE,
"hdrmode" },

+{ "header_insertion_mode",  "Set header insertion
mode",OFFSET(header_insertion_mode),
AV_OPT_TYPE_INT,{.i64 = -1 }, -1,
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED, VE,
"hdrmode" },

 { "none",   "", 0, AV_OPT_TYPE_CONST, {.i64 =
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_NONE  }, 0, 0, VE,
"hdrmode" },

 { "gop","", 0, AV_OPT_TYPE_CONST, {.i64 =
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_GOP_ALIGNED   }, 0, 0, VE,
"hdrmode" },

 { "frame",  "", 0, AV_OPT_TYPE_CONST, {.i64 =
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED }, 0, 0, VE,
"hdrmode" },

@@ -220,7 +220,9 @@ FF_ENABLE_DEPRECATION_WARNINGS

 // Picture control properties

 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder,
AMF_VIDEO_ENCODER_AV1_GOP_SIZE, avctx->gop_size);



-AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder,
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE, ctx->header_insertion_mode);

+// Setup header insertion mode only if this option was defined
explicitly

+if (ctx->header_insertion_mode != -1)

+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder,
AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE, ctx->header_insertion_mode);



 // Rate control

 // autodetect rate control method

-- 

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