From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PoC][PATCH 08/14] avutil/frame: add a param change side data type Date: Wed, 29 Jan 2025 10:53:24 -0300 Message-ID: <92af91b2-cbfe-4ea5-834d-95fa8cf7381e@gmail.com> (raw) In-Reply-To: <DU0P250MB0747D8F877371619FCE912A08FEE2@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> [-- Attachment #1.1.1: Type: text/plain, Size: 5420 bytes --] On 1/29/2025 9:29 AM, Andreas Rheinhardt wrote: > James Almer: >> Similar in purpose as the packet side data of the same name, but for encoders. >> >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> An example of RefCount used for side data, including a copy and uninit callback >> to handle allocations within the entry. >> >> libavutil/frame.h | 14 ++++++++++++++ >> libavutil/side_data.c | 23 +++++++++++++++++++++++ >> 2 files changed, 37 insertions(+) >> >> diff --git a/libavutil/frame.h b/libavutil/frame.h >> index 1feb11506a..c677407781 100644 >> --- a/libavutil/frame.h >> +++ b/libavutil/frame.h >> @@ -243,8 +243,22 @@ enum AVFrameSideDataType { >> * The data is an int storing the view ID. >> */ >> AV_FRAME_DATA_VIEW_ID, >> + >> + /** >> + * A side data used to signal an encoder that certain parameters changed. >> + * The payload is an AVParamChange struct. >> + */ >> + AV_FRAME_DATA_PARAM_CHANGE, >> }; >> >> +typedef struct AVParamChange { >> + /** >> + * A dictionary filled with options to be passed to an already initialized >> + * encoder. May contain global and encoder private options. >> + */ >> + AVDictionary *opts; >> +} AVParamChange; >> + >> enum AVActiveFormatDescription { >> AV_AFD_SAME = 8, >> AV_AFD_4_3 = 9, >> diff --git a/libavutil/side_data.c b/libavutil/side_data.c >> index 597228baf1..c156d2bef8 100644 >> --- a/libavutil/side_data.c >> +++ b/libavutil/side_data.c >> @@ -63,6 +63,24 @@ typedef struct FFSideDataDescriptor { >> size_t size; >> } FFSideDataDescriptor; >> >> +/* Type specific refstruct callbacks */ >> + >> +static int copy_param_change(void *_dst, const void *_src) >> +{ >> + const AVParamChange *src = _src; >> + AVParamChange *dst = _dst; >> + int ret = av_dict_copy(&dst->opts, src->opts, 0); >> + if (ret < 0) >> + av_dict_free(&dst->opts); >> + return ret; >> +} >> + >> +static void uninit_param_change(AVRefStructOpaque opaque, void *obj) >> +{ >> + AVParamChange *param = obj; >> + av_dict_free(¶m->opts); >> +} >> + >> static const FFSideDataDescriptor sd_props[] = { >> [AV_FRAME_DATA_PANSCAN] = { .p = { "AVPanScan", AV_SIDE_DATA_PROP_STRUCT | AV_SIDE_DATA_PROP_SIZE_DEPENDENT }, >> .size = sizeof(AVPanScan) }, >> @@ -88,6 +106,11 @@ static const FFSideDataDescriptor sd_props[] = { >> [AV_FRAME_DATA_DOVI_METADATA] = { .p = { "Dolby Vision Metadata", AV_SIDE_DATA_PROP_COLOR_DEPENDENT } }, >> [AV_FRAME_DATA_LCEVC] = { .p = { "LCEVC NAL data", AV_SIDE_DATA_PROP_SIZE_DEPENDENT } }, >> [AV_FRAME_DATA_VIEW_ID] = { .p = { "View ID" } }, >> + [AV_FRAME_DATA_PARAM_CHANGE] = { .p = { "Param Change", AV_SIDE_DATA_PROP_STRUCT }, >> + .props = FF_SIDE_DATA_PROP_REFSTRUCT, >> + .copy = copy_param_change, >> + .uninit = uninit_param_change, >> + .size = sizeof(AVParamChange) }, >> [AV_FRAME_DATA_STEREO3D] = { .p = { "Stereo 3D", AV_SIDE_DATA_PROP_GLOBAL | AV_SIDE_DATA_PROP_STRUCT }, >> .size = sizeof(AVStereo3D) }, >> [AV_FRAME_DATA_REPLAYGAIN] = { .p = { "AVReplayGain", AV_SIDE_DATA_PROP_GLOBAL | AV_SIDE_DATA_PROP_STRUCT }, > > I dislike the whole approach: Frame side data is supposed to contain > side-data that applies to the frame; yet a lot of encoder options which > will ultimately be added to this side data (if it gets committed) are > not frame properties at all. Fair enough. > > Furthermore, this approach necessitates checking every frame (even of > encoders that do not support parameter changes) for the existence of > said side-data, although this side data will not exist in the There's no need to check them. I just copied the check done for the packet side data of the same name, which aborts if it's present when it shouldn't. We can always just silently ignore it instead if the encoder doesn't care about it. > overwhelming majority of cases. Why not add a new function for this > task? (This does not imply that I am in favor of the reconfiguration > approach at all. I'm still leaning towards "close+reopen".) Like i said, there are some cases where it's better to do a graceful re-initialization for the sake of compression if you only care about changing a few values. If we can implement a way to do it that's not invasive, then it's IMO worth giving the option. Right now, libx264 does it silently if it detects changes to the avctx or the private struct, which is not ok as it gives the user the impression it can be done for every encoder, when that's clearly not the case and can even result in crazy behavior for some. I'll look into making it a function later. [-- Attachment #1.2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-01-29 13:53 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-01-25 20:21 [FFmpeg-devel] [PATCH 01/14] avutil/frame: move side data helpers to a new file James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 02/14] avutil/frame: allow the addition of internal fields to AVSideDataDescriptor James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 03/14] avutil/frame: allow the addition of internal fields to AVFrameSideData James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 04/14] avutil/frame: schedule making AVFrameSideData.buf internal James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 05/14] avutil/frame: add functions to check and ensure a side data entry is writable James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 06/14] avutil/frame: av_frame_side_data_new_struct() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 07/14] avutil/frame: add support for RefStruct as backing for side data James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PoC][PATCH 08/14] avutil/frame: add a param change side data type James Almer 2025-01-29 12:29 ` Andreas Rheinhardt 2025-01-29 13:53 ` James Almer [this message] 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 09/14] avutil/ambient_viewing_environment: deprecate av_ambient_viewing_environment_create_side_data() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 10/14] avutil/downmix_info: deprecate av_downmix_info_update_side_data() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 11/14] avutil/hdr_dynamic_metadata: deprecate av_dynamic_hdr_plus_create_side_data() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 12/14] avutil/hdr_dynamic_vivid_metadata: deprecate av_dynamic_hdr_vivid_create_side_data() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 13/14] avutil/mastering_display_metadata: deprecate av_{content_light, mastering_display_metadata}_create_side_data() James Almer 2025-01-25 20:21 ` [FFmpeg-devel] [PATCH 14/14] avutil/stereo3d: deprecate av_stereo3d_create_side_data() James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=92af91b2-cbfe-4ea5-834d-95fa8cf7381e@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git