1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

lavc/*dec: use side data preference for mastering display/content light metadata

This commit is contained in:
Anton Khirnov 2024-02-23 10:21:54 +01:00
parent 588c5c3d51
commit 6169bd0fea
5 changed files with 166 additions and 128 deletions

View File

@ -999,10 +999,13 @@ static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
int ret = 0;
if (s->mdcv) {
AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
if (!mastering)
return AVERROR(ENOMEM);
AVMasteringDisplayMetadata *mastering;
ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
if (ret < 0)
return ret;
if (mastering) {
for (int i = 0; i < 3; i++) {
mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
@ -1016,15 +1019,20 @@ static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
mastering->has_primaries = 1;
mastering->has_luminance = 1;
}
}
if (s->cll) {
AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
if (!light)
return AVERROR(ENOMEM);
AVContentLightMetadata *light;
ret = ff_decode_content_light_new(avctx, frame, &light);
if (ret < 0)
return ret;
if (light) {
light->MaxCLL = s->cll->max_cll;
light->MaxFALL = s->cll->max_fall;
}
}
while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
if (ret >= 0)

View File

@ -35,6 +35,7 @@
#include "atsc_a53.h"
#include "avcodec.h"
#include "decode.h"
#include "dynamic_hdr_vivid.h"
#include "get_bits.h"
#include "golomb.h"
@ -515,6 +516,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
int seed)
{
H2645SEIFramePacking *fp = &sei->frame_packing;
int ret;
if (fp->present &&
is_frame_packing_type_valid(fp->arrangement_type, codec_id) &&
@ -710,11 +712,13 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
const int chroma_den = 50000;
const int luma_den = 10000;
int i;
AVMasteringDisplayMetadata *metadata =
av_mastering_display_metadata_create_side_data(frame);
if (!metadata)
return AVERROR(ENOMEM);
AVMasteringDisplayMetadata *metadata;
ret = ff_decode_mastering_display_new(avctx, frame, &metadata);
if (ret < 0)
return ret;
if (metadata) {
for (i = 0; i < 3; i++) {
const int j = mapping[i];
metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
@ -748,12 +752,16 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
"min_luminance=%f, max_luminance=%f\n",
av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
}
}
if (sei->content_light.present) {
AVContentLightMetadata *metadata =
av_content_light_metadata_create_side_data(frame);
if (!metadata)
return AVERROR(ENOMEM);
AVContentLightMetadata *metadata;
ret = ff_decode_content_light_new(avctx, frame, &metadata);
if (ret < 0)
return ret;
if (metadata) {
metadata->MaxCLL = sei->content_light.max_content_light_level;
metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
@ -761,6 +769,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
metadata->MaxCLL, metadata->MaxFALL);
}
}
return 0;
}

View File

@ -487,12 +487,13 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
}
if (p->mastering_display) {
AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
if (!mastering) {
res = AVERROR(ENOMEM);
goto fail;
}
AVMasteringDisplayMetadata *mastering;
res = ff_decode_mastering_display_new(c, frame, &mastering);
if (res < 0)
goto fail;
if (mastering) {
for (int i = 0; i < 3; i++) {
mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16);
mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16);
@ -506,15 +507,19 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
mastering->has_primaries = 1;
mastering->has_luminance = 1;
}
if (p->content_light) {
AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
if (!light) {
res = AVERROR(ENOMEM);
goto fail;
}
if (p->content_light) {
AVContentLightMetadata *light;
res = ff_decode_content_light_new(c, frame, &light);
if (res < 0)
goto fail;
if (light) {
light->MaxCLL = p->content_light->max_content_light_level;
light->MaxFALL = p->content_light->max_frame_average_light_level;
}
}
if (p->itut_t35) {
#if FF_DAV1D_VERSION_AT_LEAST(6,9)
for (size_t i = 0; i < p->n_itut_t35; i++) {

View File

@ -746,10 +746,13 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
avctx->bits_per_raw_sample = s->significant_bits;
if (s->have_clli) {
AVContentLightMetadata *clli =
av_content_light_metadata_create_side_data(frame);
if (!clli)
return AVERROR(ENOMEM);
AVContentLightMetadata *clli;
ret = ff_decode_content_light_new(avctx, frame, &clli);
if (ret < 0)
return ret;
if (clli) {
/*
* 0.0001 divisor value
* see: https://www.w3.org/TR/png-3/#cLLi-chunk
@ -757,12 +760,16 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
clli->MaxCLL = s->clli_max / 10000;
clli->MaxFALL = s->clli_avg / 10000;
}
}
if (s->have_mdvc) {
AVMasteringDisplayMetadata *mdvc =
av_mastering_display_metadata_create_side_data(frame);
if (!mdvc)
return AVERROR(ENOMEM);
AVMasteringDisplayMetadata *mdvc;
ret = ff_decode_mastering_display_new(avctx, frame, &mdvc);
if (ret < 0)
return ret;
if (mdvc) {
mdvc->has_primaries = 1;
for (int i = 0; i < 3; i++) {
mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000);
@ -774,6 +781,7 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000);
mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000);
}
}
return 0;
}

View File

@ -651,17 +651,21 @@ static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam
static int qsv_export_hdr_side_data(AVCodecContext *avctx, mfxExtMasteringDisplayColourVolume *mdcv,
mfxExtContentLightLevelInfo *clli, AVFrame *frame)
{
int ret;
// The SDK re-uses this flag for HDR SEI parsing
if (mdcv->InsertPayloadToggle) {
AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
AVMasteringDisplayMetadata *mastering;
const int mapping[3] = {2, 0, 1};
const int chroma_den = 50000;
const int luma_den = 10000;
int i;
if (!mastering)
return AVERROR(ENOMEM);
ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
if (ret < 0)
return ret;
if (mastering) {
for (i = 0; i < 3; i++) {
const int j = mapping[i];
mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den);
@ -677,17 +681,21 @@ static int qsv_export_hdr_side_data(AVCodecContext *avctx, mfxExtMasteringDispla
mastering->has_luminance = 1;
mastering->has_primaries = 1;
}
}
// The SDK re-uses this flag for HDR SEI parsing
if (clli->InsertPayloadToggle) {
AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
AVContentLightMetadata *light;
if (!light)
return AVERROR(ENOMEM);
ret = ff_decode_content_light_new(avctx, frame, &light);
if (ret < 0)
return ret;
if (light) {
light->MaxCLL = clli->MaxContentLightLevel;
light->MaxFALL = clli->MaxPicAverageLightLevel;
}
}
return 0;
}