Nov 12, 2020, 19:07 by jamr...@gmail.com: > On 11/12/2020 2:42 PM, Lynne wrote: > >> + if (p->frame_hdr->film_grain.present && (!dav1d->apply_grain || >> + (c->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))) { >> + AVFilmGrainParams *fgp; >> + if (p->frame_hdr->film_grain.update) { >> > > You're not gaining anything by looking at this field. You're either > allocating a new buffer or making the existing one writable. There is no case > where it can be reused for more than one frame, so you'll be always > allocating stuff and copying data. > > Also, libdav1d already takes care of ensuring p->frame_hdr->film_grain > contains the correct values for every frame for us (It actually takes them > from the correct reference frame pointed by film_grain_params_ref_idx when > film_grain.update is false, whereas here you're always using the one from the > previous returned frame), so just use av_film_grain_params_create_side_data() > then copy the fields, like mastering and content level do above. >
Fair enough. Still saved a copy occasionally. v3 attached, does the same as all other side data.
>From bb803054dcca05a2f409247011cfb475affa6f36 Mon Sep 17 00:00:00 2001 From: Lynne <d...@lynne.ee> Date: Thu, 12 Nov 2020 12:48:20 +0100 Subject: [PATCH v3] libdav1d: use film grain export flag to export AVFilmGrainParams side data This patch is relatively straightforward with one exception: the decoder option flag. The option was introduced to troubleshoot but its existence is conflicting and redundant now that we have a codec-generic flag. Hence this patch deprecates it. The way it interacts with AV_CODEC_EXPORT_DATA_FILM_GRAIN is as follows: If filmgrain is unset and AV_CODEC_EXPORT_DATA_FILM_GRAIN is present, disable film grain application and export side data. If filmgrain is set to 0, disable film grain and export side data. If filmgrain is set to 1, apply film grain but export side data if the AV_CODEC_EXPORT_DATA_FILM_GRAIN flag is set. This may result in double film grain application, but the user has requested it by setting both. --- libavcodec/libdav1d.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 3af7ef4edc..21b10b6a30 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -22,6 +22,7 @@ #include <dav1d/dav1d.h> #include "libavutil/avassert.h" +#include "libavutil/film_grain_params.h" #include "libavutil/mastering_display_metadata.h" #include "libavutil/imgutils.h" #include "libavutil/opt.h" @@ -137,6 +138,8 @@ static av_cold int libdav1d_init(AVCodecContext *c) s.frame_size_limit = c->max_pixels; if (dav1d->apply_grain >= 0) s.apply_grain = dav1d->apply_grain; + else if (c->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) + s.apply_grain = 0; s.all_layers = dav1d->all_layers; if (dav1d->operating_point >= 0) @@ -395,6 +398,42 @@ FF_ENABLE_DEPRECATION_WARNINGS break; } } + if (p->frame_hdr->film_grain.present && (!dav1d->apply_grain || + (c->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))) { + AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); + if (!fgp) { + res = AVERROR(ENOMEM); + goto fail; + } + + fgp->type = AV_FILM_GRAM_PARAMS_AV1; + fgp->seed = p->frame_hdr->film_grain.data.seed; + fgp->limit_output_range = p->frame_hdr->film_grain.data.clip_to_restricted_range; + fgp->codec.aom.num_y_points = p->frame_hdr->film_grain.data.num_y_points; + fgp->codec.aom.chroma_scaling_from_luma = p->frame_hdr->film_grain.data.chroma_scaling_from_luma; + fgp->codec.aom.scaling_shift = p->frame_hdr->film_grain.data.scaling_shift; + fgp->codec.aom.ar_coeff_lag = p->frame_hdr->film_grain.data.ar_coeff_lag; + fgp->codec.aom.ar_coeff_shift = p->frame_hdr->film_grain.data.ar_coeff_shift; + fgp->codec.aom.grain_scale_shift = p->frame_hdr->film_grain.data.grain_scale_shift; + fgp->codec.aom.overlap_flag = p->frame_hdr->film_grain.data.overlap_flag; + + memcpy(&fgp->codec.aom.y_points, &p->frame_hdr->film_grain.data.y_points, + sizeof(fgp->codec.aom.y_points)); + memcpy(&fgp->codec.aom.num_uv_points, &p->frame_hdr->film_grain.data.num_uv_points, + sizeof(fgp->codec.aom.num_uv_points)); + memcpy(&fgp->codec.aom.uv_points, &p->frame_hdr->film_grain.data.uv_points, + sizeof(fgp->codec.aom.uv_points)); + memcpy(&fgp->codec.aom.ar_coeffs_y, &p->frame_hdr->film_grain.data.ar_coeffs_y, + sizeof(fgp->codec.aom.ar_coeffs_y)); + memcpy(&fgp->codec.aom.ar_coeffs_uv, &p->frame_hdr->film_grain.data.ar_coeffs_uv, + sizeof(fgp->codec.aom.ar_coeffs_uv)); + memcpy(&fgp->codec.aom.uv_mult, &p->frame_hdr->film_grain.data.uv_mult, + sizeof(fgp->codec.aom.uv_mult)); + memcpy(&fgp->codec.aom.uv_mult_luma, &p->frame_hdr->film_grain.data.uv_luma_mult, + sizeof(fgp->codec.aom.uv_mult_luma)); + memcpy(&fgp->codec.aom.uv_offset, &p->frame_hdr->film_grain.data.uv_offset, + sizeof(fgp->codec.aom.uv_offset)); + } res = 0; fail: @@ -420,7 +459,7 @@ static av_cold int libdav1d_close(AVCodecContext *c) static const AVOption libdav1d_options[] = { { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_TILE_THREADS, VD }, { "framethreads", "Frame threads", OFFSET(frame_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_THREADS, VD }, - { "filmgrain", "Apply Film Grain", OFFSET(apply_grain), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD }, + { "filmgrain", "Apply Film Grain", OFFSET(apply_grain), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD | AV_OPT_FLAG_DEPRECATED }, { "oppoint", "Select an operating point of the scalable bitstream", OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31, VD }, { "alllayers", "Output all spatial layers", OFFSET(all_layers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD }, { NULL } -- 2.29.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".