Re: [FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-10-25 Thread Mohammad Izadi
Michael, I appreciate it if you can take a look and give me your feedback.

Thanks,
Mohammad


On Thu, Sep 8, 2022 at 10:03 AM Mohammad Izadi  wrote:

> Michael, I appreciate it if you can take a look and give me your feedback.
>
>
> On Thu, Sep 8, 2022 at 9:31 AM Michael Niedermayer 
> wrote:
>
>> On Wed, Sep 07, 2022 at 02:12:46PM +0100, Derek Buitenhuis wrote:
>> > On 9/6/2022 10:47 PM, Mohammad Izadi wrote:
>> > > +if (side_data && side_data_size > 0)
>> > > +
>> ff_write_dynamic_hdr10_plus_to_full_itu_t_t35((AVDynamicHDRPlus*)side_data,
>> _plus_itu_t_t35, _plus_itu_t_t35_size);
>> >
>> > You can't use ff_-prefixed functions across library boundaries.
>> >
>> > It nees to be either public (av*) or avpriv. I suspect people won't
>> want it to
>> > be avpriv.
>> >
>> > Personally, I think having serialization as a public API is useful, but
>> YMMV. Mostly
>> > because I was just writing my own serialization to make use of the
>> exported side data :P.
>>
>> I agree
>>
>> on a related subject, side data serialization should be moved to a common
>> API
>> We have common APIs for parsers, decoder, bitstream filters but for
>> parsing/decoding side data this is heading toward something less
>> structured
>>
>> Above is not a comment on this patch, the patch is fine. I just want to
>> point
>> to this before we have several dozen such functions which need to be
>> deprecated and supported when a more structured system is introduced
>>
>> thx
>>
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> Into a blind darkness they enter who follow after the Ignorance,
>> they as if into a greater darkness enter who devote themselves
>> to the Knowledge alone. -- Isha Upanishad
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-09-08 Thread Mohammad Izadi
Michael, I appreciate it if you can take a look and give me your feedback.


On Thu, Sep 8, 2022 at 9:31 AM Michael Niedermayer 
wrote:

> On Wed, Sep 07, 2022 at 02:12:46PM +0100, Derek Buitenhuis wrote:
> > On 9/6/2022 10:47 PM, Mohammad Izadi wrote:
> > > +if (side_data && side_data_size > 0)
> > > +
> ff_write_dynamic_hdr10_plus_to_full_itu_t_t35((AVDynamicHDRPlus*)side_data,
> _plus_itu_t_t35, _plus_itu_t_t35_size);
> >
> > You can't use ff_-prefixed functions across library boundaries.
> >
> > It nees to be either public (av*) or avpriv. I suspect people won't want
> it to
> > be avpriv.
> >
> > Personally, I think having serialization as a public API is useful, but
> YMMV. Mostly
> > because I was just writing my own serialization to make use of the
> exported side data :P.
>
> I agree
>
> on a related subject, side data serialization should be moved to a common
> API
> We have common APIs for parsers, decoder, bitstream filters but for
> parsing/decoding side data this is heading toward something less structured
>
> Above is not a comment on this patch, the patch is fine. I just want to
> point
> to this before we have several dozen such functions which need to be
> deprecated and supported when a more structured system is introduced
>
> thx
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Into a blind darkness they enter who follow after the Ignorance,
> they as if into a greater darkness enter who devote themselves
> to the Knowledge alone. -- Isha Upanishad
> ___
> 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] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-09-07 Thread Mohammad Izadi
The fate test file can be found here: 
https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
The video file needs to be copied to fate-suite/mkv/
---
 libavcodec/dynamic_hdr10_plus.c | 269 +---
 libavcodec/dynamic_hdr10_plus.h |  26 +-
 libavformat/matroska.h  |   5 +
 libavformat/matroskadec.c   |  30 ++-
 libavformat/matroskaenc.c   |  44 +++-
 tests/fate/matroska.mak |   6 +
 tests/ref/fate/matroska-hdr10-plus-metadata |  74 ++
 7 files changed, 397 insertions(+), 57 deletions(-)
 create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata

diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
index 34a44aac65..d05f211c94 100644
--- a/libavcodec/dynamic_hdr10_plus.c
+++ b/libavcodec/dynamic_hdr10_plus.c
@@ -18,6 +18,12 @@
 
 #include "dynamic_hdr10_plus.h"
 #include "get_bits.h"
+#include "put_bits.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static const int64_t luminance_den = 1;
 static const int32_t peak_luminance_den = 15;
@@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
 static const int32_t bezier_anchor_den = 1023;
 static const int32_t saturation_weight_den = 8;
 
-int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
uint8_t *data,
- int size)
+int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
uint8_t* data,
+int size)
 {
 GetBitContext gbc, *gb = 
 int ret;
@@ -40,10 +46,12 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 if (ret < 0)
 return ret;
 
-if (get_bits_left(gb) < 10)
+if (get_bits_left(gb) < 8)
 return AVERROR_INVALIDDATA;
+ s->application_version = get_bits(gb, 8);
 
-s->application_version = get_bits(gb, 8);
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
 s->num_windows = get_bits(gb, 2);
 
 if (s->num_windows < 1 || s->num_windows > 3) {
@@ -56,15 +64,11 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 for (int w = 1; w < s->num_windows; w++) {
 // The corners are set to absolute coordinates here. They should be
 // converted to the relative coordinates (in [0, 1]) in the decoder.
-AVHDRPlusColorTransformParams *params = >params[w];
-params->window_upper_left_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_upper_left_corner_y =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_y =
-(AVRational){get_bits(gb, 16), 1};
+AVHDRPlusColorTransformParams* params = >params[w];
+params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
 
 params->center_of_ellipse_x = get_bits(gb, 16);
 params->center_of_ellipse_y = get_bits(gb, 16);
@@ -78,8 +82,7 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (get_bits_left(gb) < 28)
 return AVERROR_INVALIDDATA;
 
-s->targeted_system_display_maximum_luminance =
-(AVRational){get_bits_long(gb, 27), luminance_den};
+s->targeted_system_display_maximum_luminance = (AVRational) { 
get_bits_long(gb, 27), luminance_den };
 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
 
 if (s->targeted_system_display_actual_peak_luminance_flag) {
@@ -99,22 +102,19 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 
 for (int i = 0; i < rows; i++) {
 for (int j = 0; j < cols; j++) {
-s->targeted_system_display_actual_peak_luminance[i][j] =
-(AVRational){get_bits(gb, 4), peak_luminance_den};
+s->targeted_system_display_actual_peak_luminance[i][j] = 
(AVRational) { get_bits(gb, 4), peak_luminance_den };
 }
 }
 }
 for (int w = 0; w < s->num_windows; w++) {
-AVHDRPlusColorTransformParams *params = >params[w];
+AVHDRPlusColorTransformParams* params = >params[w];
 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
 return AVERROR_INVALIDDATA;
 
 for (int i = 0; i < 3; i++) {
-params->maxscl[i] =
-(AVRational){get_bits(gb, 

Re: [FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-09-07 Thread Mohammad Izadi
Thank you Derek for your comment ! It’s fixed.


On Wed, Sep 7, 2022 at 6:13 AM Derek Buitenhuis 
wrote:

> On 9/6/2022 10:47 PM, Mohammad Izadi wrote:
> > +if (side_data && side_data_size > 0)
> > +
> ff_write_dynamic_hdr10_plus_to_full_itu_t_t35((AVDynamicHDRPlus*)side_data,
> _plus_itu_t_t35, _plus_itu_t_t35_size);
>
> You can't use ff_-prefixed functions across library boundaries.
>
> It nees to be either public (av*) or avpriv. I suspect people won't want
> it to
> be avpriv.
>
> Personally, I think having serialization as a public API is useful, but
> YMMV. Mostly
> because I was just writing my own serialization to make use of the
> exported side data :P.
>
> - Derek
> ___
> 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] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-09-06 Thread Mohammad Izadi
The fate test file can be found here: 
https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
The video file needs to be copied to fate-suite/mkv/
---
 libavcodec/dynamic_hdr10_plus.c | 269 +---
 libavcodec/dynamic_hdr10_plus.h |  35 ++-
 libavformat/matroska.h  |   5 +
 libavformat/matroskadec.c   |  30 ++-
 libavformat/matroskaenc.c   |  45 +++-
 tests/fate/matroska.mak |   6 +
 tests/ref/fate/matroska-hdr10-plus-metadata |  74 ++
 7 files changed, 407 insertions(+), 57 deletions(-)
 create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata

diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
index 34a44aac65..ce15569196 100644
--- a/libavcodec/dynamic_hdr10_plus.c
+++ b/libavcodec/dynamic_hdr10_plus.c
@@ -18,6 +18,12 @@
 
 #include "dynamic_hdr10_plus.h"
 #include "get_bits.h"
+#include "put_bits.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static const int64_t luminance_den = 1;
 static const int32_t peak_luminance_den = 15;
@@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
 static const int32_t bezier_anchor_den = 1023;
 static const int32_t saturation_weight_den = 8;
 
-int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
uint8_t *data,
- int size)
+int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
uint8_t* data,
+int size)
 {
 GetBitContext gbc, *gb = 
 int ret;
@@ -40,10 +46,12 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 if (ret < 0)
 return ret;
 
-if (get_bits_left(gb) < 10)
+if (get_bits_left(gb) < 8)
 return AVERROR_INVALIDDATA;
+ s->application_version = get_bits(gb, 8);
 
-s->application_version = get_bits(gb, 8);
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
 s->num_windows = get_bits(gb, 2);
 
 if (s->num_windows < 1 || s->num_windows > 3) {
@@ -56,15 +64,11 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 for (int w = 1; w < s->num_windows; w++) {
 // The corners are set to absolute coordinates here. They should be
 // converted to the relative coordinates (in [0, 1]) in the decoder.
-AVHDRPlusColorTransformParams *params = >params[w];
-params->window_upper_left_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_upper_left_corner_y =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_y =
-(AVRational){get_bits(gb, 16), 1};
+AVHDRPlusColorTransformParams* params = >params[w];
+params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
 
 params->center_of_ellipse_x = get_bits(gb, 16);
 params->center_of_ellipse_y = get_bits(gb, 16);
@@ -78,8 +82,7 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (get_bits_left(gb) < 28)
 return AVERROR_INVALIDDATA;
 
-s->targeted_system_display_maximum_luminance =
-(AVRational){get_bits_long(gb, 27), luminance_den};
+s->targeted_system_display_maximum_luminance = (AVRational) { 
get_bits_long(gb, 27), luminance_den };
 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
 
 if (s->targeted_system_display_actual_peak_luminance_flag) {
@@ -99,22 +102,19 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 
 for (int i = 0; i < rows; i++) {
 for (int j = 0; j < cols; j++) {
-s->targeted_system_display_actual_peak_luminance[i][j] =
-(AVRational){get_bits(gb, 4), peak_luminance_den};
+s->targeted_system_display_actual_peak_luminance[i][j] = 
(AVRational) { get_bits(gb, 4), peak_luminance_den };
 }
 }
 }
 for (int w = 0; w < s->num_windows; w++) {
-AVHDRPlusColorTransformParams *params = >params[w];
+AVHDRPlusColorTransformParams* params = >params[w];
 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
 return AVERROR_INVALIDDATA;
 
 for (int i = 0; i < 3; i++) {
-params->maxscl[i] =
-(AVRational){get_bits(gb, 

Re: [FFmpeg-devel] [PATCH] Add YCOCG colorspace to input arguments of vf_colorspace.

2022-05-31 Thread Mohammad Izadi
FYI


On Thu, May 19, 2022 at 1:42 PM Mohammad Izadi  wrote:

> ffmpeg support YCOCG (YCOCG=YCGCO). However, vf_colorspace is only support
> YCGCO as input. Added YCOCG to the inputs.
> ---
>  libavfilter/vf_colorspace.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
> index 3c8b3b20eb..bccd04528e 100644
> --- a/libavfilter/vf_colorspace.c
> +++ b/libavfilter/vf_colorspace.c
> @@ -906,6 +906,7 @@ static const AVOption colorspace_options[] = {
>  ENUM("smpte170m",   AVCOL_SPC_SMPTE170M,   "csp"),
>  ENUM("smpte240m",   AVCOL_SPC_SMPTE240M,   "csp"),
>  ENUM("ycgco",   AVCOL_SPC_YCGCO,   "csp"),
> +ENUM("ycocg",   AVCOL_SPC_YCOCG,   "csp"),
>  ENUM("gbr", AVCOL_SPC_RGB, "csp"),
>  ENUM("bt2020nc",AVCOL_SPC_BT2020_NCL,  "csp"),
>  ENUM("bt2020ncl",   AVCOL_SPC_BT2020_NCL,  "csp"),
> --
> 2.36.1.124.g0e6072fb45-goog
>
>
___
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] Add YCOCG colorspace to input arguments of vf_colorspace.

2022-05-19 Thread Mohammad Izadi
ffmpeg support YCOCG (YCOCG=YCGCO). However, vf_colorspace is only support 
YCGCO as input. Added YCOCG to the inputs.
---
 libavfilter/vf_colorspace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
index 3c8b3b20eb..bccd04528e 100644
--- a/libavfilter/vf_colorspace.c
+++ b/libavfilter/vf_colorspace.c
@@ -906,6 +906,7 @@ static const AVOption colorspace_options[] = {
 ENUM("smpte170m",   AVCOL_SPC_SMPTE170M,   "csp"),
 ENUM("smpte240m",   AVCOL_SPC_SMPTE240M,   "csp"),
 ENUM("ycgco",   AVCOL_SPC_YCGCO,   "csp"),
+ENUM("ycocg",   AVCOL_SPC_YCOCG,   "csp"),
 ENUM("gbr", AVCOL_SPC_RGB, "csp"),
 ENUM("bt2020nc",AVCOL_SPC_BT2020_NCL,  "csp"),
 ENUM("bt2020ncl",   AVCOL_SPC_BT2020_NCL,  "csp"),
-- 
2.36.1.124.g0e6072fb45-goog

___
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] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-03-30 Thread Mohammad Izadi
From: Gyan Doshi 

The fate test file can be found here: 
https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
The video file needs to be copied to fate-suite/mkv/
---
 libavcodec/dynamic_hdr10_plus.c | 269 +---
 libavcodec/dynamic_hdr10_plus.h |  35 ++-
 libavformat/matroska.h  |   5 +
 libavformat/matroskadec.c   |  30 ++-
 libavformat/matroskaenc.c   |  44 +++-
 tests/fate/matroska.mak |   6 +
 tests/ref/fate/matroska-hdr10-plus-metadata | 152 +++
 7 files changed, 484 insertions(+), 57 deletions(-)
 create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata

diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
index 34a44aac65..ce15569196 100644
--- a/libavcodec/dynamic_hdr10_plus.c
+++ b/libavcodec/dynamic_hdr10_plus.c
@@ -18,6 +18,12 @@
 
 #include "dynamic_hdr10_plus.h"
 #include "get_bits.h"
+#include "put_bits.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static const int64_t luminance_den = 1;
 static const int32_t peak_luminance_den = 15;
@@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
 static const int32_t bezier_anchor_den = 1023;
 static const int32_t saturation_weight_den = 8;
 
-int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
uint8_t *data,
- int size)
+int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
uint8_t* data,
+int size)
 {
 GetBitContext gbc, *gb = 
 int ret;
@@ -40,10 +46,12 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 if (ret < 0)
 return ret;
 
-if (get_bits_left(gb) < 10)
+if (get_bits_left(gb) < 8)
 return AVERROR_INVALIDDATA;
+ s->application_version = get_bits(gb, 8);
 
-s->application_version = get_bits(gb, 8);
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
 s->num_windows = get_bits(gb, 2);
 
 if (s->num_windows < 1 || s->num_windows > 3) {
@@ -56,15 +64,11 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 for (int w = 1; w < s->num_windows; w++) {
 // The corners are set to absolute coordinates here. They should be
 // converted to the relative coordinates (in [0, 1]) in the decoder.
-AVHDRPlusColorTransformParams *params = >params[w];
-params->window_upper_left_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_upper_left_corner_y =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_y =
-(AVRational){get_bits(gb, 16), 1};
+AVHDRPlusColorTransformParams* params = >params[w];
+params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
 
 params->center_of_ellipse_x = get_bits(gb, 16);
 params->center_of_ellipse_y = get_bits(gb, 16);
@@ -78,8 +82,7 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (get_bits_left(gb) < 28)
 return AVERROR_INVALIDDATA;
 
-s->targeted_system_display_maximum_luminance =
-(AVRational){get_bits_long(gb, 27), luminance_den};
+s->targeted_system_display_maximum_luminance = (AVRational) { 
get_bits_long(gb, 27), luminance_den };
 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
 
 if (s->targeted_system_display_actual_peak_luminance_flag) {
@@ -99,22 +102,19 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 
 for (int i = 0; i < rows; i++) {
 for (int j = 0; j < cols; j++) {
-s->targeted_system_display_actual_peak_luminance[i][j] =
-(AVRational){get_bits(gb, 4), peak_luminance_den};
+s->targeted_system_display_actual_peak_luminance[i][j] = 
(AVRational) { get_bits(gb, 4), peak_luminance_den };
 }
 }
 }
 for (int w = 0; w < s->num_windows; w++) {
-AVHDRPlusColorTransformParams *params = >params[w];
+AVHDRPlusColorTransformParams* params = >params[w];
 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
 return AVERROR_INVALIDDATA;
 
 for (int i = 0; i < 3; i++) {
-params->maxscl[i] =
-

Re: [FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2021-08-18 Thread Mohammad Izadi
On Tue, Aug 17, 2021 at 9:41 PM Gyan Doshi  wrote:

>
>
> On 2021-08-18 04:10 am, Mohammad Izadi wrote:
> > From: Gyan Doshi 
>
> Can you refresh my memory on how I'm involved?
>
Don't know. Sent to ffmpeg-devel@ffmpeg.org.

>
> >
> > The fate test file can be found here:
> https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
> > The video file needs to be copied to fate-suite/mkv/
> > ---
> >   libavcodec/dynamic_hdr10_plus.c | 273 +---
> >   libavcodec/dynamic_hdr10_plus.h |  35 ++-
> >   libavformat/matroska.h  |   5 +
> >   libavformat/matroskadec.c   |  30 ++-
> >   libavformat/matroskaenc.c   |  47 ++--
> >   tests/fate/matroska.mak |   6 +
> >   tests/ref/fate/matroska-hdr10-plus-metadata | 150 +++
> >   7 files changed, 484 insertions(+), 62 deletions(-)
> >   create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata
> >
> > diff --git a/libavcodec/dynamic_hdr10_plus.c
> b/libavcodec/dynamic_hdr10_plus.c
> > index a602e606ed..df7828a476 100644
> > --- a/libavcodec/dynamic_hdr10_plus.c
> > +++ b/libavcodec/dynamic_hdr10_plus.c
> > @@ -18,6 +18,12 @@
> >
> >   #include "dynamic_hdr10_plus.h"
> >   #include "get_bits.h"
> > +#include "put_bits.h"
> > +
> > +static const uint8_t usa_country_code = 0xB5;
> > +static const uint16_t smpte_provider_code = 0x003C;
> > +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > +static const uint16_t smpte2094_40_application_identifier = 0x04;
> >
> >   static const int64_t luminance_den = 1;
> >   static const int32_t peak_luminance_den = 15;
> > @@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
> >   static const int32_t bezier_anchor_den = 1023;
> >   static const int32_t saturation_weight_den = 8;
> >
> > -int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const
> uint8_t *data,
> > - int size)
> > +int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const
> uint8_t* data,
> > +  int size)
> >   {
> >   GetBitContext gbc, *gb = 
> >   int ret;
> > @@ -40,7 +46,9 @@ int
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
> >   if (ret < 0)
> >   return ret;
> >
> > -s->application_version = get_bits(gb, 8);
> > +if (get_bits_left(gb) < 8)
> > +return AVERROR_INVALIDDATA;
> > + s->application_version = get_bits(gb, 8);
> >
> >   if (get_bits_left(gb) < 2)
> >   return AVERROR_INVALIDDATA;
> > @@ -56,15 +64,11 @@ int
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
> >   for (int w = 1; w < s->num_windows; w++) {
> >   // The corners are set to absolute coordinates here. They
> should be
> >   // converted to the relative coordinates (in [0, 1]) in the
> decoder.
> > -AVHDRPlusColorTransformParams *params = >params[w];
> > -params->window_upper_left_corner_x =
> > -(AVRational){get_bits(gb, 16), 1};
> > -params->window_upper_left_corner_y =
> > -(AVRational){get_bits(gb, 16), 1};
> > -params->window_lower_right_corner_x =
> > -(AVRational){get_bits(gb, 16), 1};
> > -params->window_lower_right_corner_y =
> > -(AVRational){get_bits(gb, 16), 1};
> > +AVHDRPlusColorTransformParams* params = >params[w];
> > +params->window_upper_left_corner_x = (AVRational) {
> get_bits(gb, 16), 1 };
> > +params->window_upper_left_corner_y = (AVRational) {
> get_bits(gb, 16), 1 };
> > +params->window_lower_right_corner_x = (AVRational) {
> get_bits(gb, 16), 1 };
> > +params->window_lower_right_corner_y = (AVRational) {
> get_bits(gb, 16), 1 };
> >
> >   params->center_of_ellipse_x = get_bits(gb, 16);
> >   params->center_of_ellipse_y = get_bits(gb, 16);
> > @@ -78,8 +82,7 @@ int
> ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
> >   if (get_bits_left(gb) < 28)
> >   return AVERROR(EINVAL);
> >
> > -s->targeted_system_display_maximum_luminance =
> > -(AVRational){get_bits_long(gb, 27), luminance_den};
> > +s-

[FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2021-08-17 Thread Mohammad Izadi
From: Gyan Doshi 

The fate test file can be found here: 
https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
The video file needs to be copied to fate-suite/mkv/
---
 libavcodec/dynamic_hdr10_plus.c | 273 +---
 libavcodec/dynamic_hdr10_plus.h |  35 ++-
 libavformat/matroska.h  |   5 +
 libavformat/matroskadec.c   |  30 ++-
 libavformat/matroskaenc.c   |  47 ++--
 tests/fate/matroska.mak |   6 +
 tests/ref/fate/matroska-hdr10-plus-metadata | 150 +++
 7 files changed, 484 insertions(+), 62 deletions(-)
 create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata

diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
index a602e606ed..df7828a476 100644
--- a/libavcodec/dynamic_hdr10_plus.c
+++ b/libavcodec/dynamic_hdr10_plus.c
@@ -18,6 +18,12 @@
 
 #include "dynamic_hdr10_plus.h"
 #include "get_bits.h"
+#include "put_bits.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static const int64_t luminance_den = 1;
 static const int32_t peak_luminance_den = 15;
@@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
 static const int32_t bezier_anchor_den = 1023;
 static const int32_t saturation_weight_den = 8;
 
-int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
uint8_t *data,
- int size)
+int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
uint8_t* data,
+int size)
 {
 GetBitContext gbc, *gb = 
 int ret;
@@ -40,7 +46,9 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (ret < 0)
 return ret;
 
-s->application_version = get_bits(gb, 8);
+if (get_bits_left(gb) < 8)
+return AVERROR_INVALIDDATA;
+ s->application_version = get_bits(gb, 8);
 
 if (get_bits_left(gb) < 2)
 return AVERROR_INVALIDDATA;
@@ -56,15 +64,11 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 for (int w = 1; w < s->num_windows; w++) {
 // The corners are set to absolute coordinates here. They should be
 // converted to the relative coordinates (in [0, 1]) in the decoder.
-AVHDRPlusColorTransformParams *params = >params[w];
-params->window_upper_left_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_upper_left_corner_y =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_y =
-(AVRational){get_bits(gb, 16), 1};
+AVHDRPlusColorTransformParams* params = >params[w];
+params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
 
 params->center_of_ellipse_x = get_bits(gb, 16);
 params->center_of_ellipse_y = get_bits(gb, 16);
@@ -78,8 +82,7 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (get_bits_left(gb) < 28)
 return AVERROR(EINVAL);
 
-s->targeted_system_display_maximum_luminance =
-(AVRational){get_bits_long(gb, 27), luminance_den};
+s->targeted_system_display_maximum_luminance = (AVRational) { 
get_bits_long(gb, 27), luminance_den };
 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
 
 if (s->targeted_system_display_actual_peak_luminance_flag) {
@@ -99,38 +102,33 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 
 for (int i = 0; i < rows; i++) {
 for (int j = 0; j < cols; j++) {
-s->targeted_system_display_actual_peak_luminance[i][j] =
-(AVRational){get_bits(gb, 4), peak_luminance_den};
+s->targeted_system_display_actual_peak_luminance[i][j] = 
(AVRational) { get_bits(gb, 4), peak_luminance_den };
 }
 }
 }
 for (int w = 0; w < s->num_windows; w++) {
-AVHDRPlusColorTransformParams *params = >params[w];
+AVHDRPlusColorTransformParams* params = >params[w];
 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
 return AVERROR(EINVAL);
 
 for (int i = 0; i < 3; i++) {
-params->maxscl[i] =
-(AVRational){get_bits(gb, 17), rgb_den};
+params->maxscl[i] = (AVRational) { get_bits(gb, 17), rgb_den };
 }
-

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-24 Thread Mohammad Izadi
On Tue, Jun 22, 2021 at 1:47 PM James Zern 
wrote:

> On Thu, Jun 17, 2021 at 10:21 PM Mohammad Izadi
>  wrote:
> >
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 91 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 105 insertions(+), 2 deletions(-)
> >
>
> lgtm with updates for version.h and doc/APIchanges locally. I'll
> submit this soon if there aren't any additional comments.
>
Rebased.
Great, thanks!

>
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 06493763b3..ee7881e1e9 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >
> >
> >  API changes, most recent first:
> > +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
>
> 8c88a66d3c should be xx to start with since the commit hash will
> change.
>
Done.

> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-24 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 91 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 06493763b3..162b4db050 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - xx - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-06-09 - xx - lavf 59.3.100 - avformat.h
   Add pts_wrap_bits to AVStream
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index e5e4256871..568710cf4a 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1497,6 +1497,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 94932a48da..a7de6b5321 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,51 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus frame_hdr10_plus;
+while (av_fifo_size(*fifo) >= sizeof(frame_hdr10_plus)) {
+av_fifo_generic_read(*fifo, _hdr10_plus, 
sizeof(frame_hdr10_plus), NULL);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+av_fifo_generic_peek(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data) {
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return AVERROR(ENOMEM);
+}
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +436,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-21 Thread Mohammad Izadi
LGTM?


On Thu, Jun 17, 2021 at 10:21 PM Mohammad Izadi  wrote:

>
>
> On Thu, Jun 17, 2021 at 1:04 PM James Zern 
> wrote:
>
>> On Wed, Jun 16, 2021 at 3:53 PM Mohammad Izadi
>>  wrote:
>> >
>> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
>> different for VP9 and cannot store the metadata in the bit stream. HDR10+
>> should be passed to packet side data an stored in the container (mkv) for
>> VP9.
>> >
>> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
>> passing it to the AVPacket side data.
>> > ---
>> >  doc/APIchanges |  2 +
>> >  libavcodec/avpacket.c  |  1 +
>> >  libavcodec/decode.c|  1 +
>> >  libavcodec/libvpxenc.c | 91 ++
>> >  libavcodec/packet.h|  8 
>> >  libavcodec/version.h   |  4 +-
>> >  6 files changed, 105 insertions(+), 2 deletions(-)
>> >
>> > [...]
>> > +
>> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
>> > +{
>> > +FrameHDR10Plus frame_hdr10_plus;
>> > +while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
>> > +av_fifo_generic_read(*fifo, _hdr10_plus,
>> sizeof(FrameHDR10Plus), NULL);
>>
>> use sizeof(frame_hdr10_plus) in these two cases
>>
> Done
>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-17 Thread Mohammad Izadi
On Thu, Jun 17, 2021 at 1:04 PM James Zern 
wrote:

> On Wed, Jun 16, 2021 at 3:53 PM Mohammad Izadi
>  wrote:
> >
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 91 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 105 insertions(+), 2 deletions(-)
> >
> > [...]
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus frame_hdr10_plus;
> > +while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
> > +av_fifo_generic_read(*fifo, _hdr10_plus,
> sizeof(FrameHDR10Plus), NULL);
>
> use sizeof(frame_hdr10_plus) in these two cases
>
Done

> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-17 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 91 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 06493763b3..ee7881e1e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-06-09 - xx - lavf 59.3.100 - avformat.h
   Add pts_wrap_bits to AVStream
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 94932a48da..a7de6b5321 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,51 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus frame_hdr10_plus;
+while (av_fifo_size(*fifo) >= sizeof(frame_hdr10_plus)) {
+av_fifo_generic_read(*fifo, _hdr10_plus, 
sizeof(frame_hdr10_plus), NULL);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+av_fifo_generic_peek(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data) {
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return AVERROR(ENOMEM);
+}
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +436,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-16 Thread Mohammad Izadi
On Tue, Jun 15, 2021 at 5:18 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mohammad Izadi:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 91 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 105 insertions(+), 2 deletions(-)
> >
> > @@ -1620,6 +1692,25 @@ static int vpx_encode(AVCodecContext *avctx,
> AVPacket *pkt,
> >  vp9_encode_set_roi(avctx, frame->width, frame->height,
> sd);
> >  }
> >  }
> > +
> > +if (!ctx->discard_hdr10_plus) {
> > +AVFrameSideData *hdr10_plus_metadata;
> > +// Add HDR10+ metadata to queue.
> > +hdr10_plus_metadata = av_frame_get_side_data(frame,
> AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> > +if (hdr10_plus_metadata) {
> > +int err;
> > +struct FrameHDR10Plus data;
> > +data.pts = frame->pts;
> > +data.hdr10_plus =
> av_buffer_ref(hdr10_plus_metadata->buf);
> > +if (!data.hdr10_plus)
> > +return AVERROR(ENOMEM);
> > +err = add_hdr10_plus(ctx->hdr10_plus_fifo, );
> > +if (err < 0) {
> > +av_freep(_plus);
>
> This is not how you free an AVBufferRef.
>
Fixed.

>
> > +return err;
> > +}
> > +}
> > +}
> >  }
> >
> >  // this is for encoding with preset temporal layering patterns
> defined in
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-16 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 91 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 06493763b3..ee7881e1e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-06-09 - xx - lavf 59.3.100 - avformat.h
   Add pts_wrap_bits to AVStream
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 94932a48da..2b08acf11f 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,51 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus frame_hdr10_plus;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, _hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+av_fifo_generic_peek(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data) {
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return AVERROR(ENOMEM);
+}
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +436,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-15 Thread Mohammad Izadi
Thanks,
Mohammad


On Mon, Jun 14, 2021 at 5:17 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mohammad Izadi:
> > On Thu, Jun 10, 2021 at 4:05 PM Andreas Rheinhardt <
> > andreas.rheinha...@outlook.com> wrote:
> >
> >> Mohammad Izadi:
> >>> HDR10+ metadata is stored in the bit stream for HEVC. The story is
> >> different for VP9 and cannot store the metadata in the bit stream.
> HDR10+
> >> should be passed to packet side data an stored in the container (mkv)
> for
> >> VP9.
> >>>
> >>> This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> >> passing it to the AVPacket side data.
> >>> ---
> >>>  doc/APIchanges |  2 +
> >>>  libavcodec/avpacket.c  |  1 +
> >>>  libavcodec/decode.c|  1 +
> >>>  libavcodec/libvpxenc.c | 99 ++
> >>>  libavcodec/packet.h|  8 
> >>>  libavcodec/version.h   |  4 +-
> >>>  6 files changed, 113 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/doc/APIchanges b/doc/APIchanges
> >>> index 55171311ed..bba5b06c6a 100644
> >>> --- a/doc/APIchanges
> >>> +++ b/doc/APIchanges
> >>> @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >>>
> >>>
> >>>  API changes, most recent first:
> >>> +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> >>> +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >>>
> >>>  2021-xx-xx - xx - lavc 59.1.100 - avcodec.h codec.h
> >>>Move av_get_profile_name() from avcodec.h to codec.h.
> >>> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> >>> index 7383d12d3e..800bee3489 100644
> >>> --- a/libavcodec/avpacket.c
> >>> +++ b/libavcodec/avpacket.c
> >>> @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> >> AVPacketSideDataType type)
> >>>  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >>>  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> >> configuration record";
> >>>  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> >> 12-1:2014 timecode";
> >>> +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+
> Dynamic
> >> Metadata (SMPTE 2094-40)";
> >>>  }
> >>>  return NULL;
> >>>  }
> >>> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> >>> index 75bc7ad98e..40f688e40c 100644
> >>> --- a/libavcodec/decode.c
> >>> +++ b/libavcodec/decode.c
> >>> @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> >> AVFrame *frame)
> >>>  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> >> },
> >>>  { AV_PKT_DATA_ICC_PROFILE,
> >> AV_FRAME_DATA_ICC_PROFILE },
> >>>  { AV_PKT_DATA_S12M_TIMECODE,
> >> AV_FRAME_DATA_S12M_TIMECODE },
> >>> +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
> >>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >>>  };
> >>>
> >>>  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> >> sizeof(*pkt))
> >>> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> >>> index 66bad444d0..e2e6c60b68 100644
> >>> --- a/libavcodec/libvpxenc.c
> >>> +++ b/libavcodec/libvpxenc.c
> >>> @@ -64,6 +64,11 @@ struct FrameListData {
> >>>  struct FrameListData *next;
> >>>  };
> >>>
> >>> +typedef struct FrameHDR10Plus {
> >>> +int64_t pts;
> >>> +AVBufferRef *hdr10_plus;
> >>> +} FrameHDR10Plus;
> >>> +
> >>>  typedef struct VPxEncoderContext {
> >>>  AVClass *class;
> >>>  struct vpx_codec_ctx encoder;
> >>> @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >>>  int tune_content;
> >>>  int corpus_complexity;
> >>>  int tpl_model;
> >>> +int discard_hdr10_plus;
> >>> +AVFifoBuffer *hdr10_plus_fifo;
> >>>  /**
> >>>   * If the driver does not support ROI then warn the first time we
> >>>   * encounter a frame with ROI side data.
> >>> @@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct
> >> FrameLis

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-15 Thread Mohammad Izadi
Thanks,
Mohammad


On Mon, Jun 14, 2021 at 4:42 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mohammad Izadi:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 87 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 101 insertions(+), 2 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 06493763b3..ee7881e1e9 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >
> >
> >  API changes, most recent first:
> > +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> > +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >
> >  2021-06-09 - xx - lavf 59.3.100 - avformat.h
> >Add pts_wrap_bits to AVStream
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index 7383d12d3e..800bee3489 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
> >  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> > +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  }
> >  return NULL;
> >  }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75bc7ad98e..40f688e40c 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> >  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >  { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> > +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  };
> >
> >  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 94932a48da..308ebe1691 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -64,6 +64,11 @@ struct FrameListData {
> >  struct FrameListData *next;
> >  };
> >
> > +typedef struct FrameHDR10Plus {
> > +int64_t pts;
> > +AVBufferRef *hdr10_plus;
> > +} FrameHDR10Plus;
> > +
> >  typedef struct VPxEncoderContext {
> >  AVClass *class;
> >  struct vpx_codec_ctx encoder;
> > @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >  int tune_content;
> >  int corpus_complexity;
> >  int tpl_model;
> > +int discard_hdr10_plus;
> > +AVFifoBuffer *hdr10_plus_fifo;
> >  /**
> >   * If the driver does not support ROI then warn the first time we
> >   * encounter a frame with ROI side data.
> > @@ -316,6 +323,47 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >  }
> >  }
> >
> > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> > +{
> > +int err = av_fifo_grow(fifo, sizeof(*data));
> > +if (err < 0)
> > +return err;
> > +av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
> > +return 0;
> > +}
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus frame_hdr10_plus;
> > +while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
> > +av_fifo_generic_read(*fifo, _hdr10_plus,
> sizeof(FrameHDR10Plus), NULL);
> > +av_buffer_unref(_hdr10_plus.hdr10_plus);
> > +}
> > +av_fifo_freep(fifo);
> > +}
> > +
> > +static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
> > +{

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-15 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 91 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 06493763b3..ee7881e1e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-06-09 - xx - lavf 59.3.100 - avformat.h
   Add pts_wrap_bits to AVStream
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 94932a48da..5aaa3db06e 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,51 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus frame_hdr10_plus;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, _hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+av_fifo_generic_peek(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data) {
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return AVERROR(ENOMEM);
+}
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +436,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-14 Thread Mohammad Izadi
On Thu, Jun 10, 2021 at 4:05 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mohammad Izadi:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 99 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 113 insertions(+), 2 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 55171311ed..bba5b06c6a 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >
> >
> >  API changes, most recent first:
> > +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> > +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >
> >  2021-xx-xx - xx - lavc 59.1.100 - avcodec.h codec.h
> >Move av_get_profile_name() from avcodec.h to codec.h.
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index 7383d12d3e..800bee3489 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
> >  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> > +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  }
> >  return NULL;
> >  }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75bc7ad98e..40f688e40c 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> >  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >  { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> > +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  };
> >
> >  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 66bad444d0..e2e6c60b68 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -64,6 +64,11 @@ struct FrameListData {
> >  struct FrameListData *next;
> >  };
> >
> > +typedef struct FrameHDR10Plus {
> > +int64_t pts;
> > +AVBufferRef *hdr10_plus;
> > +} FrameHDR10Plus;
> > +
> >  typedef struct VPxEncoderContext {
> >  AVClass *class;
> >  struct vpx_codec_ctx encoder;
> > @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >  int tune_content;
> >  int corpus_complexity;
> >  int tpl_model;
> > +int discard_hdr10_plus;
> > +AVFifoBuffer *hdr10_plus_fifo;
> >  /**
> >   * If the driver does not support ROI then warn the first time we
> >   * encounter a frame with ROI side data.
> > @@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >  }
> >  }
> >
> > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> > +{
> > +int err = av_fifo_grow(fifo, sizeof(*data));
> > +if (err < 0)
> > +return err;
> > +av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
> > +return 0;
> > +}
> > +
> > +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> > +{
> > +if (!p)
> > +return;
> > +av_buffer_unref(>hdr10_plus);
> > +av_free(p);
> > +}
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus *frame_hdr10_plus = NULL;
> > +while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
> > +av_fifo_generic_read(*fifo, frame_hdr10_plus,

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-14 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 87 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 06493763b3..ee7881e1e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-06-09 - xx - lavf 59.3.100 - avformat.h
   Add pts_wrap_bits to AVStream
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 94932a48da..308ebe1691 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,47 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus frame_hdr10_plus;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, _hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+av_buffer_unref(_hdr10_plus.hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data)
+return AVERROR(ENOMEM);
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +432,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -835,6 +885,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 AVDictionaryEntry* en = NULL;
 
+ctx->discard_hdr10_plus = 1;
 av_log(avctx, AV_LOG_INFO, "%s\n", 

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-10 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 99 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 55171311ed..bba5b06c6a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-xx-xx - xx - lavc 59.1.100 - avcodec.h codec.h
   Move av_get_profile_name() from avcodec.h to codec.h.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..e2e6c60b68 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus frame_hdr10_plus;
+uint8_t *data;
+if (!pkt)
+return 0;
+if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+return 0;
+
+av_fifo_generic_read(fifo, _hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
+if (!data)
+return AVERROR(ENOMEM);
+
+memcpy(data, frame_hdr10_plus.hdr10_plus->data, 
frame_hdr10_plus.hdr10_plus->size);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +440,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ 

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-10 Thread Mohammad Izadi
On Tue, Jun 8, 2021 at 12:01 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Andreas Rheinhardt:
> > Mohammad Izadi:
> >> HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >>
> >> This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> >> ---
> >>  doc/APIchanges |  2 +
> >>  libavcodec/avpacket.c  |  1 +
> >>  libavcodec/decode.c|  1 +
> >>  libavcodec/libvpxenc.c | 99 ++
> >>  libavcodec/packet.h|  8 
> >>  libavcodec/version.h   |  4 +-
> >>  6 files changed, 113 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/doc/APIchanges b/doc/APIchanges
> >> index c46f4d5304..60995579e5 100644
> >> --- a/doc/APIchanges
> >> +++ b/doc/APIchanges
> >> @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >>
> >>
> >>  API changes, most recent first:
> >> +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> >> +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >>
> >>  2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
> >>Constified AVCodecParserContext.parser.
> >> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> >> index 7383d12d3e..800bee3489 100644
> >> --- a/libavcodec/avpacket.c
> >> +++ b/libavcodec/avpacket.c
> >> @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >>  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >>  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
> >>  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> >> +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+
> Dynamic Metadata (SMPTE 2094-40)";
> >>  }
> >>  return NULL;
> >>  }
> >> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> >> index 75bc7ad98e..40f688e40c 100644
> >> --- a/libavcodec/decode.c
> >> +++ b/libavcodec/decode.c
> >> @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >>  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> >>  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >>  { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> >> +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >>  };
> >>
> >>  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> >> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> >> index 66bad444d0..d15cf29766 100644
> >> --- a/libavcodec/libvpxenc.c
> >> +++ b/libavcodec/libvpxenc.c
> >> @@ -64,6 +64,11 @@ struct FrameListData {
> >>  struct FrameListData *next;
> >>  };
> >>
> >> +typedef struct FrameHDR10Plus {
> >> +int64_t pts;
> >> +AVBufferRef *hdr10_plus;
> >> +} FrameHDR10Plus;
> >> +
> >>  typedef struct VPxEncoderContext {
> >>  AVClass *class;
> >>  struct vpx_codec_ctx encoder;
> >> @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >>  int tune_content;
> >>  int corpus_complexity;
> >>  int tpl_model;
> >> +int discard_hdr10_plus;
> >> +AVFifoBuffer *hdr10_plus_fifo;
> >>  /**
> >>   * If the driver does not support ROI then warn the first time we
> >>   * encounter a frame with ROI side data.
> >> @@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >>  }
> >>  }
> >>
> >> +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> >> +{
> >> +int err = av_fifo_grow(fifo, sizeof(*data));
> >> +if (err < 0)
> >> +return err;
> >> +av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
> >> +return 0;
> >> +}
> >> +
> >> +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> >> +{
> >> +if (!p)
> >> +return;
>

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-08 Thread Mohammad Izadi
On Mon, Jun 7, 2021 at 12:59 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Michael Niedermayer:
> > On Mon, Jun 07, 2021 at 10:39:19AM -0700, Mohammad Izadi wrote:
> >> HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >>
> >> This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> >> ---
> >>  doc/APIchanges |  2 +
> >>  libavcodec/avpacket.c  |  1 +
> >>  libavcodec/decode.c|  1 +
> >>  libavcodec/libvpxenc.c | 98 ++
> >>  libavcodec/packet.h|  8 
> >>  libavcodec/version.h   |  4 +-
> >>  6 files changed, 112 insertions(+), 2 deletions(-)
> >
> > still crashing  ...
> >
> >  heres a test with a fate sample:
> >
> >  -i ~/fate/msmpeg4v1/mpg4.avi -vcodec libvpx -y   vpx.webm
> >
> >
> > frame=   50 fps=0.7 q=0.0 Lsize=  58kB time=00:00:01.63 bitrate=
> 288.0kbits/s speed=0.0229x
> > video:57kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: 1.558648%
> > ==26333== Invalid read of size 4
> > ==26333==at 0x1220B5E: av_fifo_size (fifo.c:79)
> > ==26333==by 0x9F64C5: free_hdr10_plus_fifo (libvpxenc.c:346)
> > ==26333==by 0x9F699D: vpx_free (libvpxenc.c:443)
> > ==26333==by 0x7A20D6: avcodec_close (avcodec.c:472)
> > ==26333==by 0xAE5002: avcodec_free_context (options.c:163)
> > ==26333==by 0x24AC0F: ffmpeg_cleanup (ffmpeg.c:609)
> > ==26333==by 0x24258A: exit_program (cmdutils.c:135)
> > ==26333==by 0x25C5AF: main (ffmpeg.c:5034)
> > ==26333==  Address 0x24 is not stack'd, malloc'd or (recently) free'd
> >
> >
> The reason is that the fifo is not allocated unconditionally, but when
> freeing it is checked whether the fifo is empty even when the fifo has
> never been allocated at all.
>
Fixed. Verified and passes now.

>
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-08 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 99 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..d15cf29766 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !frame_hdr10_plus->hdr10_plus || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +440,8 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+if (ctx->hdr10_plus_fifo)
+

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-07 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 98 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..cf7e25a4bc 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !frame_hdr10_plus->hdr10_plus || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +440,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-07 Thread Mohammad Izadi
On Mon, Jun 7, 2021 at 9:51 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mohammad Izadi:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 94 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  4 +-
> >  6 files changed, 108 insertions(+), 2 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index c46f4d5304..60995579e5 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >
> >
> >  API changes, most recent first:
> > +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> > +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >
> >  2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
> >Constified AVCodecParserContext.parser.
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index 7383d12d3e..800bee3489 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
> >  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> > +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  }
> >  return NULL;
> >  }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75bc7ad98e..40f688e40c 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> >  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >  { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> > +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  };
> >
> >  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 66bad444d0..8930f079ef 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -64,6 +64,11 @@ struct FrameListData {
> >  struct FrameListData *next;
> >  };
> >
> > +typedef struct FrameHDR10Plus {
> > +int64_t pts;
> > +AVBufferRef *hdr10_plus;
> > +} FrameHDR10Plus;
> > +
> >  typedef struct VPxEncoderContext {
> >  AVClass *class;
> >  struct vpx_codec_ctx encoder;
> > @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >  int tune_content;
> >  int corpus_complexity;
> >  int tpl_model;
> > +int discard_hdr10_plus;
> > +AVFifoBuffer *hdr10_plus_fifo;
> >  /**
> >   * If the driver does not support ROI then warn the first time we
> >   * encounter a frame with ROI side data.
> > @@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >  }
> >  }
> >
> > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> > +{
> > +int err = av_fifo_grow(fifo, sizeof(*data));
> > +if (err < 0)
> > +return err;
> > +av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
> > +return 0;
> > +}
> > +
> > +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> > +{
> > +if (!p)
> > +return;
> > +av_buffer_unref(>hdr10_plus);
> > +av_free(p);
> > +}
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus *frame_hdr10_plus = NULL;
> > +while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
> > +av_fifo_generic_read(*fifo, frame_hdr10_plus,
> sizeof(FrameHDR10P

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-07 Thread Mohammad Izadi
On Wed, Jun 2, 2021 at 1:34 PM James Zern 
wrote:

> On Tue, Jun 1, 2021 at 6:23 PM Mohammad Izadi
>  wrote:
> >
> > On Fri, May 28, 2021 at 4:49 AM Michael Niedermayer
> 
> > wrote:
> >
> > > On Thu, May 27, 2021 at 09:44:10AM -0700, Mohammad Izadi wrote:
> > > > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> > > different for VP9 and cannot store the metadata in the bit stream.
> HDR10+
> > > should be passed to packet side data an stored in the container (mkv)
> for
> > > VP9.
> > > >
> > > > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> > > passing it to the AVPacket side data.
> > > > ---
> > > >  doc/APIchanges |  2 +
> > > >  libavcodec/avpacket.c  |  1 +
> > > >  libavcodec/decode.c|  1 +
> > > >  libavcodec/libvpxenc.c | 92
> ++
> > > >  libavcodec/packet.h|  8 
> > > >  libavcodec/version.h   |  2 +-
> > > >  6 files changed, 105 insertions(+), 1 deletion(-)
> > > [...]
> > > > @@ -316,6 +323,53 @@ static av_cold void free_frame_list(struct
> > > FrameListData *list)
> > > >  }
> > > >  }
> > > >
> > > > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> > > FrameHDR10Plus *data)
> > > > +{
> > > > +int err = av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
> > > > +if (err < 0)
> > > > +return err;
> > > > +av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
> > > > +return 0;
> > > > +}
> > > > +
> > > > +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> > > > +{
> > > > +if (!p)
> > > > +return;
> > > > +av_buffer_unref(>hdr10_plus);
> > > > +av_free(p);
> > > > +}
> > > > +
> > > > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > > > +{
> > > > +FrameHDR10Plus *frame_hdr10_plus = NULL;
> > > > +while (av_fifo_generic_read(*fifo, frame_hdr10_plus,
> > > sizeof(*frame_hdr10_plus), NULL) > 0)
> > > > +free_hdr10_plus(frame_hdr10_plus);
> > > > +av_fifo_freep(fifo);
> > > > +}
> > >
> > > This seems crashing
> > >
> > Fixed. Can you please verify it?
> >
>
> Is there a way we could enable this kind of test in fate? Mohammad, do
> you have any examples of content that could be used for testing?
>
Yes. I already added a test for H265 in this patch:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20201123212933.3560940-1-iz...@google.com/
A video sample is attached in the patch as well. I will add a test in fate
in my followup patches after handling the packet in mkv  as would have
access to output.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-07 Thread Mohammad Izadi
On Wed, Jun 2, 2021 at 1:31 PM James Zern 
wrote:

> On Tue, Jun 1, 2021 at 6:47 PM Mohammad Izadi
>  wrote:
> > [...]
> > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> > +{
> > +int err = av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
>
> Prefer sizeof(var) for these to match the rest of the code.
>
Done.

> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-07 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 94 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 108 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..8930f079ef 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(*data));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !frame_hdr10_plus->hdr10_plus || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +440,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-01 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 94 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  2 +-
 6 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..ca5c1a9f71 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,55 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_size(*fifo) >= sizeof(FrameHDR10Plus)) {
+av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(FrameHDR10Plus), 
NULL);
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !frame_hdr10_plus->hdr10_plus || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +440,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-06-01 Thread Mohammad Izadi
On Fri, May 28, 2021 at 4:49 AM Michael Niedermayer 
wrote:

> On Thu, May 27, 2021 at 09:44:10AM -0700, Mohammad Izadi wrote:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 92 ++
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  2 +-
> >  6 files changed, 105 insertions(+), 1 deletion(-)
> [...]
> > @@ -316,6 +323,53 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >  }
> >  }
> >
> > +static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct
> FrameHDR10Plus *data)
> > +{
> > +int err = av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
> > +if (err < 0)
> > +return err;
> > +av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
> > +return 0;
> > +}
> > +
> > +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> > +{
> > +if (!p)
> > +return;
> > +av_buffer_unref(>hdr10_plus);
> > +av_free(p);
> > +}
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus *frame_hdr10_plus = NULL;
> > +while (av_fifo_generic_read(*fifo, frame_hdr10_plus,
> sizeof(*frame_hdr10_plus), NULL) > 0)
> > +free_hdr10_plus(frame_hdr10_plus);
> > +av_fifo_freep(fifo);
> > +}
>
> This seems crashing
>
Fixed. Can you please verify it?

>
> frame=3 fps=0.1 q=0.0 Lsize=  18kB time=00:00:01.03 bitrate=
> 145.7kbits/s speed=0.0346x
> video:3kB audio:14kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: 7.865490%
> ==21306== Invalid read of size 8
> ==21306==at 0x12203B3: av_fifo_generic_read (fifo.c:218)
> ==21306==by 0x9F5DA3: free_hdr10_plus_fifo (libvpxenc.c:346)
> ==21306==by 0x9F627A: vpx_free (libvpxenc.c:441)
> ==21306==by 0x7A1B02: avcodec_close (avcodec.c:472)
> ==21306==by 0xAE48E0: avcodec_free_context (options.c:163)
> ==21306==by 0x24AA21: ffmpeg_cleanup (ffmpeg.c:609)
> ==21306==by 0x24239C: exit_program (cmdutils.c:135)
> ==21306==by 0x25C3AB: main (ffmpeg.c:5030)
> ==21306==  Address 0x18 is not stack'd, malloc'd or (recently) free'd
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Dictatorship: All citizens are under surveillance, all their steps and
> actions recorded, for the politicians to enforce control.
> Democracy: All politicians are under surveillance, all their steps and
> actions recorded, for the citizens to enforce control.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-27 Thread Mohammad Izadi
On Wed, May 26, 2021 at 9:17 PM James Zern 
wrote:

> On Wed, May 26, 2021 at 6:35 PM Mohammad Izadi
>  wrote:
> > [...]
> > +static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus
> *data)
> > +{
> > +av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
>
> This return should be checked.
>
Done

>
> > +av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
> > +}
> >
> > [...]
> > +static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
> > +{
> > +FrameHDR10Plus *frame_hdr10_plus;
> > +uint8_t *data;
> > +if (av_fifo_size(fifo) < 1)
> > +return 0;
> > +
> > +av_fifo_generic_read(fifo, frame_hdr10_plus,
> sizeof(*frame_hdr10_plus), NULL);
> > +if (!frame_hdr10_plus || !pkt || !(frame_hdr10_plus->hdr10_plus) ||
> frame_hdr10_plus->pts != pkt->pts)
>
> The inner ()s can be remove in the hdr10_plus check
>
Done

>

>
> > -if(!avctx->bit_rate)
> > -if(avctx->rc_max_rate || avctx->rc_buffer_size ||
> avctx->rc_initial_buffer_occupancy) {
> > +if (!avctx->bit_rate)
> > +if (avctx->rc_max_rate || avctx->rc_buffer_size ||
> avctx->rc_initial_buffer_occupancy) {
>
> Let's leave the cosmetic change to a separate commit.
>
Done

>

>
> > +/**
> > + * HDR10+ dynamic metadata associated with a video frame. The
> metadata is in
> > + * the form of the AVDynamicHDRPlus struct and contains
> > + * information for color volume transform - application 4 of
> > + * SPMTE 2094-40:2016 standard.
>
> SMPTE
>
Done

>

> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-27 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 92 ++
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  2 +-
 6 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..6265e64668 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,53 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
+{
+int err = av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+if (err < 0)
+return err;
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+return 0;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_generic_read(*fifo, frame_hdr10_plus, 
sizeof(*frame_hdr10_plus), NULL) > 0)
+free_hdr10_plus(frame_hdr10_plus);
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !frame_hdr10_plus->hdr10_plus || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +438,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -835,6 +890,7 @@ 

Re: [FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-27 Thread Mohammad Izadi
All done.


On Wed, May 26, 2021 at 2:42 PM Lynne  wrote:

> May 26, 2021, 20:43 by izadi-at-google@ffmpeg.org:
>
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  doc/APIchanges |  2 +
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 89 +-
> >  libavcodec/packet.h|  8 
> >  libavcodec/version.h   |  2 +-
> >  6 files changed, 100 insertions(+), 3 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index c46f4d5304..60995579e5 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -13,6 +13,8 @@ libavutil: 2021-04-27
> >
> >
> >  API changes, most recent first:
> > +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> > +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >
> >  2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
> >  Constified AVCodecParserContext.parser.
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index 7383d12d3e..800bee3489 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >  case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration
> record";
> >  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014
> timecode";
> > +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  }
> >  return NULL;
> >  }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75bc7ad98e..40f688e40c 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
> >  { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
> >  { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE },
> > +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  };
> >
> >  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 66bad444d0..44ac90cafe 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -64,6 +64,11 @@ struct FrameListData {
> >  struct FrameListData *next;
> >  };
> >
> > +typedef struct FrameHDR10Plus {
> > +int64_t pts;
> > +AVBufferRef *hdr10_plus;
> > +} FrameHDR10Plus;
> > +
> >  typedef struct VPxEncoderContext {
> >  AVClass *class;
> >  struct vpx_codec_ctx encoder;
> > @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
> >  int tune_content;
> >  int corpus_complexity;
> >  int tpl_model;
> > +int discard_hdr10_plus;
> > +AVFifoBuffer *hdr10_plus_fifo;
> >  /**
> >  * If the driver does not support ROI then warn the first time we
> >  * encounter a frame with ROI side data.
> > @@ -316,6 +323,49 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >  }
> >  }
> >
> > +static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus
> *data)
> > +{
> > +av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
> > +av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
> > +}
> > +
> > +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> > +{
> > +if (!p) return;
> >
>
> Put the returns on a newline.
>
>
> > +av_buffer_unref(>hdr10_plus);
> > +av_free(p);
> > +}
> > +
> > +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> > +{
> > +FrameHDR10Plus *frame_hdr10_plus = NULL;
> > +while (av_fifo_generic_read(*fifo, frame_hdr10_plus,
> sizeof(*frame_hdr10_plus), NULL) > 0) {
> > +free_hdr10_plus(frame_hdr10_plus);
> > +}
> >
>
> No brackets around one-line expressions.
> Fix the coding style nits and it looks good to me.
>
> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-26 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 90 +-
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  2 +-
 6 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..3fa0dbd8e2 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,50 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data)
+{
+av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p)
+return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_generic_read(*fifo, frame_hdr10_plus, 
sizeof(*frame_hdr10_plus), NULL) > 0)
+free_hdr10_plus(frame_hdr10_plus);
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)
+return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !(frame_hdr10_plus->hdr10_plus) || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +435,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -835,6 +887,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 

[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-26 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  2 +
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 89 +-
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  2 +-
 6 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c46f4d5304..60995579e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,8 @@ libavutil: 2021-04-27
 
 
 API changes, most recent first:
+2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
 
 2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
   Constified AVCodecParserContext.parser.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7383d12d3e..800bee3489 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75bc7ad98e..40f688e40c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 66bad444d0..44ac90cafe 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -64,6 +64,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -316,6 +323,49 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data)
+{
+av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p) return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_generic_read(*fifo, frame_hdr10_plus, 
sizeof(*frame_hdr10_plus), NULL) > 0) {
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)  return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !(frame_hdr10_plus->hdr10_plus) || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -384,6 +434,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -835,6 +886,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 

Re: [FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-26 Thread Mohammad Izadi
On Tue, May 25, 2021 at 11:21 PM Moritz Barsnick  wrote:

> On Tue, May 25, 2021 at 18:53:11 -0700, Mohammad Izadi wrote:
>
> > Subject: Pass the HDR10+ metadata to the packet side data in VP9 encoder
>
> You should prefix this with "avcodec: ".
>
Done

>
> >  API changes, most recent first:
> > +2021-05-25 - xx - lavc 58.137.101 - packet.h
> > +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> > +
> >  2021-04-17 - xx - lavu 56.73.100 - frame.h detection_bbox.h
> [...]
> >  #define LIBAVCODEC_VERSION_MAJOR  58
> > -#define LIBAVCODEC_VERSION_MINOR 136
> > +#define LIBAVCODEC_VERSION_MINOR 137
> >  #define LIBAVCODEC_VERSION_MICRO 101
>
> You need to reset MICRO to 100 when bumping MINOR.
>
Done.

>
> Moritz
> ___
> 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: Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-26 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  3 ++
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 88 +-
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  4 +-
 6 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index cd3ea3c865..e3d841ac33 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2017-10-21
 
 
 API changes, most recent first:
+2021-05-25 - xx - lavc 58.137.100 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
+
 2021-04-17 - xx - lavu 56.73.100 - frame.h detection_bbox.h
   Add AV_FRAME_DATA_DETECTION_BBOXES
 
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index b5bac5c5f2..7a3b0a73e3 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0956a6ac6f..bf5fbcca97 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 3f36943c12..f2885fbda7 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -63,6 +63,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -120,6 +125,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -315,6 +322,49 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data)
+{
+av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p) return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_generic_read(*fifo, frame_hdr10_plus, 
sizeof(*frame_hdr10_plus), NULL) > 0) {
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)  return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !(frame_hdr10_plus->hdr10_plus) || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -383,6 +433,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -834,6 +885,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 

Re: [FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-25 Thread Mohammad Izadi
Answered inline:


On Tue, May 25, 2021 at 8:15 AM James Almer  wrote:

> On 4/26/2021 10:54 PM, Mohammad Izadi wrote:
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >   libavcodec/avpacket.c  |  1 +
> >   libavcodec/decode.c|  1 +
> >   libavcodec/libvpxenc.c | 88 +-
> >   libavcodec/packet.h|  8 
> >   4 files changed, 96 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index b5bac5c5f2..7a3b0a73e3 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >   case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
> >   case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
> >   case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> > +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >   }
> >   return NULL;
> >   }
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 0956a6ac6f..bf5fbcca97 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >   { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> >   { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >   { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> > +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
>
> This has nothing to do with encoding.
>
Currently it has nothing to do with encoding. We extract HDR10+ in hevc
decoder and pass it through into MKV. In the future, we will ingest HDR10+
to bitstream in hevc and av1 encoder.

>
> >   };
> >
> >   if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 3f36943c12..2096c08437 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -63,6 +63,12 @@ struct FrameListData {
> >   struct FrameListData *next;
> >   };
> >
> > +typedef struct FrameHDR10PlusList {
> > +int64_t pts;
> > +AVBufferRef *hdr10_plus;
> > +struct FrameHDR10PlusList *next;
> > +} FrameHDR10PlusList;
> > +
> >   typedef struct VPxEncoderContext {
> >   AVClass *class;
> >   struct vpx_codec_ctx encoder;
> > @@ -120,6 +126,8 @@ typedef struct VPxEncoderContext {
> >   int tune_content;
> >   int corpus_complexity;
> >   int tpl_model;
> > +int discard_hdr10_plus;
> > +struct FrameHDR10PlusList *hdr10_plus_list;
> >   /**
> >* If the driver does not support ROI then warn the first time we
> >* encounter a frame with ROI side data.
> > @@ -315,6 +323,53 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
> >   }
> >   }
> >
> > +
> > +static void add_hdr10_plus(void *list, struct FrameHDR10PlusList *data)
> > +{
> > +struct FrameHDR10PlusList **p = list;
> > +while (*p)
> > +p = &(*p)->next;
> > +*p = data;
> > +data->next = NULL;
> > +}
> > +
> > +static av_cold void free_hdr10_plus(struct FrameHDR10PlusList *p)
> > +{
> > +av_buffer_unref(>hdr10_plus);
> > +av_free(p);
> > +}
> > +
> > +static av_cold void free_hdr10_plus_list(struct FrameHDR10PlusList
> *list)
> > +{
> > +struct FrameHDR10PlusList *p = list;
> > +while (p) {
> > +list = list->next;
> > +free_hdr10_plus(p);
> > +p = list;
> > +}
> > +}
>
> This looks like it should be done with AVFifoBuffer.
>
Fixed.

>
> > +
> > +static int copy_hdr10_plus_to_pkt(void *list, AVPacket *pkt)
> > +{
> > +struct FrameHDR10PlusList **p = list;
> > +struct FrameHDR10PlusList *head = *p;
> > +
> > +if (head &am

[FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-25 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 doc/APIchanges |  3 ++
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 88 +-
 libavcodec/packet.h|  8 
 libavcodec/version.h   |  2 +-
 6 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index cd3ea3c865..28dba43476 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2017-10-21
 
 
 API changes, most recent first:
+2021-05-25 - xx - lavc 58.137.101 - packet.h
+  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
+
 2021-04-17 - xx - lavu 56.73.100 - frame.h detection_bbox.h
   Add AV_FRAME_DATA_DETECTION_BBOXES
 
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index b5bac5c5f2..7a3b0a73e3 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0956a6ac6f..bf5fbcca97 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 3f36943c12..f2885fbda7 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -63,6 +63,11 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10Plus {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+} FrameHDR10Plus;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -120,6 +125,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+AVFifoBuffer *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -315,6 +322,49 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data)
+{
+av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
+av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
+{
+if (!p) return;
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+{
+FrameHDR10Plus *frame_hdr10_plus = NULL;
+while (av_fifo_generic_read(*fifo, frame_hdr10_plus, 
sizeof(*frame_hdr10_plus), NULL) > 0) {
+free_hdr10_plus(frame_hdr10_plus);
+}
+av_fifo_freep(fifo);
+}
+
+static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+{
+FrameHDR10Plus *frame_hdr10_plus;
+uint8_t *data;
+if (av_fifo_size(fifo) < 1)  return 0;
+
+av_fifo_generic_read(fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), 
NULL);
+if (!frame_hdr10_plus || !pkt || !(frame_hdr10_plus->hdr10_plus) || 
frame_hdr10_plus->pts != pkt->pts)
+return 0;
+
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus->hdr10_plus->size);
+if (!data) {
+free_hdr10_plus(frame_hdr10_plus);
+return AVERROR(ENOMEM);
+}
+memcpy(data, frame_hdr10_plus->hdr10_plus->data, 
frame_hdr10_plus->hdr10_plus->size);
+free_hdr10_plus(frame_hdr10_plus);
+
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -383,6 +433,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_fifo(>hdr10_plus_fifo);
 return 0;
 }
 
@@ -834,6 +885,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 

Re: [FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-05-24 Thread Mohammad Izadi
Any more comments or looks good to go?
Thanks,
Mohammad


On Mon, Apr 26, 2021 at 6:54 PM Mohammad Izadi  wrote:

> HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
>
> This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> ---
>  libavcodec/avpacket.c  |  1 +
>  libavcodec/decode.c|  1 +
>  libavcodec/libvpxenc.c | 88 +-
>  libavcodec/packet.h|  8 
>  4 files changed, 96 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index b5bac5c5f2..7a3b0a73e3 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
>  case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
>  case AV_PKT_DATA_DOVI_CONF:  return "DOVI
> configuration record";
>  case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST
> 12-1:2014 timecode";
> +case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
>  }
>  return NULL;
>  }
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 0956a6ac6f..bf5fbcca97 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
>  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
>  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
>  { AV_PKT_DATA_S12M_TIMECODE,
> AV_FRAME_DATA_S12M_TIMECODE },
> +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
>  };
>
>  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >=
> sizeof(*pkt))
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 3f36943c12..2096c08437 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -63,6 +63,12 @@ struct FrameListData {
>  struct FrameListData *next;
>  };
>
> +typedef struct FrameHDR10PlusList {
> +int64_t pts;
> +AVBufferRef *hdr10_plus;
> +struct FrameHDR10PlusList *next;
> +} FrameHDR10PlusList;
> +
>  typedef struct VPxEncoderContext {
>  AVClass *class;
>  struct vpx_codec_ctx encoder;
> @@ -120,6 +126,8 @@ typedef struct VPxEncoderContext {
>  int tune_content;
>  int corpus_complexity;
>  int tpl_model;
> +int discard_hdr10_plus;
> +struct FrameHDR10PlusList *hdr10_plus_list;
>  /**
>   * If the driver does not support ROI then warn the first time we
>   * encounter a frame with ROI side data.
> @@ -315,6 +323,53 @@ static av_cold void free_frame_list(struct
> FrameListData *list)
>  }
>  }
>
> +
> +static void add_hdr10_plus(void *list, struct FrameHDR10PlusList *data)
> +{
> +struct FrameHDR10PlusList **p = list;
> +while (*p)
> +p = &(*p)->next;
> +*p = data;
> +data->next = NULL;
> +}
> +
> +static av_cold void free_hdr10_plus(struct FrameHDR10PlusList *p)
> +{
> +av_buffer_unref(>hdr10_plus);
> +av_free(p);
> +}
> +
> +static av_cold void free_hdr10_plus_list(struct FrameHDR10PlusList *list)
> +{
> +struct FrameHDR10PlusList *p = list;
> +while (p) {
> +list = list->next;
> +free_hdr10_plus(p);
> +p = list;
> +}
> +}
> +
> +static int copy_hdr10_plus_to_pkt(void *list, AVPacket *pkt)
> +{
> +struct FrameHDR10PlusList **p = list;
> +struct FrameHDR10PlusList *head = *p;
> +
> +if (head && pkt && head->hdr10_plus && head->pts == pkt->pts) {
> +uint8_t *data;
> +*p = (*p)->next;
> +data = av_packet_new_side_data(pkt,
> AV_PKT_DATA_DYNAMIC_HDR10_PLUS, head->hdr10_plus->size);
> +
> +if (!data) {
> +free_hdr10_plus(head);
> +return AVERROR(ENOMEM);
> +}
> +memcpy(data, head->hdr10_plus->data, head->hdr10_plus->size);
> +free_hdr10_plus(head);
> +
> +}
> +return 0;
> +}
> +
>  static av_cold int codecctl_int(AVCodecContext *avctx,
>  enum vp8e_enc_control_id id, int val)
>  {
> @@ -383,6 +438,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
>  av_freep(>twopass_stats.buf);
>  av_fr

[FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-04-26 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 88 +-
 libavcodec/packet.h|  8 
 4 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index b5bac5c5f2..7a3b0a73e3 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0956a6ac6f..bf5fbcca97 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 3f36943c12..2096c08437 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -63,6 +63,12 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10PlusList {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+struct FrameHDR10PlusList *next;
+} FrameHDR10PlusList;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -120,6 +126,8 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int discard_hdr10_plus;
+struct FrameHDR10PlusList *hdr10_plus_list;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -315,6 +323,53 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+
+static void add_hdr10_plus(void *list, struct FrameHDR10PlusList *data)
+{
+struct FrameHDR10PlusList **p = list;
+while (*p)
+p = &(*p)->next;
+*p = data;
+data->next = NULL;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10PlusList *p)
+{
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_list(struct FrameHDR10PlusList *list)
+{
+struct FrameHDR10PlusList *p = list;
+while (p) {
+list = list->next;
+free_hdr10_plus(p);
+p = list;
+}
+}
+
+static int copy_hdr10_plus_to_pkt(void *list, AVPacket *pkt)
+{
+struct FrameHDR10PlusList **p = list;
+struct FrameHDR10PlusList *head = *p;
+
+if (head && pkt && head->hdr10_plus && head->pts == pkt->pts) {
+uint8_t *data;
+*p = (*p)->next;
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
head->hdr10_plus->size);
+
+if (!data) {
+free_hdr10_plus(head);
+return AVERROR(ENOMEM);
+}
+memcpy(data, head->hdr10_plus->data, head->hdr10_plus->size);
+free_hdr10_plus(head);
+
+}
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -383,6 +438,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_list(ctx->hdr10_plus_list);
 return 0;
 }
 
@@ -828,6 +884,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 AVCPBProperties *cpb_props;
 int res;
 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
+ctx->discard_hdr10_plus = 1;
 #if CONFIG_LIBVPX_VP9_ENCODER
 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
 vpx_svc_extra_cfg_t svc_params;
@@ -850,11 +907,16 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 if (avctx->codec_id == AV_CODEC_ID_VP9) {
 if (set_pix_fmt(avctx, codec_caps, , , _fmt))
 return AVERROR(EINVAL);
+// Keep HDR10+ if it has bit depth higher than 8 and
+// it has PQ trc (SMPTE2084).
+if (enccfg.g_bit_depth > 8 && avctx->color_trc == 

Re: [FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-04-26 Thread Mohammad Izadi
On Fri, Apr 23, 2021 at 11:53 AM James Zern 
wrote:

> Hi,
>
> On Fri, Apr 23, 2021 at 8:58 AM Mohammad Izadi
>  wrote:
> >
> > HDR10+ metadata is stored in the bit stream for HEVC. The story is
> different for VP9 and cannot store the metadata in the bit stream. HDR10+
> should be passed to packet side data an stored in the container (mkv) for
> VP9.
> >
> > This CL is taking HDR10+ from AVFrame side data in libvpxenc and is
> passing it to the AVPacket side data.
> > ---
> >  libavcodec/avpacket.c  |  1 +
> >  libavcodec/decode.c|  1 +
> >  libavcodec/libvpxenc.c | 71 ++
> >  libavcodec/packet.h| 10 +-
> >  4 files changed, 82 insertions(+), 1 deletion(-)
> >
>
> Just some quick cosmetics, I didn't take a close look at the
> implementation.
>
> > [...]
> > +static int copy_hdr10_plus_to_pkt(void *list, AVPacket *pkt)
> > +{
> > +struct FrameHDR10PlusList **p = list;
> > +struct FrameHDR10PlusList *head = *p;
> > +
> > +if(head && pkt && head->hdr10_plus && head->pts == pkt->pts) {
>
> Add whitespace after 'if' and elsewhere before the '{'. You can use
> tools/patcheck as a guide to the formatting [1].
>
*Fixed.*

>
> > [...]
> >
> > @@ -1245,6 +1300,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >  AV_WB64(side_data, 1);
> >  memcpy(side_data + 8, cx_frame->buf_alpha,
> cx_frame->sz_alpha);
> >  }
> > +if(cx_frame->frame_number != -1) { // Not invisible frame
>
> VP9 won't emit frames like this, but this is a shared path with VP8. Can
> we get
> this metadata (unnecessarily) when doing a 8-bit encode?
>
*Great point! planned to discard it in matroska, but we can discard HDR10+
if it is PQ HDR (high bit depth and SPMTE2084). We shouldn't get it. Fixed
in the code.*

> > +VPxContext *ctx = avctx->priv_data;
> > +int err = copy_hdr10_plus_to_pkt(>hdr10_plus_list,
> pkt);
> > +if (err < 0)
> > +return err;
> > +}
> >  } else {
> >  return ret;
> >  }
> > @@ -1579,6 +1640,7 @@ static int vpx_encode(AVCodecContext *avctx,
> AVPacket *pkt,
> >  const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
> >  vpx_svc_layer_id_t layer_id;
> >  int layer_id_valid = 0;
> > +AVFrameSideData *hdr10_plus_metadata;
> >
> >  if (frame) {
> >  const AVFrameSideData *sd = av_frame_get_side_data(frame,
> AV_FRAME_DATA_REGIONS_OF_INTEREST);
> > @@ -1655,6 +1717,15 @@ static int vpx_encode(AVCodecContext *avctx,
> AVPacket *pkt,
> >  vp9_encode_set_roi(avctx, frame->width, frame->height,
> sd);
> >  }
> >  }
> > +
> > +// Add HDR10+ metadata to queue.
> > +hdr10_plus_metadata = av_frame_get_side_data(frame,
> AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> > +if(hdr10_plus_metadata){
> > +struct FrameHDR10PlusList *data =  av_malloc(sizeof(struct
> FrameHDR10PlusList));
>
> This allocation should be checked and prefer sizeof(*data).
>
*Fixed.*

>
> > +data->pts = frame->pts;
> > +data->hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf);
> > +add_hdr10_plus(>hdr10_plus_list, data);
> > +}
> >  }
> >
> >  // this is for encoding with preset temporal layering patterns
> defined in
> > diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> > index ca18ae631f..89e683b357 100644
> > --- a/libavcodec/packet.h
> > +++ b/libavcodec/packet.h
> > @@ -298,7 +298,15 @@ enum AVPacketSideDataType {
> >   * If its value becomes huge, some code using it
> >   * needs to be updated as it assumes it to be smaller than other
> limits.
> >   */
> > -AV_PKT_DATA_NB
> > +AV_PKT_DATA_NB,
>
> This should be the final entry in the enum, see the comment above.
>
*Fixed.*

>

>
> > +
> > +/**
> > + * HDR10+ dynamic metadata associated with a video frame. The
> metadata is in
> > + * the form of the AVDynamicHDRPlus struct and contains
> > + * information for color volume transform - application 4 of
> > + * SPMTE 2094-40:2016 standard.
> > + */
> > +AV_PKT_DATA_DYNAMIC_HDR10_PLUS
> >  };
> >
> >  #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS
> //DEPRECATED
>
> [1] https://ffmpeg.org/developer.html#Coding-Rules-1
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] Pass the HDR10+ metadata to the packet side data in VP9 encoder

2021-04-23 Thread Mohammad Izadi
HDR10+ metadata is stored in the bit stream for HEVC. The story is different 
for VP9 and cannot store the metadata in the bit stream. HDR10+ should be 
passed to packet side data an stored in the container (mkv) for VP9.

This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it 
to the AVPacket side data.
---
 libavcodec/avpacket.c  |  1 +
 libavcodec/decode.c|  1 +
 libavcodec/libvpxenc.c | 71 ++
 libavcodec/packet.h| 10 +-
 4 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index b5bac5c5f2..7a3b0a73e3 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -416,6 +416,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
 case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 case AV_PKT_DATA_S12M_TIMECODE:  return "SMPTE ST 12-1:2014 
timecode";
+case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 }
 return NULL;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0956a6ac6f..bf5fbcca97 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1736,6 +1736,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 { AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 };
 
 if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= 
sizeof(*pkt))
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 3f36943c12..373c6e8418 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -63,6 +63,12 @@ struct FrameListData {
 struct FrameListData *next;
 };
 
+typedef struct FrameHDR10PlusList {
+int64_t pts;
+AVBufferRef *hdr10_plus;
+struct FrameHDR10PlusList *next;
+} FrameHDR10PlusList;
+
 typedef struct VPxEncoderContext {
 AVClass *class;
 struct vpx_codec_ctx encoder;
@@ -120,6 +126,7 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+struct FrameHDR10PlusList *hdr10_plus_list;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -315,6 +322,53 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
+
+static void add_hdr10_plus(void *list, struct FrameHDR10PlusList *data)
+{
+struct FrameHDR10PlusList **p = list;
+while (*p)
+p = &(*p)->next;
+*p = data;
+data->next = NULL;
+}
+
+static av_cold void free_hdr10_plus(struct FrameHDR10PlusList *p)
+{
+av_buffer_unref(>hdr10_plus);
+av_free(p);
+}
+
+static av_cold void free_hdr10_plus_list(struct FrameHDR10PlusList *list)
+{
+struct FrameHDR10PlusList *p = list;
+while (p) {
+list = list->next;
+free_hdr10_plus(p);
+p = list;
+}
+}
+
+static int copy_hdr10_plus_to_pkt(void *list, AVPacket *pkt)
+{
+struct FrameHDR10PlusList **p = list;
+struct FrameHDR10PlusList *head = *p;
+
+if(head && pkt && head->hdr10_plus && head->pts == pkt->pts) {
+uint8_t *data;
+*p = (*p)->next;
+data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
head->hdr10_plus->size);
+
+if (!data) {
+free_hdr10_plus(head);
+return AVERROR(ENOMEM);
+}
+memcpy(data, head->hdr10_plus->data, head->hdr10_plus->size);
+free_hdr10_plus(head);
+
+}
+return 0;
+}
+
 static av_cold int codecctl_int(AVCodecContext *avctx,
 enum vp8e_enc_control_id id, int val)
 {
@@ -383,6 +437,7 @@ static av_cold int vpx_free(AVCodecContext *avctx)
 av_freep(>twopass_stats.buf);
 av_freep(>stats_out);
 free_frame_list(ctx->coded_frame_list);
+free_hdr10_plus_list(ctx->hdr10_plus_list);
 return 0;
 }
 
@@ -1245,6 +1300,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 AV_WB64(side_data, 1);
 memcpy(side_data + 8, cx_frame->buf_alpha, cx_frame->sz_alpha);
 }
+if(cx_frame->frame_number != -1) { // Not invisible frame
+VPxContext *ctx = avctx->priv_data;
+int err = copy_hdr10_plus_to_pkt(>hdr10_plus_list, pkt);
+if (err < 0)
+return err;
+}
 } else {
 return ret;
 }
@@ -1579,6 +1640,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
 vpx_svc_layer_id_t layer_id;
 int layer_id_valid = 0;
+AVFrameSideData *hdr10_plus_metadata;
 
 if (frame) 

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-12-01 Thread Mohammad Izadi
Ian, can you please take a look into it? And if it's fine to push it.

Thanks,
Mohammad


On Mon, Nov 23, 2020 at 1:29 PM Mohammad Izadi  wrote:

> From: Mohammad Izadi 
>
> HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to
> be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to
> side data packet to be used or passed through.
> ---
> The fate test file can be found here:
> https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
> The video file needs to be copied to fate-suite/mov/
> configure  |   1 +
>  fftools/ffprobe.c  | 106 +
>  libavcodec/Makefile|   3 +
>  libavcodec/avpacket.c  |   1 +
>  libavcodec/decode.c|   1 +
>  libavcodec/dynamic_hdr10_plus.c| 196 +
>  libavcodec/dynamic_hdr10_plus.h|  34 +
>  libavcodec/hevc_sei.c  |  62 ++--
>  libavcodec/hevc_sei.h  |   5 +
>  libavcodec/hevcdec.c   |  18 +++
>  libavcodec/packet.h|   8 +
>  libavcodec/version.h   |   2 +-
>  libavfilter/vf_showinfo.c  | 106 -
>  tests/fate/mov.mak |   3 +
>  tests/ref/fate/mov-hdr10-plus-metadata |  90 
>  15 files changed, 621 insertions(+), 15 deletions(-)
>  create mode 100644 libavcodec/dynamic_hdr10_plus.c
>  create mode 100644 libavcodec/dynamic_hdr10_plus.h
>  create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata
>
> diff --git a/configure b/configure
> index 51e43fbf66..a9f12a421e 100755
> --- a/configure
> +++ b/configure
> @@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
>  dirac_parse
>  dnn
>  dvprofile
> +dynamic_hdr10_plus
>  exif
>  faandct
>  faanidct
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 86bd23d36d..4cee4e8ec3 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -35,6 +35,7 @@
>  #include "libavutil/bprint.h"
>  #include "libavutil/display.h"
>  #include "libavutil/hash.h"
> +#include "libavutil/hdr_dynamic_metadata.h"
>  #include "libavutil/mastering_display_metadata.h"
>  #include "libavutil/dovi_meta.h"
>  #include "libavutil/opt.h"
> @@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w,
> AVDictionary *tags, int section_id
>  return ret;
>  }
>
> +static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus
> *metadata)
> +{
> +if (!metadata)
> +return;
> +print_int("application version", metadata->application_version);
> +print_int("num_windows", metadata->num_windows);
> +for (int n = 1; n < metadata->num_windows; n++) {
> +AVHDRPlusColorTransformParams *params = >params[n];
> +print_q("window_upper_left_corner_x",
> +params->window_upper_left_corner_x,'/');
> +print_q("window_upper_left_corner_y",
> +params->window_upper_left_corner_y,'/');
> +print_q("window_lower_right_corner_x",
> +params->window_lower_right_corner_x,'/');
> +print_q("window_lower_right_corner_y",
> +params->window_lower_right_corner_y,'/');
> +print_q("window_upper_left_corner_x",
> +params->window_upper_left_corner_x,'/');
> +print_q("window_upper_left_corner_y",
> +params->window_upper_left_corner_y,'/');
> +print_int("center_of_ellipse_x",
> +  params->center_of_ellipse_x ) ;
> +print_int("center_of_ellipse_y",
> +  params->center_of_ellipse_y );
> +print_int("rotation_angle",
> +  params->rotation_angle);
> +print_int("semimajor_axis_internal_ellipse",
> +  params->semimajor_axis_internal_ellipse);
> +print_int("semimajor_axis_external_ellipse",
> +  params->semimajor_axis_external_ellipse);
> +print_int("semiminor_axis_external_ellipse",
> +  params->semiminor_axis_external_ellipse);
> +print_int("overlap_process_option",
> +  params->overlap_process_option);
> +}
> +print_q("targeted_system_display_maximum_luminance",
> +metadata->targeted_system_display_maximum_luminance,'/');
> +if (metadata->targ

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-23 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
The video file needs to be copied to fate-suite/mov/
configure  |   1 +
 fftools/ffprobe.c  | 106 +
 libavcodec/Makefile|   3 +
 libavcodec/avpacket.c  |   1 +
 libavcodec/decode.c|   1 +
 libavcodec/dynamic_hdr10_plus.c| 196 +
 libavcodec/dynamic_hdr10_plus.h|  34 +
 libavcodec/hevc_sei.c  |  62 ++--
 libavcodec/hevc_sei.h  |   5 +
 libavcodec/hevcdec.c   |  18 +++
 libavcodec/packet.h|   8 +
 libavcodec/version.h   |   2 +-
 libavfilter/vf_showinfo.c  | 106 -
 tests/fate/mov.mak |   3 +
 tests/ref/fate/mov-hdr10-plus-metadata |  90 
 15 files changed, 621 insertions(+), 15 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 create mode 100644 libavcodec/dynamic_hdr10_plus.h
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+  
metadata->num_cols_targeted_system_display_actual_peak_luminance);
+for (int i = 0; i < 
metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
+for (int j = 0; j < 
metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
+

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-23 Thread Mohammad Izadi
Thanks,
Mohammad


On Fri, Nov 20, 2020 at 5:44 AM Anton Khirnov  wrote:

> Quoting Mohammad Izadi (2020-11-20 04:57:11)
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> > ---
> > The fate test file can be found here:
> https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
> > The video file needs to be copied to fate-suite/mov/
>
> >  configure |   1 +
> >  fftools/ffprobe.c | 106 +
> >  libavcodec/Makefile   |   3 +
> >  libavcodec/avpacket.c |   1 +
> >  libavcodec/decode.c   |   1 +
> >  libavcodec/dynamic_hdr10_plus.c   | 223 ++
> >  .../dynamic_hdr10_plus.h  |  22 +-
> >  libavcodec/hevc_sei.c |  62 -
> >  libavcodec/hevc_sei.h |   5 +
> >  libavcodec/hevcdec.c  |  18 ++
> >  libavcodec/packet.h   |   8 +
> >  libavcodec/version.h  |   2 +-
> >  libavfilter/vf_showinfo.c | 106 -
> >  libavutil/Makefile|   2 -
> >  libavutil/hdr_dynamic_metadata.c  |  47 
> >  tests/fate/mov.mak|   3 +
> >  tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
> >  17 files changed, 629 insertions(+), 71 deletions(-)
> >  create mode 100644 libavcodec/dynamic_hdr10_plus.c
> >  rename libavutil/hdr_dynamic_metadata.h =>
> libavcodec/dynamic_hdr10_plus.h (95%)
>
> You cannot move a public header like that, it breaks API.
>
Right reverted the change in the following patch.

> Also, the patch does way too many things at once, it should be split.

Some changes are asked to be added by reviewers just for being able to test
it. This CL has been hanging for a long time. I think Vittorio and Ian can
help on this to proceed with this CL.

>
> --
> Anton Khirnov
> ___
> 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] Support HDR10+ metadata for HEVC.

2020-11-19 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
The video file needs to be copied to fate-suite/mov/
   
 configure |   1 +
 fftools/ffprobe.c | 106 +
 libavcodec/Makefile   |   3 +
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/dynamic_hdr10_plus.c   | 223 ++
 .../dynamic_hdr10_plus.h  |  22 +-
 libavcodec/hevc_sei.c |  62 -
 libavcodec/hevc_sei.h |   5 +
 libavcodec/hevcdec.c  |  18 ++
 libavcodec/packet.h   |   8 +
 libavcodec/version.h  |   2 +-
 libavfilter/vf_showinfo.c | 106 -
 libavutil/Makefile|   2 -
 libavutil/hdr_dynamic_metadata.c  |  47 
 tests/fate/mov.mak|   3 +
 tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
 17 files changed, 629 insertions(+), 71 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 rename libavutil/hdr_dynamic_metadata.h => libavcodec/dynamic_hdr10_plus.h 
(95%)
 delete mode 100644 libavutil/hdr_dynamic_metadata.c
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..5187e03603 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -30,6 +30,7 @@
 
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/dynamic_hdr10_plus.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+ 

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-17 Thread Mohammad Izadi
On Sun, Nov 15, 2020 at 12:19 AM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> Mohammad Izadi:
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> >
> > The fate test file can be found here:
> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
> >
> > The video file needs to be copied to fate-suite/mov/
> > ---
>
> 1. The comments regarding fate don't belong in the commit message, they
> belong here below the --- (the --annotate option is useful for this when
> using git send-email).
>
Done.

> 2. This file is huge. Why don't you use a file with a smaller
> bitrate/resolution?
>
Took another video with ~1mb. It seems 1080p is the lowest res we can
capture HDR10+ by Samsung S10. Removed audio as well. Added the link to the
patch.

>
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
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] Support HDR10+ metadata for HEVC.

2020-11-17 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1vcT0ohzpoyVFcxQN32jKIhUrBaBwZweT/view?usp=sharing
 
The video file needs to be copied to fate-suite/mov/
   
configure |   1 +
 fftools/ffprobe.c | 106 +
 libavcodec/Makefile   |   3 +
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/dynamic_hdr10_plus.c   | 223 ++
 .../dynamic_hdr10_plus.h  |  22 +-
 libavcodec/hevc_sei.c |  62 -
 libavcodec/hevc_sei.h |   5 +
 libavcodec/hevcdec.c  |  18 ++
 libavcodec/packet.h   |   8 +
 libavcodec/version.h  |   2 +-
 libavfilter/vf_showinfo.c | 106 -
 libavutil/Makefile|   2 -
 libavutil/hdr_dynamic_metadata.c  |  47 
 tests/fate/mov.mak|   3 +
 tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
 17 files changed, 629 insertions(+), 71 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 rename libavutil/hdr_dynamic_metadata.h => libavcodec/dynamic_hdr10_plus.h 
(95%)
 delete mode 100644 libavutil/hdr_dynamic_metadata.c
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-16 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
The video file needs to be copied to fate-suite/mov/

configure |   1 +
 fftools/ffprobe.c | 106 +
 libavcodec/Makefile   |   3 +
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/dynamic_hdr10_plus.c   | 223 ++
 .../dynamic_hdr10_plus.h  |  22 +-
 libavcodec/hevc_sei.c |  62 -
 libavcodec/hevc_sei.h |   5 +
 libavcodec/hevcdec.c  |  18 ++
 libavcodec/packet.h   |   8 +
 libavcodec/version.h  |   2 +-
 libavfilter/vf_showinfo.c | 106 -
 libavutil/Makefile|   2 -
 libavutil/hdr_dynamic_metadata.c  |  47 
 tests/fate/mov.mak|   3 +
 tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
 17 files changed, 629 insertions(+), 71 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 rename libavutil/hdr_dynamic_metadata.h => libavcodec/dynamic_hdr10_plus.h 
(95%)
 delete mode 100644 libavutil/hdr_dynamic_metadata.c
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+  
metadata->num_cols_targe

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-15 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
The fate test file can be found here: 
https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing

The video file needs to be copied to fate-suite/mov/

 configure |   1 +
 fftools/ffprobe.c | 106 +
 libavcodec/Makefile   |   3 +
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/dynamic_hdr10_plus.c   | 223 ++
 .../dynamic_hdr10_plus.h  |  22 +-
 libavcodec/hevc_sei.c |  62 -
 libavcodec/hevc_sei.h |   5 +
 libavcodec/hevcdec.c  |  18 ++
 libavcodec/packet.h   |   8 +
 libavcodec/version.h  |   2 +-
 libavfilter/vf_showinfo.c | 106 -
 libavutil/Makefile|   2 -
 libavutil/hdr_dynamic_metadata.c  |  47 
 tests/fate/mov.mak|   3 +
 tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
 17 files changed, 629 insertions(+), 71 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 rename libavutil/hdr_dynamic_metadata.h => libavcodec/dynamic_hdr10_plus.h 
(95%)
 delete mode 100644 libavutil/hdr_dynamic_metadata.c
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+  
metadata->num_cols_targe

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-14 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.

The fate test file can be found here: 
https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing

The video file needs to be copied to fate-suite/mov/
---
 configure |   1 +
 fftools/ffprobe.c | 106 +
 libavcodec/Makefile   |   3 +
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/dynamic_hdr10_plus.c   | 223 ++
 .../dynamic_hdr10_plus.h  |  22 +-
 libavcodec/hevc_sei.c |  62 -
 libavcodec/hevc_sei.h |   5 +
 libavcodec/hevcdec.c  |  18 ++
 libavcodec/packet.h   |   8 +
 libavcodec/version.h  |   2 +-
 libavfilter/vf_showinfo.c | 106 -
 libavutil/Makefile|   2 -
 libavutil/hdr_dynamic_metadata.c  |  47 
 tests/fate/mov.mak|   3 +
 tests/ref/fate/mov-hdr10-plus-metadata|  90 +++
 17 files changed, 629 insertions(+), 71 deletions(-)
 create mode 100644 libavcodec/dynamic_hdr10_plus.c
 rename libavutil/hdr_dynamic_metadata.h => libavcodec/dynamic_hdr10_plus.h 
(95%)
 delete mode 100644 libavutil/hdr_dynamic_metadata.c
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/configure b/configure
index 51e43fbf66..a9f12a421e 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ CONFIG_EXTRA="
 dirac_parse
 dnn
 dvprofile
+dynamic_hdr10_plus
 exif
 faandct
 faanidct
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..4cee4e8ec3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1860,6 +1861,105 @@ static inline int show_tags(WriterContext *w, 
AVDictionary *tags, int section_id
 return ret;
 }
 
+static void print_dynamic_hdr10_plus(WriterContext *w, AVDynamicHDRPlus 
*metadata)
+{
+if (!metadata)
+return;
+print_int("application version", metadata->application_version);
+print_int("num_windows", metadata->num_windows);
+for (int n = 1; n < metadata->num_windows; n++) {
+AVHDRPlusColorTransformParams *params = >params[n];
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_q("window_lower_right_corner_x",
+params->window_lower_right_corner_x,'/');
+print_q("window_lower_right_corner_y",
+params->window_lower_right_corner_y,'/');
+print_q("window_upper_left_corner_x",
+params->window_upper_left_corner_x,'/');
+print_q("window_upper_left_corner_y",
+params->window_upper_left_corner_y,'/');
+print_int("center_of_ellipse_x",
+  params->center_of_ellipse_x ) ;
+print_int("center_of_ellipse_y",
+  params->center_of_ellipse_y );
+print_int("rotation_angle",
+  params->rotation_angle);
+print_int("semimajor_axis_internal_ellipse",
+  params->semimajor_axis_internal_ellipse);
+print_int("semimajor_axis_external_ellipse",
+  params->semimajor_axis_external_ellipse);
+print_int("semiminor_axis_external_ellipse",
+  params->semiminor_axis_external_ellipse);
+print_int("overlap_process_option",
+  params->overlap_process_option);
+}
+print_q("targeted_system_display_maximum_luminance",
+metadata->targeted_system_display_maximum_luminance,'/');
+if (metadata->targeted_system_display_actual_peak_luminance_flag) {
+print_int("num_rows_targeted_system_display_actual_peak_luminance",
+  
metadata->num_rows_targeted_system_display_actual_peak_luminance);
+print_int("num_cols_targeted_system_display_actual_peak_luminance",
+  
metadata->num_cols_targe

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-14 Thread Mohammad Izadi
Thank you Ian for your great detailed comments.

Thanks,
Mohammad


On Wed, Nov 11, 2020 at 5:10 PM Jan EkstrΓΆm  wrote:

> On 14.10.2020 2:53, Mohammad Izadi wrote:
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> >
> > The fate test file can be found here:
> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
> >
> > The video file needs to be copied to fate-suite/mov/
> > ---
>
> Long overdue initial attempt at a review follows...
>
> >  fftools/ffprobe.c  |  16 +++
> >  libavcodec/avpacket.c  |   1 +
> >  libavcodec/decode.c|   1 +
> >  libavcodec/hevc_sei.c  |  39 --
> >  libavcodec/hevc_sei.h  |   5 +
> >  libavcodec/hevcdec.c   |  16 +++
> >  libavcodec/internal.h  |   9 ++
> >  libavcodec/packet.h|   8 ++
> >  libavcodec/utils.c | 180 +
> >  libavcodec/version.h   |   2 +-
> >  libavfilter/vf_showinfo.c  |  28 
> >  tests/fate/mov.mak |   3 +
> >  tests/ref/fate/mov-hdr10-plus-metadata |  55 
> >  13 files changed, 350 insertions(+), 13 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata
> >
> > diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> > index d4e494f11f..0b80edf842 100644
> > --- a/fftools/ffprobe.c
> > +++ b/fftools/ffprobe.c
> > @@ -35,6 +35,7 @@
> >  #include "libavutil/bprint.h"
> >  #include "libavutil/display.h"
> >  #include "libavutil/hash.h"
> > +#include "libavutil/hdr_dynamic_metadata.h"
> >  #include "libavutil/mastering_display_metadata.h"
> >  #include "libavutil/dovi_meta.h"
> >  #include "libavutil/opt.h"
> > @@ -1925,6 +1926,13 @@ static void print_pkt_side_data(WriterContext *w,
> >  print_q("min_luminance", metadata->min_luminance, '/');
> >  print_q("max_luminance", metadata->max_luminance, '/');
> >  }
> > +} else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR_PLUS) {
> > +AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
> > +// Partially print HDR10+ metadata.
> > +print_int("num_windows", metadata->num_windows);
> > +print_q("targeted_system_display_maximum_luminance",
> metadata->targeted_system_display_maximum_luminance, '/');
> > +
> print_int("targeted_system_display_actual_peak_luminance_flag",
> metadata->targeted_system_display_actual_peak_luminance_flag);
> > +print_int("mastering_display_actual_peak_luminance_flag",
> metadata->mastering_display_actual_peak_luminance_flag);
> >  } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
> >  AVContentLightMetadata *metadata = (AVContentLightMetadata
> *)sd->data;
> >  print_int("max_content", metadata->MaxCLL);
> > @@ -2250,6 +2258,14 @@ static void show_frame(WriterContext *w, AVFrame
> *frame, AVStream *stream,
> >  print_q("min_luminance", metadata->min_luminance,
> '/');
> >  print_q("max_luminance", metadata->max_luminance,
> '/');
> >  }
> > +} else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
> > +AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus
> *)sd->data;
> > +// Partially print HDR10+ metadata.
> > + print_int("num_windows", metadata->num_windows);
> > + print_q("targeted_system_display_maximum_luminance",
> metadata->targeted_system_display_maximum_luminance, '/');
> > +
>  print_int("targeted_system_display_actual_peak_luminance_flag",
> metadata->targeted_system_display_actual_peak_luminance_flag);
> > + print_int("mastering_display_actual_peak_luminance_flag",
> metadata->mastering_display_actual_peak_luminance_flag);
> > +
>
> Some really minor stuff:
> - Empty line at the end
> - Tabs vs space, seemingly some tabs ended up here. Copy and paste can
> make that happen. I know this has been done in this duplicated fashion so
> far

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-11 Thread Mohammad Izadi
Is anybody there? Any update? Can we push it to the head?

Thanks,
Mohammad


On Fri, Nov 6, 2020 at 9:42 PM Mohammad Izadi  wrote:

> Any update? Can we push it to the head?
> Thanks,
> Mohammad
>
>
> On Mon, Oct 26, 2020 at 11:53 AM Mohammad Izadi  wrote:
>
>> Thank you, Jan! I hope you feel better soon.
>>
>>
>>
>> On Sun, Oct 25, 2020 at 5:49 PM Jan EkstrΓΆm  wrote:
>>
>>> On Wed, Oct 14, 2020 at 2:54 AM Mohammad Izadi
>>>  wrote:
>>> >
>>> > From: Mohammad Izadi 
>>> >
>>> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
>>> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
>>> to side data packet to be used or passed through.
>>> >
>>> > The fate test file can be found here:
>>> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
>>> >
>>> > The video file needs to be copied to fate-suite/mov/
>>> > ---
>>>
>>> Thanks for posting the latest version of this patch, unfortunately it
>>> also coincided with me first trying to get the colorspace ffmpeg.c
>>> patch forwards, and then getting a flu/cold which is still ongoing.
>>>
>>> Applied it after some tweaking as
>>> https://github.com/jeeb/ffmpeg/commits/hdr10plus_v2 and it does
>>> compile.
>>>
>>> Will attempt to review it as I get the time and feel better.
>>>
>>> Jan
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-11-06 Thread Mohammad Izadi
Any update? Can we push it to the head?
Thanks,
Mohammad


On Mon, Oct 26, 2020 at 11:53 AM Mohammad Izadi  wrote:

> Thank you, Jan! I hope you feel better soon.
>
>
>
> On Sun, Oct 25, 2020 at 5:49 PM Jan EkstrΓΆm  wrote:
>
>> On Wed, Oct 14, 2020 at 2:54 AM Mohammad Izadi
>>  wrote:
>> >
>> > From: Mohammad Izadi 
>> >
>> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
>> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
>> to side data packet to be used or passed through.
>> >
>> > The fate test file can be found here:
>> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
>> >
>> > The video file needs to be copied to fate-suite/mov/
>> > ---
>>
>> Thanks for posting the latest version of this patch, unfortunately it
>> also coincided with me first trying to get the colorspace ffmpeg.c
>> patch forwards, and then getting a flu/cold which is still ongoing.
>>
>> Applied it after some tweaking as
>> https://github.com/jeeb/ffmpeg/commits/hdr10plus_v2 and it does
>> compile.
>>
>> Will attempt to review it as I get the time and feel better.
>>
>> Jan
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-10-26 Thread Mohammad Izadi
Thank you, Jan! I hope you feel better soon.



On Sun, Oct 25, 2020 at 5:49 PM Jan EkstrΓΆm  wrote:

> On Wed, Oct 14, 2020 at 2:54 AM Mohammad Izadi
>  wrote:
> >
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> >
> > The fate test file can be found here:
> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
> >
> > The video file needs to be copied to fate-suite/mov/
> > ---
>
> Thanks for posting the latest version of this patch, unfortunately it
> also coincided with me first trying to get the colorspace ffmpeg.c
> patch forwards, and then getting a flu/cold which is still ongoing.
>
> Applied it after some tweaking as
> https://github.com/jeeb/ffmpeg/commits/hdr10plus_v2 and it does
> compile.
>
> Will attempt to review it as I get the time and feel better.
>
> Jan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-10-22 Thread Mohammad Izadi
Any comments?

Thanks,
Mohammad


On Tue, Oct 13, 2020 at 4:53 PM Mohammad Izadi  wrote:

> From: Mohammad Izadi 
>
> HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to
> be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to
> side data packet to be used or passed through.
>
> The fate test file can be found here:
> https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing
>
> The video file needs to be copied to fate-suite/mov/
> ---
>  fftools/ffprobe.c  |  16 +++
>  libavcodec/avpacket.c  |   1 +
>  libavcodec/decode.c|   1 +
>  libavcodec/hevc_sei.c  |  39 --
>  libavcodec/hevc_sei.h  |   5 +
>  libavcodec/hevcdec.c   |  16 +++
>  libavcodec/internal.h  |   9 ++
>  libavcodec/packet.h|   8 ++
>  libavcodec/utils.c | 180 +
>  libavcodec/version.h   |   2 +-
>  libavfilter/vf_showinfo.c  |  28 
>  tests/fate/mov.mak |   3 +
>  tests/ref/fate/mov-hdr10-plus-metadata |  55 
>  13 files changed, 350 insertions(+), 13 deletions(-)
>  create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index d4e494f11f..0b80edf842 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -35,6 +35,7 @@
>  #include "libavutil/bprint.h"
>  #include "libavutil/display.h"
>  #include "libavutil/hash.h"
> +#include "libavutil/hdr_dynamic_metadata.h"
>  #include "libavutil/mastering_display_metadata.h"
>  #include "libavutil/dovi_meta.h"
>  #include "libavutil/opt.h"
> @@ -1925,6 +1926,13 @@ static void print_pkt_side_data(WriterContext *w,
>  print_q("min_luminance", metadata->min_luminance, '/');
>  print_q("max_luminance", metadata->max_luminance, '/');
>  }
> +} else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR_PLUS) {
> +AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
> +// Partially print HDR10+ metadata.
> +print_int("num_windows", metadata->num_windows);
> +print_q("targeted_system_display_maximum_luminance",
> metadata->targeted_system_display_maximum_luminance, '/');
> +
> print_int("targeted_system_display_actual_peak_luminance_flag",
> metadata->targeted_system_display_actual_peak_luminance_flag);
> +print_int("mastering_display_actual_peak_luminance_flag",
> metadata->mastering_display_actual_peak_luminance_flag);
>  } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
>  AVContentLightMetadata *metadata = (AVContentLightMetadata
> *)sd->data;
>  print_int("max_content", metadata->MaxCLL);
> @@ -2250,6 +2258,14 @@ static void show_frame(WriterContext *w, AVFrame
> *frame, AVStream *stream,
>  print_q("min_luminance", metadata->min_luminance,
> '/');
>  print_q("max_luminance", metadata->max_luminance,
> '/');
>  }
> +} else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
> +AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
> +// Partially print HDR10+ metadata.
> +   print_int("num_windows", metadata->num_windows);
> +   print_q("targeted_system_display_maximum_luminance",
> metadata->targeted_system_display_maximum_luminance, '/');
> +
>  print_int("targeted_system_display_actual_peak_luminance_flag",
> metadata->targeted_system_display_actual_peak_luminance_flag);
> +   print_int("mastering_display_actual_peak_luminance_flag",
> metadata->mastering_display_actual_peak_luminance_flag);
> +
>  } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
>  AVContentLightMetadata *metadata =
> (AVContentLightMetadata *)sd->data;
>  print_int("max_content", metadata->MaxCLL);
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index dce26cb31a..8307032335 <(830)%20703-2335> 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
>  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light
> level metadata";
>  case 

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-10-13 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.

The fate test file can be found here: 
https://drive.google.com/file/d/1Hadzc24-RsgnRqS-B0bxLmzDeTwEOhtE/view?usp=sharing

The video file needs to be copied to fate-suite/mov/
---
 fftools/ffprobe.c  |  16 +++
 libavcodec/avpacket.c  |   1 +
 libavcodec/decode.c|   1 +
 libavcodec/hevc_sei.c  |  39 --
 libavcodec/hevc_sei.h  |   5 +
 libavcodec/hevcdec.c   |  16 +++
 libavcodec/internal.h  |   9 ++
 libavcodec/packet.h|   8 ++
 libavcodec/utils.c | 180 +
 libavcodec/version.h   |   2 +-
 libavfilter/vf_showinfo.c  |  28 
 tests/fate/mov.mak |   3 +
 tests/ref/fate/mov-hdr10-plus-metadata |  55 
 13 files changed, 350 insertions(+), 13 deletions(-)
 create mode 100644 tests/ref/fate/mov-hdr10-plus-metadata

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index d4e494f11f..0b80edf842 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -35,6 +35,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
@@ -1925,6 +1926,13 @@ static void print_pkt_side_data(WriterContext *w,
 print_q("min_luminance", metadata->min_luminance, '/');
 print_q("max_luminance", metadata->max_luminance, '/');
 }
+} else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR_PLUS) {
+AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
+// Partially print HDR10+ metadata.
+print_int("num_windows", metadata->num_windows);
+print_q("targeted_system_display_maximum_luminance", 
metadata->targeted_system_display_maximum_luminance, '/');
+print_int("targeted_system_display_actual_peak_luminance_flag", 
metadata->targeted_system_display_actual_peak_luminance_flag);
+print_int("mastering_display_actual_peak_luminance_flag", 
metadata->mastering_display_actual_peak_luminance_flag);
 } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
 AVContentLightMetadata *metadata = (AVContentLightMetadata 
*)sd->data;
 print_int("max_content", metadata->MaxCLL);
@@ -2250,6 +2258,14 @@ static void show_frame(WriterContext *w, AVFrame *frame, 
AVStream *stream,
 print_q("min_luminance", metadata->min_luminance, '/');
 print_q("max_luminance", metadata->max_luminance, '/');
 }
+} else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
+AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
+// Partially print HDR10+ metadata.
+   print_int("num_windows", metadata->num_windows);
+   print_q("targeted_system_display_maximum_luminance", 
metadata->targeted_system_display_maximum_luminance, '/');
+   print_int("targeted_system_display_actual_peak_luminance_flag", 
metadata->targeted_system_display_actual_peak_luminance_flag);
+   print_int("mastering_display_actual_peak_luminance_flag", 
metadata->mastering_display_actual_peak_luminance_flag);
+
 } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
 AVContentLightMetadata *metadata = (AVContentLightMetadata 
*)sd->data;
 print_int("max_content", metadata->MaxCLL);
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dce26cb31a..8307032335 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light level 
metadata";
 case AV_PKT_DATA_SPHERICAL:  return "Spherical Mapping";
 case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
+case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption 
initialization data";
 case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption info";
 case AV_PKT_DATA_AFD:  

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-09-08 Thread Mohammad Izadi
I will add the test by the end of this week.
Thanks,
Mohammad


On Mon, Sep 7, 2020 at 2:56 AM Jan EkstrΓΆm  wrote:

> On Sat, Jul 25, 2020 at 12:09 AM Mohammad Izadi
>  wrote:
> >
> > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> > andreas.rheinha...@gmail.com> wrote:
> >
> > > Mohammad Izadi:
> > > > From: Mohammad Izadi 
> > > >
> > > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that
> needs
> > > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
> transferred
> > > to side data packet to be used or passed through.
> > > > ---
> > > >  libavcodec/avpacket.c |   1 +
> > > >  libavcodec/decode.c   |   1 +
> > > >  libavcodec/hevc_sei.c |  39 ++---
> > > >  libavcodec/hevc_sei.h |   5 ++
> > > >  libavcodec/hevcdec.c  |  16 
> > > >  libavcodec/internal.h |   9 +++
> > > >  libavcodec/packet.h   |   8 ++
> > > >  libavcodec/utils.c| 180
> ++
> > > >  libavcodec/version.h  |   2 +-
> > > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > > >
> > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > > index dce26cb31a..8307032335 <(830)%20703-2335> <(830)%20703-2335>
> 100644
> > > > --- a/libavcodec/avpacket.c
> > > > +++ b/libavcodec/avpacket.c
> > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > > AVPacketSideDataType type)
> > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content
> light
> > > level metadata";
> > > >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> > > Mapping";
> > > >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> > > Captions";
> > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> Dynamic
> > > Metadata (SMPTE 2094-40)";
> > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> > > initialization data";
> > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> > > info";
> > > >  case AV_PKT_DATA_AFD:return "Active
> Format
> > > Description data";
> > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > > index de9c079f9d..cd3286f7fb 100644
> > > > --- a/libavcodec/decode.c
> > > > +++ b/libavcodec/decode.c
> > > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext
> *avctx,
> > > AVFrame *frame)
> > > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > > >  { AV_PKT_DATA_A53_CC,
>  AV_FRAME_DATA_A53_CC
> > > },
> > > > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
> > >  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> > > >  { AV_PKT_DATA_ICC_PROFILE,
> > > AV_FRAME_DATA_ICC_PROFILE },
> > > >  };
> > > >
> > > > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > > > index a4ec65dc1a..a490e752dd 100644
> > > > --- a/libavcodec/hevc_sei.c
> > > > +++ b/libavcodec/hevc_sei.c
> > > > @@ -25,6 +25,7 @@
> > > >  #include "golomb.h"
> > > >  #include "hevc_ps.h"
> > > >  #include "hevc_sei.h"
> > > > +#include "internal.h"
> > > >
> > > >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash
> *s,
> > > GetBitContext *gb)
> > > >  {
> > > > @@ -242,8 +243,8 @@ static int
> > > decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> > > >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> > > GetBitContext *gb,
> > > >   int size)
> > > >  {
> > > > -uint32_t country_code;
> > > > -uint32_t user_identifier;
> > > > +uint8_t country_code;
> > > > +uint16_t provider_code;
> > > >
> > > >  if (size < 7)
> > > >  return AVERROR(EINVAL);
> > > > @@ -2

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-08-12 Thread Mohammad Izadi
Vittorio,

What is the next step for me?

Thanks,
Mohammad


On Fri, Aug 7, 2020 at 9:51 AM Mohammad Izadi  wrote:

> Any more comments?  Are you OK to merge?
> Thanks,
> Mohammad
>
>
> On Thu, Jul 30, 2020 at 9:06 AM Vittorio Giovara <
> vittorio.giov...@gmail.com> wrote:
>
>> On Mon, Jul 27, 2020 at 11:44 PM Mohammad Izadi <
>> izadi-at-google@ffmpeg.org> wrote:
>>
>> > It seems FATE is for the regression test. Here is a sample that you can
>> use
>> > and check:
>> >
>> >  https://www.dropbox.com/s/3ewr2t2lvv2cy8d/20200727_143643.mp4?dl=0
>> >
>> >
>> Thanks I will check it out.
>> Fate is indeed for regression testing, but also for continuous
>> integration.
>> If a portion of code has a fate sample available, it is automatically
>> tested every time, and if there is a breaking change, people can act upon
>> it and prevent it from happening.
>> Vittorio
>>
>>
>> > Thanks,
>> > Mohammad
>> >
>> >
>> > On Mon, Jul 27, 2020 at 7:53 AM Vittorio Giovara <
>> > vittorio.giov...@gmail.com>
>> > wrote:
>> >
>> > > On Fri, Jul 24, 2020 at 11:09 PM Mohammad Izadi <
>> > > izadi-at-google@ffmpeg.org> wrote:
>> > >
>> > > > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
>> > > > andreas.rheinha...@gmail.com> wrote:
>> > > >
>> > > > > Mohammad Izadi:
>> > > > > > From: Mohammad Izadi 
>> > > > > >
>> > > > > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that
>> > > needs
>> > > > > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
>> > > > transferred
>> > > > > to side data packet to be used or passed through.
>> > > > > > ---
>> > > > > >  libavcodec/avpacket.c |   1 +
>> > > > > >  libavcodec/decode.c   |   1 +
>> > > > > >  libavcodec/hevc_sei.c |  39 ++---
>> > > > > >  libavcodec/hevc_sei.h |   5 ++
>> > > > > >  libavcodec/hevcdec.c  |  16 
>> > > > > >  libavcodec/internal.h |   9 +++
>> > > > > >  libavcodec/packet.h   |   8 ++
>> > > > > >  libavcodec/utils.c| 180
>> > > ++
>> > > > > >  libavcodec/version.h  |   2 +-
>> > > > > >  9 files changed, 248 insertions(+), 13 deletions(-)
>> > > > > >
>> > > > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
>> > > > > > index dce26cb31a..8307032335 <(830)%20703-2335>
>> <(830)%20703-2335> <(830)%20703-2335>
>> > > 100644
>> > > > > > --- a/libavcodec/avpacket.c
>> > > > > > +++ b/libavcodec/avpacket.c
>> > > > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
>> > > > > AVPacketSideDataType type)
>> > > > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return
>> "Content
>> > > light
>> > > > > level metadata";
>> > > > > >  case AV_PKT_DATA_SPHERICAL:  return
>> "Spherical
>> > > > > Mapping";
>> > > > > >  case AV_PKT_DATA_A53_CC: return "A53
>> > Closed
>> > > > > Captions";
>> > > > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
>> > > > Dynamic
>> > > > > Metadata (SMPTE 2094-40)";
>> > > > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return
>> > "Encryption
>> > > > > initialization data";
>> > > > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return
>> > "Encryption
>> > > > > info";
>> > > > > >  case AV_PKT_DATA_AFD:return "Active
>> > > Format
>> > > > > Description data";
>> > > > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
>> > > > > > index de9c079f9d..cd3286f7fb 100644
>> > > > > > --- a/libavcodec/decode.c
>> > > > > > +++ b/libavcodec/decode.c
>> > &g

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-08-07 Thread Mohammad Izadi
Any more comments?  Are you OK to merge?
Thanks,
Mohammad


On Thu, Jul 30, 2020 at 9:06 AM Vittorio Giovara 
wrote:

> On Mon, Jul 27, 2020 at 11:44 PM Mohammad Izadi <
> izadi-at-google@ffmpeg.org> wrote:
>
> > It seems FATE is for the regression test. Here is a sample that you can
> use
> > and check:
> >
> >  https://www.dropbox.com/s/3ewr2t2lvv2cy8d/20200727_143643.mp4?dl=0
> >
> >
> Thanks I will check it out.
> Fate is indeed for regression testing, but also for continuous integration.
> If a portion of code has a fate sample available, it is automatically
> tested every time, and if there is a breaking change, people can act upon
> it and prevent it from happening.
> Vittorio
>
>
> > Thanks,
> > Mohammad
> >
> >
> > On Mon, Jul 27, 2020 at 7:53 AM Vittorio Giovara <
> > vittorio.giov...@gmail.com>
> > wrote:
> >
> > > On Fri, Jul 24, 2020 at 11:09 PM Mohammad Izadi <
> > > izadi-at-google....@ffmpeg.org> wrote:
> > >
> > > > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> > > > andreas.rheinha...@gmail.com> wrote:
> > > >
> > > > > Mohammad Izadi:
> > > > > > From: Mohammad Izadi 
> > > > > >
> > > > > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that
> > > needs
> > > > > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
> > > > transferred
> > > > > to side data packet to be used or passed through.
> > > > > > ---
> > > > > >  libavcodec/avpacket.c |   1 +
> > > > > >  libavcodec/decode.c   |   1 +
> > > > > >  libavcodec/hevc_sei.c |  39 ++---
> > > > > >  libavcodec/hevc_sei.h |   5 ++
> > > > > >  libavcodec/hevcdec.c  |  16 
> > > > > >  libavcodec/internal.h |   9 +++
> > > > > >  libavcodec/packet.h   |   8 ++
> > > > > >  libavcodec/utils.c| 180
> > > ++
> > > > > >  libavcodec/version.h  |   2 +-
> > > > > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > > > > >
> > > > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > > > > index dce26cb31a..8307032335 <(830)%20703-2335>
> <(830)%20703-2335> <(830)%20703-2335>
> > > 100644
> > > > > > --- a/libavcodec/avpacket.c
> > > > > > +++ b/libavcodec/avpacket.c
> > > > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > > > > AVPacketSideDataType type)
> > > > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content
> > > light
> > > > > level metadata";
> > > > > >  case AV_PKT_DATA_SPHERICAL:  return
> "Spherical
> > > > > Mapping";
> > > > > >  case AV_PKT_DATA_A53_CC: return "A53
> > Closed
> > > > > Captions";
> > > > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> > > > Dynamic
> > > > > Metadata (SMPTE 2094-40)";
> > > > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return
> > "Encryption
> > > > > initialization data";
> > > > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return
> > "Encryption
> > > > > info";
> > > > > >  case AV_PKT_DATA_AFD:return "Active
> > > Format
> > > > > Description data";
> > > > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > > > > index de9c079f9d..cd3286f7fb 100644
> > > > > > --- a/libavcodec/decode.c
> > > > > > +++ b/libavcodec/decode.c
> > > > > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext
> > > *avctx,
> > > > > AVFrame *frame)
> > > > > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > > > > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > > > > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > > > > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > > > > >  { AV_PKT_DATA_A53_CC,
> > >  AV_FRAME_DATA_A53_CC
> > > > > },
> > > > > > +

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-07-27 Thread Mohammad Izadi
It seems FATE is for the regression test. Here is a sample that you can use
and check:

 https://www.dropbox.com/s/3ewr2t2lvv2cy8d/20200727_143643.mp4?dl=0

Thanks,
Mohammad


On Mon, Jul 27, 2020 at 7:53 AM Vittorio Giovara 
wrote:

> On Fri, Jul 24, 2020 at 11:09 PM Mohammad Izadi <
> izadi-at-google@ffmpeg.org> wrote:
>
> > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> > andreas.rheinha...@gmail.com> wrote:
> >
> > > Mohammad Izadi:
> > > > From: Mohammad Izadi 
> > > >
> > > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that
> needs
> > > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
> > transferred
> > > to side data packet to be used or passed through.
> > > > ---
> > > >  libavcodec/avpacket.c |   1 +
> > > >  libavcodec/decode.c   |   1 +
> > > >  libavcodec/hevc_sei.c |  39 ++---
> > > >  libavcodec/hevc_sei.h |   5 ++
> > > >  libavcodec/hevcdec.c  |  16 
> > > >  libavcodec/internal.h |   9 +++
> > > >  libavcodec/packet.h   |   8 ++
> > > >  libavcodec/utils.c| 180
> ++
> > > >  libavcodec/version.h  |   2 +-
> > > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > > >
> > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > > index dce26cb31a..8307032335 <(830)%20703-2335> <(830)%20703-2335>
> 100644
> > > > --- a/libavcodec/avpacket.c
> > > > +++ b/libavcodec/avpacket.c
> > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > > AVPacketSideDataType type)
> > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content
> light
> > > level metadata";
> > > >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> > > Mapping";
> > > >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> > > Captions";
> > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> > Dynamic
> > > Metadata (SMPTE 2094-40)";
> > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> > > initialization data";
> > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> > > info";
> > > >  case AV_PKT_DATA_AFD:return "Active
> Format
> > > Description data";
> > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > > index de9c079f9d..cd3286f7fb 100644
> > > > --- a/libavcodec/decode.c
> > > > +++ b/libavcodec/decode.c
> > > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext
> *avctx,
> > > AVFrame *frame)
> > > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > > >  { AV_PKT_DATA_A53_CC,
>  AV_FRAME_DATA_A53_CC
> > > },
> > > > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
> > >  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> > > >  { AV_PKT_DATA_ICC_PROFILE,
> > > AV_FRAME_DATA_ICC_PROFILE },
> > > >  };
> > > >
> > > > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > > > index a4ec65dc1a..a490e752dd 100644
> > > > --- a/libavcodec/hevc_sei.c
> > > > +++ b/libavcodec/hevc_sei.c
> > > > @@ -25,6 +25,7 @@
> > > >  #include "golomb.h"
> > > >  #include "hevc_ps.h"
> > > >  #include "hevc_sei.h"
> > > > +#include "internal.h"
> > > >
> > > >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash
> *s,
> > > GetBitContext *gb)
> > > >  {
> > > > @@ -242,8 +243,8 @@ static int
> > > decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> > > >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> > > GetBitContext *gb,
> > > >   int size)
> > > >  {
> > > > -uint32_t country_code;
> > > > -uint32_t user_identifier;
> > > > +uint8_t country_code;
> > > > +uint16_t provider_

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-07-24 Thread Mohammad Izadi
On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> Mohammad Izadi:
> > From: Mohammad Izadi 
> >
> > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred
> to side data packet to be used or passed through.
> > ---
> >  libavcodec/avpacket.c |   1 +
> >  libavcodec/decode.c   |   1 +
> >  libavcodec/hevc_sei.c |  39 ++---
> >  libavcodec/hevc_sei.h |   5 ++
> >  libavcodec/hevcdec.c  |  16 
> >  libavcodec/internal.h |   9 +++
> >  libavcodec/packet.h   |   8 ++
> >  libavcodec/utils.c| 180 ++
> >  libavcodec/version.h  |   2 +-
> >  9 files changed, 248 insertions(+), 13 deletions(-)
> >
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index dce26cb31a..8307032335 <(830)%20703-2335> 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light
> level metadata";
> >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> Mapping";
> >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> Captions";
> > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> initialization data";
> >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> info";
> >  case AV_PKT_DATA_AFD:return "Active Format
> Description data";
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index de9c079f9d..cd3286f7fb 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >  };
> >
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index a4ec65dc1a..a490e752dd 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -25,6 +25,7 @@
> >  #include "golomb.h"
> >  #include "hevc_ps.h"
> >  #include "hevc_sei.h"
> > +#include "internal.h"
> >
> >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
> GetBitContext *gb)
> >  {
> > @@ -242,8 +243,8 @@ static int
> decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> GetBitContext *gb,
> >   int size)
> >  {
> > -uint32_t country_code;
> > -uint32_t user_identifier;
> > +uint8_t country_code;
> > +uint16_t provider_code;
> >
> >  if (size < 7)
> >  return AVERROR(EINVAL);
> > @@ -255,18 +256,31 @@ static int
> decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
> >  size--;
> >  }
> >
> > -skip_bits(gb, 8);
> > -skip_bits(gb, 8);
> > -
> > -user_identifier = get_bits_long(gb, 32);
> > -
> > -switch (user_identifier) {
> > -case MKBETAG('G', 'A', '9', '4'):
> > +provider_code = get_bits(gb, 16);
> > +
> > +const uint8_t usa_country_code = 0xB5;
> > +const uint16_t smpte_provider_code = 0x003C;
> > +if (country_code == usa_country_code &&
> > +provider_code == smpte_provider_code) {
> > +// A/341 Amendment – 2094-40
> > +uint16_t provider_oriented_code = get_bits(gb, 16);
> > +uint8_t application_identifier = get_bits(gb, 8);
> > +const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > +const uint16_t smpte2094_40_application_identifier = 0x04;
> > +if (provider_oriented_code ==
> smpte2094_40_provider_oriente

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-07-23 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/hevc_sei.c |  39 ++---
 libavcodec/hevc_sei.h |   5 ++
 libavcodec/hevcdec.c  |  16 
 libavcodec/internal.h |   9 +++
 libavcodec/packet.h   |   8 ++
 libavcodec/utils.c| 180 ++
 libavcodec/version.h  |   2 +-
 9 files changed, 248 insertions(+), 13 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dce26cb31a..8307032335 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light level 
metadata";
 case AV_PKT_DATA_SPHERICAL:  return "Spherical Mapping";
 case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
+case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption 
initialization data";
 case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption info";
 case AV_PKT_DATA_AFD:return "Active Format 
Description data";
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index de9c079f9d..cd3286f7fb 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
 { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
+{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,   
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 };
 
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index a4ec65dc1a..a490e752dd 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "internal.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -242,8 +243,8 @@ static int 
decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
  int size)
 {
-uint32_t country_code;
-uint32_t user_identifier;
+uint8_t country_code;
+uint16_t provider_code;
 
 if (size < 7)
 return AVERROR(EINVAL);
@@ -255,18 +256,31 @@ static int 
decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
 size--;
 }
 
-skip_bits(gb, 8);
-skip_bits(gb, 8);
-
-user_identifier = get_bits_long(gb, 32);
-
-switch (user_identifier) {
-case MKBETAG('G', 'A', '9', '4'):
+provider_code = get_bits(gb, 16);
+
+const uint8_t usa_country_code = 0xB5;
+const uint16_t smpte_provider_code = 0x003C;
+if (country_code == usa_country_code &&
+provider_code == smpte_provider_code) {
+// A/341 Amendment – 2094-40
+uint16_t provider_oriented_code = get_bits(gb, 16);
+uint8_t application_identifier = get_bits(gb, 8);
+const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+const uint16_t smpte2094_40_application_identifier = 0x04;
+if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
+application_identifier == smpte2094_40_application_identifier) {
+int err = ff_read_itu_t_t35_to_dynamic_hdr_plus(gb, 
s->dynamic_hdr_plus.info);
+if (err < 0 && s->dynamic_hdr_plus.info) {
+av_buffer_unref(>dynamic_hdr_plus.info);
+}
+return err;
+}
+} else {
+uint32_t  user_identifier = get_bits_long(gb, 32);
+if(user_identifier == MKBETAG('G', 'A', '9', '4'))
 return decode_registered_user_data_closed_caption(>a53_caption, 
gb, size);
-default:
-skip_bits_long(gb, size * 8);
-break;
 }
+skip_bits_long(gb, size * 8);
 return 0;
 }
 
@@ -453,4 +467,5 @@ void ff_hevc_reset_sei(HEVCSEI *s)
 av_buffer_unref(>unregistered.buf_ref[i]);
 s->unregistered.nb_buf_ref = 0;
 av_freep(>unregistered.buf_ref);
+av_buffer_unref(>dynamic_hdr_plus.info);
 }
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index 5ee7a4796d.

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC

2020-07-23 Thread Mohammad Izadi
I am not sure if you received the patch in reply to the thread? I used:
git send-email  0001-Support-HDR10-metadata-for-HEVC.patch --to=
ffmpeg-devel@ffmpeg.org --in-reply-to=
422719c5-f010-6b39-6415-b3bf46dcb...@rothenpieler.org


It seems it created a new thread. Did you receive it?

Thanks,
Mohammad


On Thu, Jul 23, 2020 at 3:29 PM Mohammad Izadi  wrote:

>
> Thanks,
> Mohammad
>
>
> On Thu, Jul 23, 2020 at 1:14 AM zhilizhao  wrote:
>
>>
>>
>> > On Jul 17, 2020, at 5:47 AM, Steinar H. Gunderson <
>> steinar+ffm...@gunderson.no> wrote:
>> >
>> > On Thu, Jul 16, 2020 at 06:34:31PM -0300, James Almer wrote:
>> >>> static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
>> >>> +static const uint8_t usa_country_code = 0xB5;
>> >>> +static const uint16_t smpte_provider_code = 0x003C;
>> >>> +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
>> >>> +static const uint16_t smpte2094_40_application_identifier = 0x04;
>> >>> +static const int64_t luminance_den = 1;
>> >>> +static const int32_t peak_luminance_den = 15;
>> >>> +static const int64_t rgb_den = 10;
>> >>> +static const int32_t fraction_pixel_den = 1000;
>> >>> +static const int32_t knee_point_den = 4095;
>> >>> +static const int32_t bezier_anchor_den = 1023;
>> >>> +static const int32_t saturation_weight_den = 8;
>> >> Same, no global state.
>> >
>> > It's not state if it can't be changed.
>>
>> If there is any chance to reuse these variables, I prefer current style
>> than
>> use a literal with comments next to it.
>>
> I am going to use them in both read/write. For now I moved them to the
> local function and I will make them global when I added the write func.
>
>>
>> >
>> > /* Steinar */
>> > --
>> > Homepage: https://www.sesse.net/
>> > ___
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel@ffmpeg.org
>> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> >
>> > To unsubscribe, visit link above, or email
>> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC.

2020-07-23 Thread Mohammad Izadi
From: Mohammad Izadi 

HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs to be 
decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is transferred to side 
data packet to be used or passed through.
---
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/hevc_sei.c |  39 ++---
 libavcodec/hevc_sei.h |   5 ++
 libavcodec/hevcdec.c  |  16 
 libavcodec/internal.h |   9 +++
 libavcodec/packet.h   |   8 ++
 libavcodec/utils.c| 180 ++
 libavcodec/version.h  |   2 +-
 9 files changed, 248 insertions(+), 13 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dce26cb31a..8307032335 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light level 
metadata";
 case AV_PKT_DATA_SPHERICAL:  return "Spherical Mapping";
 case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
+case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption 
initialization data";
 case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption info";
 case AV_PKT_DATA_AFD:return "Active Format 
Description data";
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index de9c079f9d..cd3286f7fb 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
 { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
+{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,   
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 };
 
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index a4ec65dc1a..a490e752dd 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "internal.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -242,8 +243,8 @@ static int 
decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
  int size)
 {
-uint32_t country_code;
-uint32_t user_identifier;
+uint8_t country_code;
+uint16_t provider_code;
 
 if (size < 7)
 return AVERROR(EINVAL);
@@ -255,18 +256,31 @@ static int 
decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
 size--;
 }
 
-skip_bits(gb, 8);
-skip_bits(gb, 8);
-
-user_identifier = get_bits_long(gb, 32);
-
-switch (user_identifier) {
-case MKBETAG('G', 'A', '9', '4'):
+provider_code = get_bits(gb, 16);
+
+const uint8_t usa_country_code = 0xB5;
+const uint16_t smpte_provider_code = 0x003C;
+if (country_code == usa_country_code &&
+provider_code == smpte_provider_code) {
+// A/341 Amendment – 2094-40
+uint16_t provider_oriented_code = get_bits(gb, 16);
+uint8_t application_identifier = get_bits(gb, 8);
+const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+const uint16_t smpte2094_40_application_identifier = 0x04;
+if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
+application_identifier == smpte2094_40_application_identifier) {
+int err = ff_read_itu_t_t35_to_dynamic_hdr_plus(gb, 
s->dynamic_hdr_plus.info);
+if (err < 0 && s->dynamic_hdr_plus.info) {
+av_buffer_unref(>dynamic_hdr_plus.info);
+}
+return err;
+}
+} else {
+uint32_t  user_identifier = get_bits_long(gb, 32);
+if(user_identifier == MKBETAG('G', 'A', '9', '4'))
 return decode_registered_user_data_closed_caption(>a53_caption, 
gb, size);
-default:
-skip_bits_long(gb, size * 8);
-break;
 }
+skip_bits_long(gb, size * 8);
 return 0;
 }
 
@@ -453,4 +467,5 @@ void ff_hevc_reset_sei(HEVCSEI *s)
 av_buffer_unref(>unregistered.buf_ref[i]);
 s->unregistered.nb_buf_ref = 0;
 av_freep(>unregistered.buf_ref);
+av_buffer_unref(>dynamic_hdr_plus.info);
 }
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index 5ee7a4796d.

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC

2020-07-23 Thread Mohammad Izadi
Thanks,
Mohammad


On Thu, Jul 23, 2020 at 1:14 AM zhilizhao  wrote:

>
>
> > On Jul 17, 2020, at 5:47 AM, Steinar H. Gunderson <
> steinar+ffm...@gunderson.no> wrote:
> >
> > On Thu, Jul 16, 2020 at 06:34:31PM -0300, James Almer wrote:
> >>> static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
> >>> +static const uint8_t usa_country_code = 0xB5;
> >>> +static const uint16_t smpte_provider_code = 0x003C;
> >>> +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> >>> +static const uint16_t smpte2094_40_application_identifier = 0x04;
> >>> +static const int64_t luminance_den = 1;
> >>> +static const int32_t peak_luminance_den = 15;
> >>> +static const int64_t rgb_den = 10;
> >>> +static const int32_t fraction_pixel_den = 1000;
> >>> +static const int32_t knee_point_den = 4095;
> >>> +static const int32_t bezier_anchor_den = 1023;
> >>> +static const int32_t saturation_weight_den = 8;
> >> Same, no global state.
> >
> > It's not state if it can't be changed.
>
> If there is any chance to reuse these variables, I prefer current style
> than
> use a literal with comments next to it.
>
I am going to use them in both read/write. For now I moved them to the
local function and I will make them global when I added the write func.

>
> >
> > /* Steinar */
> > --
> > Homepage: https://www.sesse.net/
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC

2020-07-23 Thread Mohammad Izadi
Please see my answers inline:

On Thu, Jul 16, 2020 at 2:34 PM James Almer  wrote:

> On 7/16/2020 4:23 PM, Mohammad Izadi wrote:
> > From: Mohammad Izadi 
> >
> > ---
> >  libavcodec/avpacket.c |   1 +
> >  libavcodec/decode.c   |   1 +
> >  libavcodec/hevc_sei.c |  40 +++---
> >  libavcodec/hevc_sei.h |   5 ++
> >  libavcodec/hevcdec.c  |   7 ++
> >  libavcodec/internal.h |   9 +++
> >  libavcodec/packet.h   |   9 +++
> >  libavcodec/utils.c| 180 ++
> >  libavcodec/version.h  |   2 +-
> >  9 files changed, 241 insertions(+), 13 deletions(-)
> >
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index dce26cb31a..8307032335 <(830)%20703-2335> 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light
> level metadata";
> >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> Mapping";
> >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> Captions";
> > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic
> Metadata (SMPTE 2094-40)";
> >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> initialization data";
> >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> info";
> >  case AV_PKT_DATA_AFD:return "Active Format
> Description data";
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index de9c079f9d..cd3286f7fb 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> AVFrame *frame)
> >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> },
> > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
>  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> >  { AV_PKT_DATA_ICC_PROFILE,
> AV_FRAME_DATA_ICC_PROFILE },
> >  };
> >
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index a4ec65dc1a..096c414d91 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -25,6 +25,12 @@
> >  #include "golomb.h"
> >  #include "hevc_ps.h"
> >  #include "hevc_sei.h"
> > +#include "internal.h"
> > +
> > +static const uint8_t usa_country_code = 0xB5;
> > +static const uint16_t smpte_provider_code = 0x003C;
> > +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > +static const uint16_t smpte2094_40_application_identifier = 0x04;
>
> No global state, please. You can just use the values in question and add
> a comment next to them to describe their meaning, like it's done for a
> lot other values in this file.
>
> Done.

> >
> >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
> GetBitContext *gb)
> >  {
> > @@ -242,8 +248,8 @@ static int
> decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> GetBitContext *gb,
> >   int size)
> >  {
> > -uint32_t country_code;
> > -uint32_t user_identifier;
> > +uint8_t country_code;
> > +uint16_t provider_code;
> >
> >  if (size < 7)
> >  return AVERROR(EINVAL);
> > @@ -255,18 +261,27 @@ static int
> decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
> >  size--;
> >  }
> >
> > -skip_bits(gb, 8);
> > -skip_bits(gb, 8);
> > -
> > -user_identifier = get_bits_long(gb, 32);
> > -
> > -switch (user_identifier) {
> > -case MKBETAG('G', 'A', '9', '4'):
> > +provider_code = get_bits(gb, 16);
> > +
> > +if (country_code == usa_country_code &&
> > +provider_code == smpte_provider_code) {
> > +// A/341 Amendment – 2094-40
> > +uint16_t provider_oriented_code = get_bits(gb, 16);
> > +uint8_t application_identifier = get_bits(gb, 8);
> > +if (provider_oriented_code ==
> smpte2094_40_provider_o

Re: [FFmpeg-devel] [PATCH] Support HDR10+ metadata for HEVC

2020-07-22 Thread Mohammad Izadi
Please see my answers inline:


On Thu, Jul 16, 2020 at 1:30 PM Carl Eugen Hoyos  wrote:

> Am Do., 16. Juli 2020 um 21:24 Uhr schrieb Mohammad Izadi
> :
>
> > -user_identifier = get_bits_long(gb, 32);
> > -
> > -switch (user_identifier) {
> > -case MKBETAG('G', 'A', '9', '4'):
>
> Why did you have to change this existing code?
>
> We need to read the metadata (A/341 Amendment – 2094-40
<https://www.atsc.org/wp-content/uploads/2018/02/S34-301r2-A341-Amendment-2094-40.pdf>)
from the ITU-T T.35. Here is the point we need to read ITU-T T.35 and
decode it. I will update the commit message to explain it.

> Could you elaborate a little on the use-cases this patch supports (and
> does not support) in the commit message?
>
> Sure, I'll do.

> A micro version bump should be sufficient.
>
> Carl Eugen
> ___
> 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] Support HDR10+ metadata for HEVC

2020-07-16 Thread Mohammad Izadi
From: Mohammad Izadi 

---
 libavcodec/avpacket.c |   1 +
 libavcodec/decode.c   |   1 +
 libavcodec/hevc_sei.c |  40 +++---
 libavcodec/hevc_sei.h |   5 ++
 libavcodec/hevcdec.c  |   7 ++
 libavcodec/internal.h |   9 +++
 libavcodec/packet.h   |   9 +++
 libavcodec/utils.c| 180 ++
 libavcodec/version.h  |   2 +-
 9 files changed, 241 insertions(+), 13 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dce26cb31a..8307032335 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light level 
metadata";
 case AV_PKT_DATA_SPHERICAL:  return "Spherical Mapping";
 case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
+case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+ Dynamic 
Metadata (SMPTE 2094-40)";
 case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption 
initialization data";
 case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption info";
 case AV_PKT_DATA_AFD:return "Active Format 
Description data";
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index de9c079f9d..cd3286f7fb 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
 { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
 { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
+{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,   
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
 { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
 };
 
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index a4ec65dc1a..096c414d91 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,12 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "internal.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -242,8 +248,8 @@ static int 
decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
  int size)
 {
-uint32_t country_code;
-uint32_t user_identifier;
+uint8_t country_code;
+uint16_t provider_code;
 
 if (size < 7)
 return AVERROR(EINVAL);
@@ -255,18 +261,27 @@ static int 
decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
 size--;
 }
 
-skip_bits(gb, 8);
-skip_bits(gb, 8);
-
-user_identifier = get_bits_long(gb, 32);
-
-switch (user_identifier) {
-case MKBETAG('G', 'A', '9', '4'):
+provider_code = get_bits(gb, 16);
+
+if (country_code == usa_country_code &&
+provider_code == smpte_provider_code) {
+// A/341 Amendment – 2094-40
+uint16_t provider_oriented_code = get_bits(gb, 16);
+uint8_t application_identifier = get_bits(gb, 8);
+if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
+application_identifier == smpte2094_40_application_identifier) {
+int err = ff_read_itu_t_t35_to_dynamic_hdr_plus(gb, 
s->dynamic_hdr_plus.info);
+if (err < 0 && s->dynamic_hdr_plus.info) {
+av_buffer_unref(>dynamic_hdr_plus.info);
+}
+return err;
+}
+} else {
+uint32_t  user_identifier = get_bits_long(gb, 32);
+if(user_identifier == MKBETAG('G', 'A', '9', '4'))
 return decode_registered_user_data_closed_caption(>a53_caption, 
gb, size);
-default:
-skip_bits_long(gb, size * 8);
-break;
 }
+skip_bits_long(gb, size * 8);
 return 0;
 }
 
@@ -453,4 +468,5 @@ void ff_hevc_reset_sei(HEVCSEI *s)
 av_buffer_unref(>unregistered.buf_ref[i]);
 s->unregistered.nb_buf_ref = 0;
 av_freep(>unregistered.buf_ref);
+av_buffer_unref(>dynamic_hdr_plus.info);
 }
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index 5ee7a4796d..e9e2d46ed4 100644
--- a/libavcodec/hevc_sei.h
+++ b/libavcodec/hevc_sei.h
@@ -104,6 +104,10 @@ typedef struct HEVCSEIMasteringDisplay {
 uint32_t min_luminance;
 } HEVCSEIMasteringDisplay;

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-25 Thread Mohammad Izadi
On Tue, Feb 25, 2020, 9:32 PM Vittorio Giovara 
wrote:

> On Tue, Feb 25, 2020 at 9:16 PM Mohammad Izadi 
> wrote:
>
> > On Mon, Feb 24, 2020 at 9:56 AM Vittorio Giovara <
> > vittorio.giov...@gmail.com>
> > wrote:
> >
> > > On Sat, Feb 22, 2020 at 12:44 PM Mohammad Izadi 
> > > wrote:
> > >
> > > > On Fri, Feb 21, 2020, 6:44 PM Vittorio Giovara <
> > > vittorio.giov...@gmail.com
> > > > >
> > > > wrote:
> > > >
> > > > > On Fri, Feb 21, 2020 at 5:17 PM Mohammad Izadi <
> moh.iz...@gmail.com>
> > > > > wrote:
> > > > >
> > > > > > Why does the struct belong to lavu? This struct is super similar
> to
> > > > > structs
> > > > > > in libavcodec/hevc_sei.h. We just move it to a new file to share
> it
> > > > > between
> > > > > > hevc and vp9 encoder/decoder.
> > > > > >
> > > > > > --
> > > > > >
> > > > >
> > > > > 1. Please kindly stop top posting:
> > > > http://www.idallen.com/topposting.html
> > > > > 2. It belongs to lavu because it's where the frame code generically
> > > code
> > > > > is. I'm not familiar with this API too much, but from what i gather
> > > users
> > > > > may need to have a way of accessing this data without pulling in
> all
> > > the
> > > > > dependencies of lavc or lavf.
> > > > >
> > > > This struct is related to parsing and SEI, not frame. If so, why
> other
> > > > structs are not in lavu? Please check similar structs in hevc_sei?
> > > >
> > >
> > > I don't think I understand your question, but if you need examples you
> > can
> > > check these patches
> > > 8f58ecc344a92e63193c38e28c173be987954bbb structure defined in lavu,
> > > e7a6f8c972a0b5b98ef7bbf393e95c434e9e2539 structure populated in lavc
> > > d91718107c33960ad295950d7419e6dba292d723 structure defined in lavu,
> used
> > in
> > > lavc
> > > 7e244c68600f479270e979258e389ed5240885fb same
> > > and so on and so on, so I'd advise you do to the same, scrapping your
> > > current code if necessary.
> > >
> > I will do, but let me explain the problem in more details and you may
> help
> > me for a solution. The patches you mentioned, contains two structs
> > AVSphericalMapping
> > and  AVMasteringDisplayMetadata in lavu. They are easily set (afew
> members)
> > in lavc. The struct for HDR10+ is very similar and I would keep it in
> lavu.
> > But, we have to parse and decode a message and then populate the values.
> > Your structs are simple and no need for parsing them in lavc.
> > So, my struct needs two steps : 1) parsing/encoding/decoding and 2)
> > populating. It is not a good idea to implement the 2 steps for each codec
> > separately. Instead it would be  better to implement once and reuse them
> as
> > both steps are long and complex. Now please advise me where is better to
> > put 1 and 2 in lavc. Right now, I have all with struct in lavu.
> >
>
> Hi Mohammad,
> thanks for explaining the problem a bit better. If that's the case you
> could have an helper function that parses the data in lavc (usually these
> functions are prefixed with ff_, meaning their intended use is internal
> within a library) and use the helper function to parse whatever buffer you
> pass. This wrapper could then return a lavu struct to be embedded in a side
> data message like in the examples I sent you.
> Let me know if this is clear enough for you
> Thanks
>

Thanks for your solution. I have to use the parser or helper function in
libavformat for mkv too. Am I allowed to use the ff_ helpers in lavf?

> --
> Vittorio
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-25 Thread Mohammad Izadi
On Mon, Feb 24, 2020 at 9:56 AM Vittorio Giovara 
wrote:

> On Sat, Feb 22, 2020 at 12:44 PM Mohammad Izadi 
> wrote:
>
> > On Fri, Feb 21, 2020, 6:44 PM Vittorio Giovara <
> vittorio.giov...@gmail.com
> > >
> > wrote:
> >
> > > On Fri, Feb 21, 2020 at 5:17 PM Mohammad Izadi 
> > > wrote:
> > >
> > > > Why does the struct belong to lavu? This struct is super similar to
> > > structs
> > > > in libavcodec/hevc_sei.h. We just move it to a new file to share it
> > > between
> > > > hevc and vp9 encoder/decoder.
> > > >
> > > > --
> > > >
> > >
> > > 1. Please kindly stop top posting:
> > http://www.idallen.com/topposting.html
> > > 2. It belongs to lavu because it's where the frame code generically
> code
> > > is. I'm not familiar with this API too much, but from what i gather
> users
> > > may need to have a way of accessing this data without pulling in all
> the
> > > dependencies of lavc or lavf.
> > >
> > This struct is related to parsing and SEI, not frame. If so, why other
> > structs are not in lavu? Please check similar structs in hevc_sei?
> >
>
> I don't think I understand your question, but if you need examples you can
> check these patches
> 8f58ecc344a92e63193c38e28c173be987954bbb structure defined in lavu,
> e7a6f8c972a0b5b98ef7bbf393e95c434e9e2539 structure populated in lavc
> d91718107c33960ad295950d7419e6dba292d723 structure defined in lavu, used in
> lavc
> 7e244c68600f479270e979258e389ed5240885fb same
> and so on and so on, so I'd advise you do to the same, scrapping your
> current code if necessary.
>
I will do, but let me explain the problem in more details and you may help
me for a solution. The patches you mentioned, contains two structs
AVSphericalMapping
and  AVMasteringDisplayMetadata in lavu. They are easily set (afew members)
in lavc. The struct for HDR10+ is very similar and I would keep it in lavu.
But, we have to parse and decode a message and then populate the values.
Your structs are simple and no need for parsing them in lavc.
So, my struct needs two steps : 1) parsing/encoding/decoding and 2)
populating. It is not a good idea to implement the 2 steps for each codec
separately. Instead it would be  better to implement once and reuse them as
both steps are long and complex. Now please advise me where is better to
put 1 and 2 in lavc. Right now, I have all with struct in lavu.

> --
> Vittorio
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-22 Thread Mohammad Izadi
On Fri, Feb 21, 2020, 6:44 PM Vittorio Giovara 
wrote:

> On Fri, Feb 21, 2020 at 5:17 PM Mohammad Izadi 
> wrote:
>
> > Why does the struct belong to lavu? This struct is super similar to
> structs
> > in libavcodec/hevc_sei.h. We just move it to a new file to share it
> between
> > hevc and vp9 encoder/decoder.
> >
> > --
> >
>
> 1. Please kindly stop top posting: http://www.idallen.com/topposting.html
> 2. It belongs to lavu because it's where the frame code generically code
> is. I'm not familiar with this API too much, but from what i gather users
> may need to have a way of accessing this data without pulling in all the
> dependencies of lavc or lavf.
>
This struct is related to parsing and SEI, not frame. If so, why other
structs are not in lavu? Please check similar structs in hevc_sei?

>
> Vittorio
>
> On Fri, Feb 21, 2020 at 2:03 PM Hendrik Leppkes 
> wrote:
> >
> > > On Fri, Feb 21, 2020 at 7:08 PM Mohammad Izadi 
> > > wrote:
> > > >
> > > > If you believe lavc is at the top of the hierarchy, I can simply move
> > the
> > > > file to lavc. Then both lavc and lavf can use it and hierarchy is
> > > > respected. Can I do that? Doesn't break API? Any objection (with
> > > solution)?
> > > > Let's make right decisions to speed up the process please :).
> > > > --
> > >
> > >
> > > The struct itself belongs in lavu with everything else of AVFrame. The
> > > parsing of the mpeg-specific SEI data belongs in avcodec. You can't
> > > just blindly move everything.
> > >
> > > - Hendrik
> > > ___
> > > 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".
>
>
>
> --
> Vittorio
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-21 Thread Mohammad Izadi
Why does the struct belong to lavu? This struct is super similar to structs
in libavcodec/hevc_sei.h. We just move it to a new file to share it between
hevc and vp9 encoder/decoder.

--
Best,
Mohammad


On Fri, Feb 21, 2020 at 2:03 PM Hendrik Leppkes  wrote:

> On Fri, Feb 21, 2020 at 7:08 PM Mohammad Izadi 
> wrote:
> >
> > If you believe lavc is at the top of the hierarchy, I can simply move the
> > file to lavc. Then both lavc and lavf can use it and hierarchy is
> > respected. Can I do that? Doesn't break API? Any objection (with
> solution)?
> > Let's make right decisions to speed up the process please :).
> > --
>
>
> The struct itself belongs in lavu with everything else of AVFrame. The
> parsing of the mpeg-specific SEI data belongs in avcodec. You can't
> just blindly move everything.
>
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-21 Thread Mohammad Izadi
If you believe lavc is at the top of the hierarchy, I can simply move the
file to lavc. Then both lavc and lavf can use it and hierarchy is
respected. Can I do that? Doesn't break API? Any objection (with solution)?
Let's make right decisions to speed up the process please :).
--
Best,
Mohammad


On Fri, Feb 21, 2020 at 2:53 AM Hendrik Leppkes  wrote:

> On Fri, Feb 21, 2020 at 5:59 AM Vittorio Giovara
>  wrote:
> >
> > On Thu, Feb 20, 2020 at 6:38 PM James Almer  wrote:
> >
> > > On 2/20/2020 5:02 PM, Vittorio Giovara wrote:
> > > > On Mon, Feb 10, 2020 at 3:14 PM Mohammad Izadi 
> > > wrote:
> > > >
> > > >> From: Mohammad Izadi 
> > > >>
> > > >> Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet
> side
> > > >> data in the follow-up CLs.
> > > >> ---
> > > >>  libavutil/hdr_dynamic_metadata.c | 165
> +++
> > > >>  libavutil/hdr_dynamic_metadata.h |  13 ++-
> > > >>  libavutil/version.h  |   2 +-
> > > >>  3 files changed, 178 insertions(+), 2 deletions(-)
> > > >>
> > > >> diff --git a/libavutil/hdr_dynamic_metadata.c
> > > >> b/libavutil/hdr_dynamic_metadata.c
> > > >> index 0fa1ee82de..f24bcb40f5 100644
> > > >> --- a/libavutil/hdr_dynamic_metadata.c
> > > >> +++ b/libavutil/hdr_dynamic_metadata.c
> > > >> @@ -19,8 +19,17 @@
> > > >>   */
> > > >>
> > > >>  #include "hdr_dynamic_metadata.h"
> > > >> +#include "libavcodec/get_bits.h"
> > > >>
> > > >
> > > > wait is it ok to use libavcodec headers in libavutil? while it's
> fine at
> > > > compilation time since it is an inlined header, I don't think it's a
> good
> > > > idea to freely use such functions in this way: what I would do is
> rather
> > > > implement the parsing in libavcodec, store the fields in a structure
> > > > defined in libavutil and then use this new structure in here
> > >
> > > This seems excessive only to use a bitstream reader to read a bunch of
> > > fields in a buffer.
> > >
> > > get_bits.h is included in lavf, so i don't see why it couldn't be used
> > > in lavu.
> >
> >
> > bacuase lavf is a library which depends on lavc, not vice versa,
> hierarchy
> > is respected
> >
> > As you said it's inlined.
> > >
> >
> > I still consider it a poor design choice: either make bitstream reader
> > public in a separate library (not easy, i am aware) or do the bitstream
> > reading where the bistream actually is, IMO
> >
>
> I agree that the parsing should just move to avcodec. We parse every
> other SEI straight in the codec it comes from, why does this one have
> parsing in avutil? It seems weird.
>
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-20 Thread Mohammad Izadi
On Thu, Feb 20, 2020 at 12:10 PM Vittorio Giovara <
vittorio.giov...@gmail.com> wrote:

> On Mon, Feb 10, 2020 at 3:14 PM Mohammad Izadi 
> wrote:
>
> > From: Mohammad Izadi 
> >
> > Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> > data in the follow-up CLs.
> > ---
> >  libavutil/hdr_dynamic_metadata.c | 165 +++
> >  libavutil/hdr_dynamic_metadata.h |  13 ++-
> >  libavutil/version.h  |   2 +-
> >  3 files changed, 178 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavutil/hdr_dynamic_metadata.c
> > b/libavutil/hdr_dynamic_metadata.c
> > index 0fa1ee82de..f24bcb40f5 100644
> > --- a/libavutil/hdr_dynamic_metadata.c
> > +++ b/libavutil/hdr_dynamic_metadata.c
> > @@ -19,8 +19,17 @@
> >   */
> >
> >  #include "hdr_dynamic_metadata.h"
> > +#include "libavcodec/get_bits.h"
> >
>
> wait is it ok to use libavcodec headers in libavutil? while it's fine at
> compilation time since it is an inlined header, I don't think it's a good
> idea to freely use such functions in this way: what I would do is rather
> implement the parsing in libavcodec, store the fields in a structure
> defined in libavutil and then use this new structure in here
>
> What if I move it all to livavcodec?

>
> >  #include "mem.h"
> >
> > +static const int32_t luminance_den = 1;
> > +static const int32_t peak_luminance_den = 15;
> > +static const int32_t rgb_den = 10;
> > +static const int32_t fraction_pixel_den = 1000;
> > +static const int32_t knee_point_den = 4095;
> > +static const int32_t bezier_anchor_den = 1023;
> > +static const int32_t saturation_weight_den = 8;
> >
>
> These fields could also be stored in the structure i mentioned, rather then
> having them declared as static here.
>
You mean to create a new struct just for constants?

> --
> Vittorio
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-19 Thread Mohammad Izadi
On Wed, Feb 19, 2020 at 4:22 PM Mark Thompson  wrote:

> On 10/02/2020 19:38, Mohammad Izadi wrote:
> > On Sun, Feb 9, 2020 at 8:31 AM Mark Thompson  wrote:
> >
> >> On 07/02/2020 17:46, Mohammad Izadi wrote:
> >>> From: Mohammad Izadi 
> >>>
> >>> Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> >> data in the follow-up CLs.
> >>> ---
> >>>  libavutil/hdr_dynamic_metadata.c | 165 +++
> >>>  libavutil/hdr_dynamic_metadata.h |  12 ++-
> >>>  libavutil/version.h  |   2 +-
> >>>  3 files changed, 177 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/libavutil/hdr_dynamic_metadata.c
> >> b/libavutil/hdr_dynamic_metadata.c
> >>> index 0fa1ee82de..a988bcd2d5 100644
> >>> --- a/libavutil/hdr_dynamic_metadata.c
> >>> +++ b/libavutil/hdr_dynamic_metadata.c
> >>> ...
> >>> +static const int32_t peak_luminance_den = 15;
> >>> +static const int64_t rgb_den = 10;
> >>> +static const int32_t fraction_pixel_den = 1000;
> >>> +static const int32_t knee_point_den = 4095;
> >>> +static const int32_t bezier_anchor_den = 1023;
> >>> +static const int32_t saturation_weight_den = 8;
> >>
> >> It would probably be clearer just to put these constants inline; there
> >> isn't really any use to having the values standalone.
> >>
> > You are right. Actually, I am going to push the encode function in my
> next
> > CL and the static vars will be shared between both encode and decode
> > function.
>
> My point is that separating the constants is actively unhelpful in
> matching the standard to the code.
>
> From the standard you can read in one paragraph:
>
> "knee_point_x[ w ] –   specifies the x coordinate of the separation point
> between the linear part and thecurved part of the tone mapping function.
> The value of knee_point_x[ w ] shall be in the range of 0 to 4,095,
> inclusive, where 0 maps to 0 cd/m2 and the full range of 4,095 maps to the
> maximum of the scene maximum luminance and the target peak luminance in
> cd/m2."
>
> But you've split that into two distinct locations by putting
> knee_point_den as a constant here and then the code below which refers to
> it when it would be clearer to just put the constant in the code in the
> same way that the standard does.
>
> I totally understand your point. I know it should be close to their local
vars and settings. But I am not sure if you get my point. I am going to use
the constants in two functions in my next CL. If I move them to the
function now, I have to move them back in the next CL. I am using the
constants in encode and decode function. I cannot define them separately
and locally if I want to follow programming standards. I need to make sure
the values are the same for both functions.

> >>> +
> >>>  AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
> >>>  {
> >>>  AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
> >>> @@ -45,3 +54,159 @@ AVDynamicHDRPlus
> >> *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
> >>>
> >>>  return (AVDynamicHDRPlus *)side_data->data;
> >>>  }
> >>> +
> >>> +int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
> >>> +AVDynamicHDRPlus *s)
> >>
> >> Why is this function being added to libavutil?  It looks like it's meant
> >> for decoding UDR SEI messages only, so it should probably be in the
> >> relevant place in libavcodec.
> >>
> > I have used this function in my local code to decode HDR10+ of SEI
> message
> > (libavcodec) and also HDR10+ in matroska container (ibavformat). I will
> > push them in my next CLs.
>
> Um, so?  The parsing code can still go next to its uses in libavcodec.
>
I just wanted to say it would be used in two places libavcodec and
libavformat. Never mind, I don't know where is suitable for them. Where do
you want to move them?

>
> >>> +{
> >>> +int w, i, j;
> >>> +GetBitContext gb;
> >>> +if (!data)
> >>> +return AVERROR_INVALIDDATA;
> >>> +
> >>> +int ret = init_get_bits8(, data, size);
> >>> +if (ret < 0)
> >>> +return AVERROR_INVALIDDATA;
> >>> +
> >>> +if (get_bits_left() < 2)
> >>> +return AVERROR_INVALIDDATA;
> >>> +

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-19 Thread Mohammad Izadi
The comment was wrong.
--
Best,
Mohammad


On Wed, Feb 19, 2020 at 7:22 AM Derek Buitenhuis 
wrote:

> On 10/02/2020 19:44, Mohammad Izadi wrote:
> >  /**
> >   * The nominal maximum display luminance of the targeted system
> display,
> > - * in units of 0.0001 candelas per square metre. The value shall be
> in
> > + * in units of 1 candelas per square metre. The value shall be in
> >   * the range of 0 to 1, inclusive.
> >   */
> >  AVRational targeted_system_display_maximum_luminance;
>
> Is this comment change related to a behavior change (thus an API
> break), or was it always 1, and the comment was wrong?
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-18 Thread Mohammad Izadi
Hello,

What's the status of the cl review? Is it good to submit?
--
Best,
Mohammad


On Mon, Feb 10, 2020 at 11:44 AM Mohammad Izadi  wrote:

> From: Mohammad Izadi 
>
> Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> data in the follow-up CLs.
> ---
>  libavutil/hdr_dynamic_metadata.c | 165 +++
>  libavutil/hdr_dynamic_metadata.h |  13 ++-
>  libavutil/version.h  |   2 +-
>  3 files changed, 178 insertions(+), 2 deletions(-)
>
> diff --git a/libavutil/hdr_dynamic_metadata.c
> b/libavutil/hdr_dynamic_metadata.c
> index 0fa1ee82de..f24bcb40f5 100644
> --- a/libavutil/hdr_dynamic_metadata.c
> +++ b/libavutil/hdr_dynamic_metadata.c
> @@ -19,8 +19,17 @@
>   */
>
>  #include "hdr_dynamic_metadata.h"
> +#include "libavcodec/get_bits.h"
>  #include "mem.h"
>
> +static const int32_t luminance_den = 1;
> +static const int32_t peak_luminance_den = 15;
> +static const int32_t rgb_den = 10;
> +static const int32_t fraction_pixel_den = 1000;
> +static const int32_t knee_point_den = 4095;
> +static const int32_t bezier_anchor_den = 1023;
> +static const int32_t saturation_weight_den = 8;
> +
>  AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
>  {
>  AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
> @@ -45,3 +54,159 @@ AVDynamicHDRPlus
> *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
>
>  return (AVDynamicHDRPlus *)side_data->data;
>  }
> +
> +int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
> +  AVDynamicHDRPlus *s)
> +{
> +int w, i, j;
> +GetBitContext gb;
> +if (!data)
> +return AVERROR_INVALIDDATA;
> +
> +int ret = init_get_bits8(, data, size);
> +if (ret < 0)
> +return AVERROR_INVALIDDATA;
> +
> +if (get_bits_left() < 2)
> +return AVERROR_INVALIDDATA;
> +s->num_windows = get_bits(, 2);
> +
> +if (s->num_windows < 1 || s->num_windows > 3)
> +return AVERROR_INVALIDDATA;
> +
> +if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
> +return AVERROR_INVALIDDATA;
> +for (w = 1; w < s->num_windows; w++) {
> +s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
> +s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
> +s->params[w].window_lower_right_corner_x.num = get_bits(, 16);
> +s->params[w].window_lower_right_corner_y.num = get_bits(, 16);
> +// The corners are set to absolute coordinates here. They should
> be
> +// converted to the relative coordinates (in [0, 1]) in the
> decoder.
> +s->params[w].window_upper_left_corner_x.den = 1;
> +s->params[w].window_upper_left_corner_y.den = 1;
> +s->params[w].window_lower_right_corner_x.den = 1;
> +s->params[w].window_lower_right_corner_y.den = 1;
> +
> +s->params[w].center_of_ellipse_x = get_bits(, 16);
> +s->params[w].center_of_ellipse_y = get_bits(, 16);
> +s->params[w].rotation_angle = get_bits(, 8);
> +s->params[w].semimajor_axis_internal_ellipse = get_bits(, 16);
> +s->params[w].semimajor_axis_external_ellipse = get_bits(, 16);
> +s->params[w].semiminor_axis_external_ellipse = get_bits(, 16);
> +s->params[w].overlap_process_option = get_bits1();
> +}
> +
> +if (get_bits_left() < 28)
> +return AVERROR_INVALIDDATA;
> +s->targeted_system_display_maximum_luminance.num = get_bits(, 27);
> +s->targeted_system_display_maximum_luminance.den = luminance_den;
> +s->targeted_system_display_actual_peak_luminance_flag =
> get_bits1();
> +
> +if (s->targeted_system_display_actual_peak_luminance_flag) {
> +int rows, cols;
> +if (get_bits_left() < 10)
> +return AVERROR_INVALIDDATA;
> +rows = get_bits(, 5);
> +cols = get_bits(, 5);
> +if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25)))
> +return AVERROR_INVALIDDATA;
> +
> +s->num_rows_targeted_system_display_actual_peak_luminance = rows;
> +s->num_cols_targeted_system_display_actual_peak_luminance = cols;
> +
> +if (get_bits_left() < (rows * cols * 4))
> +return AVERROR_INVALIDDATA;
> +
> +for (i = 0; i < rows; i++) {
> +for (j = 0; j < cols; j++) {
> +
> s->targeted_system_display_actual_peak_luminance[i][j].num = get_bits(,
> 4);
> +
> s->targeted_system_display_actual_peak_luminance[i][j].

[FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-10 Thread Mohammad Izadi
From: Mohammad Izadi 

Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side data in 
the follow-up CLs.
---
 libavutil/hdr_dynamic_metadata.c | 165 +++
 libavutil/hdr_dynamic_metadata.h |  13 ++-
 libavutil/version.h  |   2 +-
 3 files changed, 178 insertions(+), 2 deletions(-)

diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c
index 0fa1ee82de..f24bcb40f5 100644
--- a/libavutil/hdr_dynamic_metadata.c
+++ b/libavutil/hdr_dynamic_metadata.c
@@ -19,8 +19,17 @@
  */
 
 #include "hdr_dynamic_metadata.h"
+#include "libavcodec/get_bits.h"
 #include "mem.h"
 
+static const int32_t luminance_den = 1;
+static const int32_t peak_luminance_den = 15;
+static const int32_t rgb_den = 10;
+static const int32_t fraction_pixel_den = 1000;
+static const int32_t knee_point_den = 4095;
+static const int32_t bezier_anchor_den = 1023;
+static const int32_t saturation_weight_den = 8;
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 {
 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
@@ -45,3 +54,159 @@ AVDynamicHDRPlus 
*av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 
 return (AVDynamicHDRPlus *)side_data->data;
 }
+
+int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
+  AVDynamicHDRPlus *s)
+{
+int w, i, j;
+GetBitContext gb;
+if (!data)
+return AVERROR_INVALIDDATA;
+
+int ret = init_get_bits8(, data, size);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(, 2);
+
+if (s->num_windows < 1 || s->num_windows > 3)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(, 16);
+s->params[w].center_of_ellipse_y = get_bits(, 16);
+s->params[w].rotation_angle = get_bits(, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(, 16);
+s->params[w].overlap_process_option = get_bits1();
+}
+
+if (get_bits_left() < 28)
+return AVERROR_INVALIDDATA;
+s->targeted_system_display_maximum_luminance.num = get_bits(, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits1();
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left() < 10)
+return AVERROR_INVALIDDATA;
+rows = get_bits(, 5);
+cols = get_bits(, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25)))
+return AVERROR_INVALIDDATA;
+
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left() < (rows * cols * 4))
+return AVERROR_INVALIDDATA;
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left() < (3 * 17 + 17 + 4))
+return AVERROR_INVALIDDATA;
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(, 4);
+
+if (get_bits_left() <
+(s->params[w].num_distribution_maxrgb_percent

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-10 Thread Mohammad Izadi
On Sun, Feb 9, 2020 at 8:31 AM Mark Thompson  wrote:

> On 07/02/2020 17:46, Mohammad Izadi wrote:
> > From: Mohammad Izadi 
> >
> > Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> data in the follow-up CLs.
> > ---
> >  libavutil/hdr_dynamic_metadata.c | 165 +++
> >  libavutil/hdr_dynamic_metadata.h |  12 ++-
> >  libavutil/version.h  |   2 +-
> >  3 files changed, 177 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavutil/hdr_dynamic_metadata.c
> b/libavutil/hdr_dynamic_metadata.c
> > index 0fa1ee82de..a988bcd2d5 100644
> > --- a/libavutil/hdr_dynamic_metadata.c
> > +++ b/libavutil/hdr_dynamic_metadata.c
> > @@ -19,8 +19,17 @@
> >   */
> >
> >  #include "hdr_dynamic_metadata.h"
> > +#include "libavcodec/get_bits.h"
> >  #include "mem.h"
> >
> > +static const int64_t luminance_den = 1;
>
> The int64_t looks very shady - am I missing some special integer promotion
> behaviour here?  (Note that AVRational num/den are int.)
>
Done.

>
> > +static const int32_t peak_luminance_den = 15;
> > +static const int64_t rgb_den = 10;
> > +static const int32_t fraction_pixel_den = 1000;
> > +static const int32_t knee_point_den = 4095;
> > +static const int32_t bezier_anchor_den = 1023;
> > +static const int32_t saturation_weight_den = 8;
>
> It would probably be clearer just to put these constants inline; there
> isn't really any use to having the values standalone.
>
You are right. Actually, I am going to push the encode function in my next
CL and the static vars will be shared between both encode and decode
function.

>
> > +
> >  AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
> >  {
> >  AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
> > @@ -45,3 +54,159 @@ AVDynamicHDRPlus
> *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
> >
> >  return (AVDynamicHDRPlus *)side_data->data;
> >  }
> > +
> > +int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
> > +AVDynamicHDRPlus *s)
>
> Why is this function being added to libavutil?  It looks like it's meant
> for decoding UDR SEI messages only, so it should probably be in the
> relevant place in libavcodec.
>
I have used this function in my local code to decode HDR10+ of SEI message
(libavcodec) and also HDR10+ in matroska container (ibavformat). I will
push them in my next CLs.

>
> > +{
> > +int w, i, j;
> > +GetBitContext gb;
> > +if (!data)
> > +return AVERROR_INVALIDDATA;
> > +
> > +int ret = init_get_bits8(, data, size);
> > +if (ret < 0)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (get_bits_left() < 2)
> > +return AVERROR_INVALIDDATA;
> > +s->num_windows = get_bits(, 2);
> > +
> > +if (s->num_windows < 1 || s->num_windows > 3)
> > +return AVERROR_INVALIDDATA;
> > +
> > +if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
> > +return AVERROR_INVALIDDATA;
> > +for (w = 1; w < s->num_windows; w++) {
> > +s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
> > +s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
> > +s->params[w].window_lower_right_corner_x.num = get_bits(,
> 16);
> > +s->params[w].window_lower_right_corner_y.num = get_bits(,
> 16);
> > +// The corners are set to absolute coordinates here. They
> should be
> > +// converted to the relative coordinates (in [0, 1]) in the
> decoder.
> > +s->params[w].window_upper_left_corner_x.den = 1;
> > +s->params[w].window_upper_left_corner_y.den = 1;
> > +s->params[w].window_lower_right_corner_x.den = 1;
> > +s->params[w].window_lower_right_corner_y.den = 1;
> > +
> > +s->params[w].center_of_ellipse_x = get_bits(, 16);
> > +s->params[w].center_of_ellipse_y = get_bits(, 16);
> > +s->params[w].rotation_angle = get_bits(, 8);
>
> You're range-checking some fields here but not others.  Should everything
> be verified against the constraints so that the comments on the structure
> in the header file are actually true?
>
The intention is to only pass through HDR10+ from src file to dst file. The
interpretation of the data is on the user/caller. I think it is better not
to drop the metadata by verification. I did some range checking like 

[FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-07 Thread Mohammad Izadi
From: Mohammad Izadi 

Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side data in 
the follow-up CLs.
---
 libavutil/hdr_dynamic_metadata.c | 165 +++
 libavutil/hdr_dynamic_metadata.h |  12 ++-
 libavutil/version.h  |   2 +-
 3 files changed, 177 insertions(+), 2 deletions(-)

diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c
index 0fa1ee82de..a988bcd2d5 100644
--- a/libavutil/hdr_dynamic_metadata.c
+++ b/libavutil/hdr_dynamic_metadata.c
@@ -19,8 +19,17 @@
  */
 
 #include "hdr_dynamic_metadata.h"
+#include "libavcodec/get_bits.h"
 #include "mem.h"
 
+static const int64_t luminance_den = 1;
+static const int32_t peak_luminance_den = 15;
+static const int64_t rgb_den = 10;
+static const int32_t fraction_pixel_den = 1000;
+static const int32_t knee_point_den = 4095;
+static const int32_t bezier_anchor_den = 1023;
+static const int32_t saturation_weight_den = 8;
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 {
 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
@@ -45,3 +54,159 @@ AVDynamicHDRPlus 
*av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 
 return (AVDynamicHDRPlus *)side_data->data;
 }
+
+int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
+  AVDynamicHDRPlus *s)
+{
+int w, i, j;
+GetBitContext gb;
+if (!data)
+return AVERROR_INVALIDDATA;
+
+int ret = init_get_bits8(, data, size);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(, 2);
+
+if (s->num_windows < 1 || s->num_windows > 3)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(, 16);
+s->params[w].center_of_ellipse_y = get_bits(, 16);
+s->params[w].rotation_angle = get_bits(, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(, 16);
+s->params[w].overlap_process_option = get_bits1();
+}
+
+if (get_bits_left() < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits1();
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left() < 10)
+return AVERROR(EINVAL);
+rows = get_bits(, 5);
+cols = get_bits(, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25)))
+return AVERROR_INVALIDDATA;
+
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left() < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left() < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(, 4);
+
+if (get_bits_left() <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))

[FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-05 Thread Mohammad Izadi
From: Mohammad Izadi 

Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side data in 
the follow-up CLs.
---
 libavutil/hdr_dynamic_metadata.c | 165 +++
 libavutil/hdr_dynamic_metadata.h |  12 ++-
 libavutil/version.h  |   2 +-
 3 files changed, 177 insertions(+), 2 deletions(-)

diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c
index 0fa1ee82de..a988bcd2d5 100644
--- a/libavutil/hdr_dynamic_metadata.c
+++ b/libavutil/hdr_dynamic_metadata.c
@@ -19,8 +19,17 @@
  */
 
 #include "hdr_dynamic_metadata.h"
+#include "libavcodec/get_bits.h"
 #include "mem.h"
 
+static const int64_t luminance_den = 1;
+static const int32_t peak_luminance_den = 15;
+static const int64_t rgb_den = 10;
+static const int32_t fraction_pixel_den = 1000;
+static const int32_t knee_point_den = 4095;
+static const int32_t bezier_anchor_den = 1023;
+static const int32_t saturation_weight_den = 8;
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 {
 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
@@ -45,3 +54,159 @@ AVDynamicHDRPlus 
*av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 
 return (AVDynamicHDRPlus *)side_data->data;
 }
+
+int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
+  AVDynamicHDRPlus *s)
+{
+int w, i, j;
+GetBitContext gb;
+if (!data)
+return AVERROR_INVALIDDATA;
+
+int ret = init_get_bits8(, data, size);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(, 2);
+
+if (s->num_windows < 1 || s->num_windows > 3)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(, 16);
+s->params[w].center_of_ellipse_y = get_bits(, 16);
+s->params[w].rotation_angle = get_bits(, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(, 16);
+s->params[w].overlap_process_option = get_bits1();
+}
+
+if (get_bits_left() < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits1();
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left() < 10)
+return AVERROR(EINVAL);
+rows = get_bits(, 5);
+cols = get_bits(, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25)))
+return AVERROR_INVALIDDATA;
+
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left() < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left() < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(, 4);
+
+if (get_bits_left() <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-05 Thread Mohammad Izadi
Please check my responses inline:


On Wed, Feb 5, 2020 at 5:48 AM Moritz Barsnick  wrote:

> Hi Mohammad,
>
> On Tue, Feb 04, 2020 at 18:44:00 -0800, Mohammad Izadi wrote:
> > --- a/libavutil/hdr_dynamic_metadata.c
> > +++ b/libavutil/hdr_dynamic_metadata.c
> > @@ -1,4 +1,4 @@
> > -/**
> > + /**
>
> Please review your git diff and your submitted patches carefully. You
> need to avoid this accidental change.
>
reverted the change.

>
> > +if(!data)
>
> ffmpeg style: "if ("
>
Fixed.

>
> > +if(ret < 0)
> > +return AVERROR_INVALIDDATA;
>
> Ditto.
>
> Fixed.

> > +if (get_bits_left() < 2)
> > +return AVERROR_INVALIDDATA;
> > +s->num_windows = get_bits(, 2);
> > +
> > +if (s->num_windows < 1 || s->num_windows > 3) {
> > +return AVERROR_INVALIDDATA;
> > +}
>
> Above, you skip the brackets for the one-liner return. Here, you use
> them. That's inconsistent.
>
> Fixed.

> > --- a/libavutil/hdr_dynamic_metadata.h
> > +++ b/libavutil/hdr_dynamic_metadata.h
> > @@ -23,6 +23,8 @@
> >
> >  #include "frame.h"
> >  #include "rational.h"
> > +#include "libavcodec/get_bits.h"
> > +#include "libavcodec/put_bits.h"
>
> As the header doesn't use functions from these, but the implementation
> does, they should be in libavutil/hdr_dynamic_metadata.c instead.
>
Right. Changed.

>
> >  /**
> >   * The nominal maximum display luminance of the targeted system
> display,
> > - * in units of 0.0001 candelas per square metre. The value shall be
> in
> > + * in units of 1 candelas per square metre. The value shall be in
> >   * the range of 0 to 1, inclusive.
> >   */
>
> This fix is probably not strictly related to your change?
>
Right. I have changed ffmpeg locally to pass through HDR10+ in ffmpeg. I
have to split my changes to smaller CLs for review. So, some changes like
this may not strictly related, but required for my next changes. Here, the
comment explanation needs correction anyway.

>
> Cheers,
> Moritz
> ___
> 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] Update HDR10+ metadata structure.

2020-02-04 Thread Mohammad Izadi
From: Mohammad Izadi 

Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side data in 
the follow-up CLs.
---
 libavutil/hdr_dynamic_metadata.c | 167 ++-
 libavutil/hdr_dynamic_metadata.h |  14 ++-
 libavutil/version.h  |   2 +-
 3 files changed, 180 insertions(+), 3 deletions(-)

diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c
index 0fa1ee82de..fbab192c62 100644
--- a/libavutil/hdr_dynamic_metadata.c
+++ b/libavutil/hdr_dynamic_metadata.c
@@ -1,4 +1,4 @@
-/**
+ /**
  * Copyright (c) 2018 Mohammad Izadi 
  *
  * This file is part of FFmpeg.
@@ -21,6 +21,14 @@
 #include "hdr_dynamic_metadata.h"
 #include "mem.h"
 
+static const int64_t luminance_den = 1;
+static const int32_t peak_luminance_den = 15;
+static const int64_t rgb_den = 10;
+static const int32_t fraction_pixel_den = 1000;
+static const int32_t knee_point_den = 4095;
+static const int32_t bezier_anchor_den = 1023;
+static const int32_t saturation_weight_den = 8;
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 {
 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
@@ -45,3 +53,160 @@ AVDynamicHDRPlus 
*av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 
 return (AVDynamicHDRPlus *)side_data->data;
 }
+
+int av_dynamic_hdr_plus_decode(const uint8_t *data, size_t size,
+  AVDynamicHDRPlus *s)
+{
+int w, i, j;
+GetBitContext gb;
+if(!data)
+return AVERROR_INVALIDDATA;
+
+int ret = init_get_bits8(, data, size);
+if(ret < 0)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left() < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(, 2);
+
+if (s->num_windows < 1 || s->num_windows > 3) {
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left() < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(, 16);
+s->params[w].center_of_ellipse_y = get_bits(, 16);
+s->params[w].rotation_angle = get_bits(, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(, 16);
+s->params[w].overlap_process_option = get_bits1();
+}
+
+if (get_bits_left() < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits1();
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left() < 10)
+return AVERROR(EINVAL);
+rows = get_bits(, 5);
+cols = get_bits(, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left() < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left() < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(, 4);
+
+if (get_bits_left() <
+

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-03 Thread Mohammad Izadi
Great! Thanks!

On Mon, Feb 3, 2020, 6:37 PM James Almer  wrote:

> On 2/3/2020 11:01 PM, Mohammad Izadi wrote:
> > James, I am making another CL to comply with API.
> > I have a question about using GetBitContext and PutBitContext. Is there
> any
> > alternative to use in libavutil?
>
> You can use it in libavutil as long as it's not part of the public API.
> So you should make the new public functions take size_t and uint8_t*
> parameters, then use get/putbits internally in the implementation if
> needed.
>
> Also, all public functions must use an av_ prefix.
>
> > --
> > Best,
> > Mohammad
> >
> >
> > On Mon, Jan 27, 2020 at 11:50 AM James Almer  wrote:
> >
> >> On 1/27/2020 4:08 PM, Mohammad Izadi wrote:
> >>> From: Mohammad Izadi 
> >>>
> >>> Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> >> data in the follow-up CLs.
> >>> ---
> >>>  libavutil/hdr_dynamic_metadata.c | 386 +++
> >>>  libavutil/hdr_dynamic_metadata.h |  51 +++-
> >>>  libavutil/version.h  |   2 +-
> >>>  3 files changed, 431 insertions(+), 8 deletions(-)
> >>>
> >>> diff --git a/libavutil/hdr_dynamic_metadata.c
> >> b/libavutil/hdr_dynamic_metadata.c
> >>> index 0fa1ee82de..e321a22af8 100644
> >>> --- a/libavutil/hdr_dynamic_metadata.c
> >>> +++ b/libavutil/hdr_dynamic_metadata.c
> >>> @@ -21,6 +21,19 @@
> >>>  #include "hdr_dynamic_metadata.h"
> >>>  #include "mem.h"
> >>>
> >>> +static const uint8_t usa_country_code = 0xB5;
> >>> +static const uint16_t smpte_provider_code = 0x003C;
> >>> +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> >>> +static const uint16_t smpte2094_40_application_identifier = 0x04;
> >>> +
> >>> +static const int64_t luminance_den = 1;
> >>> +static const int32_t peak_luminance_den = 15;
> >>> +static const int64_t rgb_den = 10;
> >>> +static const int32_t fraction_pixel_den = 1000;
> >>> +static const int32_t knee_point_den = 4095;
> >>> +static const int32_t bezier_anchor_den = 1023;
> >>> +static const int32_t saturation_weight_den = 8;
> >>> +
> >>>  AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
> >>>  {
> >>>  AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
> >>> @@ -33,6 +46,48 @@ AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t
> >> *size)
> >>>  return hdr_plus;
> >>>  }
> >>>
> >>> +AVDynamicHDRPlus *av_dynamic_hdr_plus(GetBitContext *gb, size_t *size)
> >>> +{
> >>> +uint8_t country_code;
> >>> +uint16_t provider_code;
> >>> +uint16_t provider_oriented_code;
> >>> +uint8_t application_identifier;
> >>> +uint8_t application_version;
> >>> +AVDynamicHDRPlus *hdr_plus;
> >>> +int err;
> >>> +
> >>> +if (get_bits_left(gb) < 7)
> >>> +return NULL;
> >>> +
> >>> +country_code = get_bits(gb, 8);
> >>> +provider_code = get_bits(gb, 16);
> >>> +
> >>> +if (country_code != usa_country_code ||
> >>> +provider_code != smpte_provider_code)
> >>> +return NULL;
> >>> +
> >>> +// A/341 Amendment – 2094-40
> >>> +provider_oriented_code = get_bits(gb, 16);
> >>> +application_identifier = get_bits(gb, 8);
> >>> +application_version  = get_bits(gb, 8);
> >>> +if (provider_oriented_code != smpte2094_40_provider_oriented_code
> ||
> >>> +application_identifier != smpte2094_40_application_identifier)
> >>> +return NULL;
> >>> +
> >>> +hdr_plus = av_dynamic_hdr_plus_alloc(size);
> >>> +if (!hdr_plus)
> >>> +return NULL;
> >>> +
> >>> +hdr_plus->application_version = application_version;
> >>> +err = decode_itu_t_t35_to_dynamic_hdr_plus(gb, hdr_plus);
> >>> +if (err < 0) {
> >>> +av_freep(_plus);
> >>> +return NULL;
> >>> +}
> >>> +
> >>> +return hdr_plus;
> >>> +}
> >>> +
> >>>  AVDynamicHDRPlus *av_dynamic_hdr_plus

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-02-03 Thread Mohammad Izadi
James, I am making another CL to comply with API.
I have a question about using GetBitContext and PutBitContext. Is there any
alternative to use in libavutil?
--
Best,
Mohammad


On Mon, Jan 27, 2020 at 11:50 AM James Almer  wrote:

> On 1/27/2020 4:08 PM, Mohammad Izadi wrote:
> > From: Mohammad Izadi 
> >
> > Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side
> data in the follow-up CLs.
> > ---
> >  libavutil/hdr_dynamic_metadata.c | 386 +++
> >  libavutil/hdr_dynamic_metadata.h |  51 +++-
> >  libavutil/version.h  |   2 +-
> >  3 files changed, 431 insertions(+), 8 deletions(-)
> >
> > diff --git a/libavutil/hdr_dynamic_metadata.c
> b/libavutil/hdr_dynamic_metadata.c
> > index 0fa1ee82de..e321a22af8 100644
> > --- a/libavutil/hdr_dynamic_metadata.c
> > +++ b/libavutil/hdr_dynamic_metadata.c
> > @@ -21,6 +21,19 @@
> >  #include "hdr_dynamic_metadata.h"
> >  #include "mem.h"
> >
> > +static const uint8_t usa_country_code = 0xB5;
> > +static const uint16_t smpte_provider_code = 0x003C;
> > +static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > +static const uint16_t smpte2094_40_application_identifier = 0x04;
> > +
> > +static const int64_t luminance_den = 1;
> > +static const int32_t peak_luminance_den = 15;
> > +static const int64_t rgb_den = 10;
> > +static const int32_t fraction_pixel_den = 1000;
> > +static const int32_t knee_point_den = 4095;
> > +static const int32_t bezier_anchor_den = 1023;
> > +static const int32_t saturation_weight_den = 8;
> > +
> >  AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
> >  {
> >  AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
> > @@ -33,6 +46,48 @@ AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t
> *size)
> >  return hdr_plus;
> >  }
> >
> > +AVDynamicHDRPlus *av_dynamic_hdr_plus(GetBitContext *gb, size_t *size)
> > +{
> > +uint8_t country_code;
> > +uint16_t provider_code;
> > +uint16_t provider_oriented_code;
> > +uint8_t application_identifier;
> > +uint8_t application_version;
> > +AVDynamicHDRPlus *hdr_plus;
> > +int err;
> > +
> > +if (get_bits_left(gb) < 7)
> > +return NULL;
> > +
> > +country_code = get_bits(gb, 8);
> > +provider_code = get_bits(gb, 16);
> > +
> > +if (country_code != usa_country_code ||
> > +provider_code != smpte_provider_code)
> > +return NULL;
> > +
> > +// A/341 Amendment – 2094-40
> > +provider_oriented_code = get_bits(gb, 16);
> > +application_identifier = get_bits(gb, 8);
> > +application_version  = get_bits(gb, 8);
> > +if (provider_oriented_code != smpte2094_40_provider_oriented_code ||
> > +application_identifier != smpte2094_40_application_identifier)
> > +return NULL;
> > +
> > +hdr_plus = av_dynamic_hdr_plus_alloc(size);
> > +if (!hdr_plus)
> > +return NULL;
> > +
> > +hdr_plus->application_version = application_version;
> > +err = decode_itu_t_t35_to_dynamic_hdr_plus(gb, hdr_plus);
> > +if (err < 0) {
> > +av_freep(_plus);
> > +return NULL;
> > +}
> > +
> > +return hdr_plus;
> > +}
> > +
> >  AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
> >  {
> >  AVFrameSideData *side_data = av_frame_new_side_data(frame,
> > @@ -43,5 +98,336 @@ AVDynamicHDRPlus
> *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
> >
> >  memset(side_data->data, 0, sizeof(AVDynamicHDRPlus));
> >
> > +
> >  return (AVDynamicHDRPlus *)side_data->data;
> >  }
> > +
> > +int decode_itu_t_t35_to_dynamic_hdr_plus(GetBitContext *gb,
> AVDynamicHDRPlus *s)
> > +{
> > +int w, i, j;
> > +
> > +if (get_bits_left(gb) < 2)
> > +return AVERROR_INVALIDDATA;
> > +s->num_windows = get_bits(gb, 2);
> > +
> > +if (s->num_windows < 1 || s->num_windows > 3) {
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
> > +return AVERROR_INVALIDDATA;
> > +for (w = 1; w < s->num_windows; w++) {
> > +s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
> > +s->params[w].window_upper_left_corner_y.num = get_bits(gb,

Re: [FFmpeg-devel] [PATCH] Update HDR10+ metadata structure.

2020-01-27 Thread Mohammad Izadi
Hey Carl,

I created this metadata 6 months ago to use it at YouTube. The metadata is
incomplete here. I already implemented HDR10+ for our local ffmpeg and
trying to push them to the head.
Please note that the current code of HDR10+ is not working.

On Mon, Jan 27, 2020, 11:44 AM Carl Eugen Hoyos  wrote:

> Am Mo., 27. Jan. 2020 um 20:34 Uhr schrieb Mohammad Izadi <
> moh.iz...@gmail.com>:
>
> >  /**
> >   * Allocate an AVDynamicHDRPlus structure and set its fields to
> >   * default values. The resulting struct can be freed using av_freep().
> > + * @param gb The input bit stream.
> > + * @param size The size of allocated memory for the returned
> > + *AVDynamicHDRPlus structure.
> >   *
> >   * @return An AVDynamicHDRPlus filled with default values or NULL
> >   * on failure.
> >   */
> > -AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size);
> > +AVDynamicHDRPlus *av_dynamic_hdr_plus(GetBitContext *gb, size_t *size);
>
> This is a public function in an installed header: You cannot simply change
> or remove it.
>
> Carl Eugen
> ___
> 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] Update HDR10+ metadata structure.

2020-01-27 Thread Mohammad Izadi
From: Mohammad Izadi 

Trying to read HDR10+ metadata from HEVC/SEI and pass it to packet side data in 
the follow-up CLs.
---
 libavutil/hdr_dynamic_metadata.c | 386 +++
 libavutil/hdr_dynamic_metadata.h |  51 +++-
 libavutil/version.h  |   2 +-
 3 files changed, 431 insertions(+), 8 deletions(-)

diff --git a/libavutil/hdr_dynamic_metadata.c b/libavutil/hdr_dynamic_metadata.c
index 0fa1ee82de..e321a22af8 100644
--- a/libavutil/hdr_dynamic_metadata.c
+++ b/libavutil/hdr_dynamic_metadata.c
@@ -21,6 +21,19 @@
 #include "hdr_dynamic_metadata.h"
 #include "mem.h"
 
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
+
+static const int64_t luminance_den = 1;
+static const int32_t peak_luminance_den = 15;
+static const int64_t rgb_den = 10;
+static const int32_t fraction_pixel_den = 1000;
+static const int32_t knee_point_den = 4095;
+static const int32_t bezier_anchor_den = 1023;
+static const int32_t saturation_weight_den = 8;
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 {
 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
@@ -33,6 +46,48 @@ AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
 return hdr_plus;
 }
 
+AVDynamicHDRPlus *av_dynamic_hdr_plus(GetBitContext *gb, size_t *size)
+{
+uint8_t country_code;
+uint16_t provider_code;
+uint16_t provider_oriented_code;
+uint8_t application_identifier;
+uint8_t application_version;
+AVDynamicHDRPlus *hdr_plus;
+int err;
+
+if (get_bits_left(gb) < 7)
+return NULL;
+
+country_code = get_bits(gb, 8);
+provider_code = get_bits(gb, 16);
+
+if (country_code != usa_country_code ||
+provider_code != smpte_provider_code)
+return NULL;
+
+// A/341 Amendment – 2094-40
+provider_oriented_code = get_bits(gb, 16);
+application_identifier = get_bits(gb, 8);
+application_version  = get_bits(gb, 8);
+if (provider_oriented_code != smpte2094_40_provider_oriented_code ||
+application_identifier != smpte2094_40_application_identifier)
+return NULL;
+
+hdr_plus = av_dynamic_hdr_plus_alloc(size);
+if (!hdr_plus)
+return NULL;
+
+hdr_plus->application_version = application_version;
+err = decode_itu_t_t35_to_dynamic_hdr_plus(gb, hdr_plus);
+if (err < 0) {
+av_freep(_plus);
+return NULL;
+}
+
+return hdr_plus;
+}
+
 AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 {
 AVFrameSideData *side_data = av_frame_new_side_data(frame,
@@ -43,5 +98,336 @@ AVDynamicHDRPlus 
*av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
 
 memset(side_data->data, 0, sizeof(AVDynamicHDRPlus));
 
+
 return (AVDynamicHDRPlus *)side_data->data;
 }
+
+int decode_itu_t_t35_to_dynamic_hdr_plus(GetBitContext *gb, AVDynamicHDRPlus 
*s)
+{
+int w, i, j;
+
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(gb, 2);
+
+if (s->num_windows < 1 || s->num_windows > 3) {
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits1(gb);
+}
+
+if (get_bits_left(gb) < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
+
+   

[FFmpeg-devel] [PATCH] Support HDR dynamic metadata (HDR10+) in HEVC decoder.

2019-01-22 Thread Mohammad Izadi
---
 libavcodec/hevc_sei.c | 216 --
 libavcodec/hevc_sei.h |   6 ++
 libavcodec/hevcdec.c  |  21 
 3 files changed, 237 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..15cd956e85 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -206,10 +207,184 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
-static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
+static int decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s, 
GetBitContext *gb,
+void *logctx, int size)
+{
+const int luminance_den = 1;
+const int peak_luminance_den = 15;
+const int rgb_den = 10;
+const int fraction_pixel_den = 1000;
+const int knee_point_den = 4095;
+const int bezier_anchor_den = 1023;
+const int saturation_weight_den = 8;
+
+int w, i, j;
+
+if (get_bits_left(gb) < size * 8)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(gb, 2);
+if (s->num_windows < 1 || s->num_windows > 3) {
+av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1, 3]\n",
+   s->num_windows);
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits(gb, 1);
+}
+
+if (get_bits_left(gb) < 28)
+return AVERROR(EINVAL);
+
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits(gb, 1);
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left(gb) < 10)
+return AVERROR(EINVAL);
+rows = get_bits(gb, 5);
+cols = get_bits(gb, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
+av_log(logctx, AV_LOG_ERROR, "num_rows=%d, num_cols=%d, they must 
[2, 25] for targeted_system_display_actual_peak_luminance\n", rows, cols);
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left(gb) < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(gb, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left(gb) < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(gb, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(gb, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(gb, 4);
+
+if (get_bits_left(gb) <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))
+return AVERROR(EINVAL);
+for (i = 0; i < 

[FFmpeg-devel] [PATCH] Support HDR dynamic metadata (HDR10+) in HEVC decoder.

2019-01-22 Thread Mohammad Izadi
---
 libavcodec/hevc_sei.c | 216 --
 libavcodec/hevc_sei.h |   6 ++
 libavcodec/hevcdec.c  |  21 
 3 files changed, 237 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..15cd956e85 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -206,10 +207,184 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
-static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
+static int decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s, 
GetBitContext *gb,
+void *logctx, int size)
+{
+const int luminance_den = 1;
+const int peak_luminance_den = 15;
+const int rgb_den = 10;
+const int fraction_pixel_den = 1000;
+const int knee_point_den = 4095;
+const int bezier_anchor_den = 1023;
+const int saturation_weight_den = 8;
+
+int w, i, j;
+
+if (get_bits_left(gb) < size * 8)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(gb, 2);
+if (s->num_windows < 1 || s->num_windows > 3) {
+av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1, 3]\n",
+   s->num_windows);
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits(gb, 1);
+}
+
+if (get_bits_left(gb) < 28)
+return AVERROR(EINVAL);
+
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits(gb, 1);
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left(gb) < 10)
+return AVERROR(EINVAL);
+rows = get_bits(gb, 5);
+cols = get_bits(gb, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
+av_log(logctx, AV_LOG_ERROR, "num_rows=%d, num_cols=%d, they must 
[2, 25] for targeted_system_display_actual_peak_luminance\n", rows, cols);
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left(gb) < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(gb, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left(gb) < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(gb, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(gb, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(gb, 4);
+
+if (get_bits_left(gb) <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))
+return AVERROR(EINVAL);
+for (i = 0; i < 

[FFmpeg-devel] [PATCH] Support HDR dynamic metadata (HDR10+) in HEVC decoder.

2019-01-22 Thread Mohammad Izadi
---
 libavcodec/hevc_sei.c | 211 --
 libavcodec/hevc_sei.h |   6 ++
 libavcodec/hevcdec.c  |  22 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..6edec9f0db 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -206,10 +207,179 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
-static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
+static int decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s, 
GetBitContext *gb,
+void *logctx, int size)
+{
+const int luminance_den = 1;
+const int peak_luminance_den = 15;
+const int rgb_den = 10;
+const int fraction_pixel_den = 1000;
+const int knee_point_den = 4095;
+const int bezier_anchor_den = 1023;
+const int saturation_weight_den = 8;
+
+int w, i, j;
+
+if (get_bits_left(gb) < size * 8)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(gb, 2);
+if (s->num_windows < 1 || s->num_windows > 3) {
+av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1, 3]\n",
+   s->num_windows);
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits(gb, 1);
+}
+
+if (get_bits_left(gb) < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits(gb, 1);
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left(gb) < 10)
+return AVERROR(EINVAL);
+rows = get_bits(gb, 5);
+cols = get_bits(gb, 5);
+if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
+av_log(logctx, AV_LOG_ERROR, "num_rows=%d, num_cols=%d, they must 
[2, 25] for targeted_system_display_actual_peak_luminance\n", rows, cols);
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left(gb) < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(gb, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left(gb) < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(gb, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(gb, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(gb, 4);
+
+if (get_bits_left(gb) <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))
+return AVERROR(EINVAL);
+for (i = 0; i < 

[FFmpeg-devel] [PATCH] Support HDR dynamic metdata (HDR10+) in HEVC decoder.

2019-01-16 Thread Mohammad Izadi
---
 libavcodec/hevc_sei.c | 211 --
 libavcodec/hevc_sei.h |   6 ++
 libavcodec/hevcdec.c  |  22 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..265e3f4dd1 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -206,10 +207,179 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
-static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
+static int decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s, 
GetBitContext *gb,
+void *logctx, int size)
+{
+const int luminance_den = 1;
+const int peak_luminance_den = 15;
+const int rgb_den = 10;
+const int fraction_pixel_den = 1000;
+const int knee_point_den = 4095;
+const int bezier_anchor_den = 1023;
+const int saturation_weight_den = 8;
+
+int w, i, j;
+
+if (get_bits_left(gb) < size * 8)
+return AVERROR_INVALIDDATA;
+
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
+s->num_windows = get_bits(gb, 2);
+if (s->num_windows < 1 || s->num_windows > 3) {
+av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1, 3]\n",
+   s->num_windows);
+return AVERROR_INVALIDDATA;
+}
+
+if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR_INVALIDDATA;
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits(gb, 1);
+}
+
+if (get_bits_left(gb) < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits(gb, 1);
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (get_bits_left(gb) < 10)
+return AVERROR(EINVAL);
+rows = get_bits(gb, 5);
+cols = get_bits(gb, 5);
+if (((rows < 2) && (rows > 25)) || ((cols < 2) && (cols > 25))) {
+av_log(logctx, AV_LOG_ERROR, "num_rows=%d, num_cols=%d, they must 
[2, 25] for targeted_system_display_actual_peak_luminance\n", rows, cols);
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+
+if (get_bits_left(gb) < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num = 
get_bits(gb, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den = 
peak_luminance_den;
+}
+}
+}
+for (w = 0; w < s->num_windows; w++) {
+if (get_bits_left(gb) < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(gb, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(gb, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(gb, 4);
+
+if (get_bits_left(gb) <
+(s->params[w].num_distribution_maxrgb_percentiles * 24))
+return AVERROR(EINVAL);
+for (i = 0; i < 

Re: [FFmpeg-devel] [PATCH] Support HDR dynamic metdata (HDR10+) in HEVC decoder.

2019-01-15 Thread Mohammad Izadi
Asking my questions again:

Q(James): Does this mean each frame can potentially have a few different
parameters if dimensions change between them? If that's the case, then
creating new references for the same buffer will not be possible, as the
buffer becomes non writable once there's more than one reference.
A: The window has absolute coordinates and if the frame scaled by a filter,
the coordinates would be invalid. So if we convert it to relative
coordinate, it would be valid fora scaled frame and we can easily converted
to the right absolute values in the encoder.
Yes, we can set it in hevc_sei, but we need to pass w/h down there.

Q(Rstislav):Can't these be set during NAL unit parsing? Or can the frame
size change
with the hdr data remaining valid for future frames.
A: As the buffer become non writable, we may set it in SEI reader. But we
need to pass w/h down there and have to some changes in hevc_parser as well.


Q(Rstislav): Does ff_hevc_reset_sei get called during uninit?
If it doesn't, you'll need to unref it again in the uninit function.
A: what uninit function do you refer exactly? I did not find it.




--
Best,
Mohammad


On Tue, Jan 8, 2019 at 12:58 PM Mohammad Izadi  wrote:

> Q(James): Does this mean each frame can potentially have a few different
> parameters if dimensions change between them? If that's the case, then
> creating new references for the same buffer will not be possible, as the
> buffer becomes non writable once there's more than one reference.
> A: The window has absolute coordinates and if the frame scaled by a
> filter, the coordinates would be invalid. So if we convert it to relative
> coordinate, it would be valid fora scaled frame and we can easily converted
> to the right absolute values in the encoder.
> Yes, we can set it in hevc_sei, but we need to pass w/h down there.
>
> Q(Rstislav):Can't these be set during NAL unit parsing? Or can the frame
> size change
> with the hdr data remaining valid for future frames.
> A: As the buffer become non writable, we may set it in SEI reader. But we
> need to pass w/h down there and have to some changes in hevc_parser as well.
>
>
> Q(Rstislav): Does ff_hevc_reset_sei get called during uninit?
> If it doesn't, you'll need to unref it again in the uninit function.
> A: what uninit function do you refer exactly? I did not find it.
>
>
>
> --
> Best,
> Mohammad
>
>
> On Mon, Jan 7, 2019 at 5:19 PM James Almer  wrote:
>
>> On 1/7/2019 8:55 PM, Mohammad Izadi wrote:
>> > ---
>> >  libavcodec/hevc_sei.c | 236 --
>> >  libavcodec/hevc_sei.h |   6 ++
>> >  libavcodec/hevcdec.c  |  19 
>> >  3 files changed, 255 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
>> > index c59bd4321e..7e59bf0813 100644
>> > --- a/libavcodec/hevc_sei.c
>> > +++ b/libavcodec/hevc_sei.c
>> > @@ -25,6 +25,7 @@
>> >  #include "golomb.h"
>> >  #include "hevc_ps.h"
>> >  #include "hevc_sei.h"
>> > +#include "libavutil/hdr_dynamic_metadata.h"
>> >
>> >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
>> GetBitContext *gb)
>> >  {
>> > @@ -206,10 +207,205 @@ static int
>> decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
>> >  return 0;
>> >  }
>> >
>> > -static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
>> GetBitContext *gb,
>> > +static int
>> decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s,
>> GetBitContext *gb,
>> > +void *logctx,
>> int size)
>> > +{
>> > +const int luminance_den = 1;
>> > +const int peak_luminance_den = 15;
>> > +const int rgb_den = 10;
>> > +const int fraction_pixel_den = 1000;
>> > +const int knee_point_den = 4095;
>> > +const int bezier_anchor_den = 1023;
>> > +const int saturation_weight_den = 8;
>> > +
>> > +int bits_left = size * 8;
>> > +int w, i, j;
>> > +
>> > +if (bits_left < 2)
>> > +return AVERROR_INVALIDDATA;
>> > +
>> > +s->num_windows = get_bits(gb, 2);
>> > +bits_left -= 2;
>> > +if (s->num_windows < 1 || s->num_windows > 3) {
>> > +av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1,
>> 3]\n",
>> > +   s->num_windows);
>> > +return AVERROR_INVALIDDATA;
>> > +}
>&g

Re: [FFmpeg-devel] [PATCH] Support HDR dynamic metdata (HDR10+) in HEVC decoder.

2019-01-08 Thread Mohammad Izadi
Q(James): Does this mean each frame can potentially have a few different
parameters if dimensions change between them? If that's the case, then
creating new references for the same buffer will not be possible, as the
buffer becomes non writable once there's more than one reference.
A: The window has absolute coordinates and if the frame scaled by a filter,
the coordinates would be invalid. So if we convert it to relative
coordinate, it would be valid fora scaled frame and we can easily converted
to the right absolute values in the encoder.
Yes, we can set it in hevc_sei, but we need to pass w/h down there.

Q(Rstislav):Can't these be set during NAL unit parsing? Or can the frame
size change
with the hdr data remaining valid for future frames.
A: As the buffer become non writable, we may set it in SEI reader. But we
need to pass w/h down there and have to some changes in hevc_parser as well.


Q(Rstislav): Does ff_hevc_reset_sei get called during uninit?
If it doesn't, you'll need to unref it again in the uninit function.
A: what uninit function do you refer exactly? I did not find it.



--
Best,
Mohammad


On Mon, Jan 7, 2019 at 5:19 PM James Almer  wrote:

> On 1/7/2019 8:55 PM, Mohammad Izadi wrote:
> > ---
> >  libavcodec/hevc_sei.c | 236 --
> >  libavcodec/hevc_sei.h |   6 ++
> >  libavcodec/hevcdec.c  |  19 
> >  3 files changed, 255 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index c59bd4321e..7e59bf0813 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -25,6 +25,7 @@
> >  #include "golomb.h"
> >  #include "hevc_ps.h"
> >  #include "hevc_sei.h"
> > +#include "libavutil/hdr_dynamic_metadata.h"
> >
> >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
> GetBitContext *gb)
> >  {
> > @@ -206,10 +207,205 @@ static int
> decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
> >  return 0;
> >  }
> >
> > -static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> GetBitContext *gb,
> > +static int
> decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s,
> GetBitContext *gb,
> > +void *logctx,
> int size)
> > +{
> > +const int luminance_den = 1;
> > +const int peak_luminance_den = 15;
> > +const int rgb_den = 10;
> > +const int fraction_pixel_den = 1000;
> > +const int knee_point_den = 4095;
> > +const int bezier_anchor_den = 1023;
> > +const int saturation_weight_den = 8;
> > +
> > +int bits_left = size * 8;
> > +int w, i, j;
> > +
> > +if (bits_left < 2)
> > +return AVERROR_INVALIDDATA;
> > +
> > +s->num_windows = get_bits(gb, 2);
> > +bits_left -= 2;
> > +if (s->num_windows < 1 || s->num_windows > 3) {
> > +av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1,
> 3]\n",
> > +   s->num_windows);
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +if (bits_left < ((19 * 8 + 1) * (s->num_windows - 1)))
> > +return AVERROR(EINVAL);
>
> AVERROR_INVALIDDATA for invalid bistreams, AVERROR(EINVAL) for invalid
> user arguments.
>
> > +for (w = 1; w < s->num_windows; w++) {
> > +s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
> > +s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
> > +s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
> > +s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
> > +// The corners are set to absolute coordinates here. They
> should be
> > +// converted to the relative coordinates (in [0, 1]) in the
> decoder.
> > +s->params[w].window_upper_left_corner_x.den = 1;
> > +s->params[w].window_upper_left_corner_y.den = 1;
> > +s->params[w].window_lower_right_corner_x.den = 1;
> > +s->params[w].window_lower_right_corner_y.den = 1;
> > +
> > +s->params[w].center_of_ellipse_x = get_bits(gb, 16);
> > +s->params[w].center_of_ellipse_y = get_bits(gb, 16);
> > +s->params[w].rotation_angle = get_bits(gb, 8);
> > +s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
> > +s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
> > +s->params[w].semiminor_axis_external_el

[FFmpeg-devel] [PATCH] Support HDR dynamic metdata (HDR10+) in HEVC decoder.

2019-01-07 Thread Mohammad Izadi
---
 libavcodec/hevc_sei.c | 236 --
 libavcodec/hevc_sei.h |   6 ++
 libavcodec/hevcdec.c  |  19 
 3 files changed, 255 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..7e59bf0813 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -25,6 +25,7 @@
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, 
GetBitContext *gb)
 {
@@ -206,10 +207,205 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
-static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
+static int decode_registered_user_data_dynamic_hdr_plus(AVDynamicHDRPlus *s, 
GetBitContext *gb,
+void *logctx, int size)
+{
+const int luminance_den = 1;
+const int peak_luminance_den = 15;
+const int rgb_den = 10;
+const int fraction_pixel_den = 1000;
+const int knee_point_den = 4095;
+const int bezier_anchor_den = 1023;
+const int saturation_weight_den = 8;
+
+int bits_left = size * 8;
+int w, i, j;
+
+if (bits_left < 2)
+return AVERROR_INVALIDDATA;
+
+s->num_windows = get_bits(gb, 2);
+bits_left -= 2;
+if (s->num_windows < 1 || s->num_windows > 3) {
+av_log(logctx, AV_LOG_ERROR, "num_windows=%d, must be in [1, 3]\n",
+   s->num_windows);
+return AVERROR_INVALIDDATA;
+}
+
+if (bits_left < ((19 * 8 + 1) * (s->num_windows - 1)))
+return AVERROR(EINVAL);
+for (w = 1; w < s->num_windows; w++) {
+s->params[w].window_upper_left_corner_x.num = get_bits(gb, 16);
+s->params[w].window_upper_left_corner_y.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_x.num = get_bits(gb, 16);
+s->params[w].window_lower_right_corner_y.num = get_bits(gb, 16);
+// The corners are set to absolute coordinates here. They should be
+// converted to the relative coordinates (in [0, 1]) in the decoder.
+s->params[w].window_upper_left_corner_x.den = 1;
+s->params[w].window_upper_left_corner_y.den = 1;
+s->params[w].window_lower_right_corner_x.den = 1;
+s->params[w].window_lower_right_corner_y.den = 1;
+
+s->params[w].center_of_ellipse_x = get_bits(gb, 16);
+s->params[w].center_of_ellipse_y = get_bits(gb, 16);
+s->params[w].rotation_angle = get_bits(gb, 8);
+s->params[w].semimajor_axis_internal_ellipse = get_bits(gb, 16);
+s->params[w].semimajor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].semiminor_axis_external_ellipse = get_bits(gb, 16);
+s->params[w].overlap_process_option = get_bits(gb, 1);
+bits_left -= 19 * 8 + 1;
+}
+
+if (bits_left < 28)
+return AVERROR(EINVAL);
+s->targeted_system_display_maximum_luminance.num = get_bits(gb, 27);
+s->targeted_system_display_maximum_luminance.den = luminance_den;
+s->targeted_system_display_actual_peak_luminance_flag = get_bits(gb, 1);
+bits_left -= 28;
+
+if (s->targeted_system_display_actual_peak_luminance_flag) {
+int rows, cols;
+if (bits_left < 10)
+return AVERROR(EINVAL);
+rows = get_bits(gb, 5);
+cols = get_bits(gb, 5);
+if (((rows < 2) && (rows > 25)) || ((cols < 2) && (cols > 25))) {
+av_log(logctx, AV_LOG_ERROR, "num_rows=%d, num_cols=%d, they must "
+   "be in [2, 25] for "
+   "targeted_system_display_actual_peak_luminance\n",
+   rows, cols);
+return AVERROR_INVALIDDATA;
+}
+s->num_rows_targeted_system_display_actual_peak_luminance = rows;
+s->num_cols_targeted_system_display_actual_peak_luminance = cols;
+bits_left -= 10;
+
+if (bits_left < (rows * cols * 4))
+return AVERROR(EINVAL);
+
+for (i = 0; i < rows; i++) {
+for (j = 0; j < cols; j++) {
+s->targeted_system_display_actual_peak_luminance[i][j].num =
+get_bits(gb, 4);
+s->targeted_system_display_actual_peak_luminance[i][j].den =
+peak_luminance_den;
+}
+}
+bits_left -= (rows * cols * 4);
+}
+for (w = 0; w < s->num_windows; w++) {
+if (bits_left < (3 * 17 + 17 + 4))
+return AVERROR(EINVAL);
+for (i = 0; i < 3; i++) {
+s->params[w].maxscl[i].num = get_bits(gb, 17);
+s->params[w].maxscl[i].den = rgb_den;
+}
+s->params[w].average_maxrgb.num = get_bits(gb, 17);
+s->params[w].average_maxrgb.den = rgb_den;
+s->params[w].num_distribution_maxrgb_percentiles = get_bits(gb, 4);
+bits_left -= (3 * 17 + 17 + 

Re: [FFmpeg-devel] [PATCH 1/2] Support HDR dynamic metdata (HDR10+) in HEVC decoder.

2019-01-04 Thread Mohammad Izadi
Thanks James.
--
Best,
Mohammad


On Fri, Jan 4, 2019 at 3:03 PM James Almer  wrote:

> On 1/4/2019 7:51 PM, Rostislav Pehlivanov wrote:
> > On Fri, 4 Jan 2019 at 21:08, James Almer  wrote:
> >
> >> On 1/4/2019 3:53 PM, Rostislav Pehlivanov wrote:
> >>> On Fri, 4 Jan 2019 at 18:12, Mohammad Izadi 
> wrote:
> >>>
> >>>> You mean a pointer in HEVCSEIDynamicHDRPlus, not in
> HEVCSEIContentLight?
> >>>> --
> >>>> Best,
> >>>> Mohammad
> >>>>
> >>>>
> >>>> On Thu, Jan 3, 2019 at 5:08 PM Rostislav Pehlivanov <
> >> atomnu...@gmail.com>
> >>>> wrote:
> >>>>
> >>>>> On Thu, 3 Jan 2019 at 20:13, Mohammad Izadi 
> >> wrote:
> >>>>>
> >>>>>>
> >>>>>>  /**
> >>>>>> @@ -94,6 +95,50 @@ typedef struct HEVCSEIMasteringDisplay {
> >>>>>>  uint32_t min_luminance;
> >>>>>>  } HEVCSEIMasteringDisplay;
> >>>>>>
> >>>>>> +typedef struct HEVCSEIDynamicHDRPlus{
> >>>>>> +int present;
> >>>>>> +uint8_t itu_t_t35_country_code;
> >>>>>> +uint8_t application_version;
> >>>>>> +uint8_t num_windows;
> >>>>>> +struct {
> >>>>>> +AVRational window_upper_left_corner_x;
> >>>>>> +AVRational window_upper_left_corner_y;
> >>>>>> +AVRational window_lower_right_corner_x;
> >>>>>> +AVRational window_lower_right_corner_y;
> >>>>>> +uint16_t center_of_ellipse_x;
> >>>>>> +uint16_t center_of_ellipse_y;
> >>>>>> +uint8_t rotation_angle;
> >>>>>> +uint16_t semimajor_axis_internal_ellipse;
> >>>>>> +uint16_t semimajor_axis_external_ellipse;
> >>>>>> +uint16_t semiminor_axis_external_ellipse;
> >>>>>> +uint8_t overlap_process_option;
> >>>>>> +AVRational maxscl[3];
> >>>>>> +AVRational average_maxrgb;
> >>>>>> +uint8_t num_distribution_maxrgb_percentiles;
> >>>>>> +struct {
> >>>>>> +uint8_t percentage;
> >>>>>> +AVRational percentile;
> >>>>>> +} distribution_maxrgb[15];
> >>>>>> +AVRational fraction_bright_pixels;
> >>>>>> +uint8_t tone_mapping_flag;
> >>>>>> +AVRational knee_point_x;
> >>>>>> +AVRational knee_point_y;
> >>>>>> +uint8_t num_bezier_curve_anchors;
> >>>>>> +AVRational bezier_curve_anchors[15];
> >>>>>> +uint8_t color_saturation_mapping_flag;
> >>>>>> +AVRational color_saturation_weight;
> >>>>>> +} params[3];
> >>>>>> +AVRational targeted_system_display_maximum_luminance;
> >>>>>> +uint8_t targeted_system_display_actual_peak_luminance_flag;
> >>>>>> +uint8_t num_rows_targeted_system_display_actual_peak_luminance;
> >>>>>> +uint8_t num_cols_targeted_system_display_actual_peak_luminance;
> >>>>>> +AVRational
> targeted_system_display_actual_peak_luminance[25][25];
> >>>>>> +uint8_t mastering_display_actual_peak_luminance_flag;
> >>>>>> +uint8_t num_rows_mastering_display_actual_peak_luminance;
> >>>>>> +uint8_t num_cols_mastering_display_actual_peak_luminance;
> >>>>>> +AVRational mastering_display_actual_peak_luminance[25][25];
> >>>>>> +} HEVCSEIDynamicHDRPlus;
> >>>>>> +
> >>>>>>
> >>>>>
> >>>>> There's no reason to create a new struct for this if all you're going
> >> to
> >>>> do
> >>>>> is to copy it over and over to new frames.
> >>>>> What you can do is this: on every SEI containing this thing just
> >>>> allocate a
> >>>>> AVDynamicHDRPlus struct via av_dynamic_hdr_plus_alloc, wrap it as an
> >>>>> AVBufferRef via av_buffer_create, populate it, put it as a pointer in
> >>>>> HEVCSEIContentLi

  1   2   >