Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Jan Ekström" <jeebjp@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: pass encoder init AVFrame side data to output AVStream
Date: Sun, 5 Mar 2023 20:16:57 +0200
Message-ID: <CAEu79SZWfbovWXv8HLN=TW0YCNUQrSEkrLcv=Ys1PKCuOh88AA@mail.gmail.com> (raw)
In-Reply-To: <20230305111720.6019-1-jeebjp@gmail.com>

On Sun, Mar 5, 2023 at 1:17 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> This enables passing through various side data during encoding,
> which is not yet in AVCodecContext/AVCodecParameters, but is read
> from AVStream side data in muxers.
>
> Additionally, add a FATE test that demonstrates PNG->J2K MP4
> transcoding with the ICC profile getting passed through.
> ---

Just tested locally and going PNG->MP4 (RGB H.264)->PNG actually does
work with ffmpeg.c now with regards to ICC side data :) So something
like this does actually help with round-tripping (most likely since
the side data goes from the AVStream to the first AVPacket and thus
into the first AVFrame, which then gets picked up by pngenc),

Currently this is only limited to video, as audio cannot work with the
avfilter peek API, as the peeked frame gets buffered, and thus any
further adjustment of audio frame size will fail, as the buffered
frame gets output first (with whatever the original requested size
was).

>  fftools/ffmpeg.c                             |  6 ++
>  fftools/ffmpeg.h                             |  1 +
>  fftools/ffmpeg_mux.c                         | 47 +++++++++++++
>  tests/fate/ffmpeg.mak                        |  4 ++
>  tests/ref/fate/ffmpeg-side-data-to-avstreams | 72 ++++++++++++++++++++
>  5 files changed, 130 insertions(+)
>  create mode 100644 tests/ref/fate/ffmpeg-side-data-to-avstreams
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index d721a5e721..134258b825 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -3113,6 +3113,12 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
>                                                   av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
>
>          if (frame) {
> +            if (!(ost->side_data_frame = av_frame_alloc()))
> +                return AVERROR(ENOMEM);
> +
> +            if ((ret = av_frame_copy_props(ost->side_data_frame, frame)) < 0)
> +                return ret;
> +
>              enc_ctx->color_range            = frame->color_range;
>              enc_ctx->color_primaries        = frame->color_primaries;
>              enc_ctx->color_trc              = frame->color_trc;
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index 4d4433f5ba..21dd0f3a9e 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -593,6 +593,7 @@ typedef struct OutputStream {
>      AVFrame *filtered_frame;
>      AVFrame *last_frame;
>      AVFrame *sq_frame;
> +    AVFrame *side_data_frame;
>      AVPacket *pkt;
>      int64_t last_dropped;
>      int64_t last_nb0_frames[3];
> diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
> index cf58051949..13da9ab8da 100644
> --- a/fftools/ffmpeg_mux.c
> +++ b/fftools/ffmpeg_mux.c
> @@ -580,6 +580,49 @@ static int bsf_init(MuxStream *ms)
>      return 0;
>  }
>
> +static int avframe_side_data_to_avstream(AVStream *stream, const AVFrame *frame)
> +{
> +    static const struct sd_mapping {
> +        enum AVPacketSideDataType packet;
> +        enum AVFrameSideDataType frame;
> +    } sd_list[] = {
> +        { AV_PKT_DATA_REPLAYGAIN ,                AV_FRAME_DATA_REPLAYGAIN },
> +        { AV_PKT_DATA_DISPLAYMATRIX,              AV_FRAME_DATA_DISPLAYMATRIX },
> +        { AV_PKT_DATA_SPHERICAL,                  AV_FRAME_DATA_SPHERICAL },
> +        { AV_PKT_DATA_STEREO3D,                   AV_FRAME_DATA_STEREO3D },
> +        { AV_PKT_DATA_AUDIO_SERVICE_TYPE,         AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
> +        { 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_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 },
> +    };

For the record, this listing was taken from
ff_decode_frame_props_from_pkt, and probably at the end of the day
should be in a "get one from the other" or "iterate me all the
mappings" sort of API in avcodec.

Then this function adding stuff to AVStream could be in avformat
without the list being duplicated.

This thing is here in this patch mostly to prove that this kind of
passing through additional side data would help.

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-request@ffmpeg.org with subject "unsubscribe".

      reply	other threads:[~2023-03-05 18:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-05 11:17 Jan Ekström
2023-03-05 18:16 ` Jan Ekström [this message]

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='CAEu79SZWfbovWXv8HLN=TW0YCNUQrSEkrLcv=Ys1PKCuOh88AA@mail.gmail.com' \
    --to=jeebjp@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