From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH] [RFC]avformat: introduce AVStreamGroup Date: Mon, 2 Oct 2023 09:10:11 -0300 Message-ID: <40fa74ce-1d31-4f06-9352-436fdd1c2bef@gmail.com> (raw) In-Reply-To: <169623945333.6638.1744815521200399312@lain.khirnov.net> On 10/2/2023 6:37 AM, Anton Khirnov wrote: > Quoting James Almer (2023-09-06 16:38:32) >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> This is an initial proof of concept for AVStream groups, something that's >> needed for quite a few existing and upcoming formats that lavf has no way to >> currently export. Said formats define a single video or audio stream composed >> by merging several individualy multiplexed streams within a media file. >> This is the case of HEIF, a format defining a tiled image where each tile is a >> separate image (either hevc, av1, etc) all of which need to be decoded >> individualy and then stitched together for presentation using container level >> information; IAMF, a new audio format where several individual streams (mono or >> stereo) need to be decoded individually and then combined to form audio streams >> with different channel layouts; and MPEG-TS programs, currently exported as >> AVProgram, which this new general purpose API would replace. >> There may be others too, like something ISOBMFF specific and not HEIF related, >> I'm told. >> >> A new struct, AVStreamGroup, would cover all these cases by grouping the >> relevant streams and propagating format specific metadata for the purpose of >> combining them into what's expected for presentation (Something a filter for >> example would have to take care of). >> >> Missing from this first version is something like a type field, which could be >> an enum listing the different currently known formats the user would then use >> to interpret the attached metadata, defined perhaps in codecpar.extradata >> >> I'd like to hear opinions and suggestions to improve and properly handle this. >> >> libavformat/avformat.c | 26 ++++++++ >> libavformat/avformat.h | 143 ++++++++++++++++++++++++++++++++++++++++- >> libavformat/dump.c | 65 +++++++++++++++++-- >> libavformat/internal.h | 28 ++++++++ >> libavformat/options.c | 77 ++++++++++++++++++++++ >> 5 files changed, 332 insertions(+), 7 deletions(-) >> > >> diff --git a/libavformat/avformat.h b/libavformat/avformat.h >> index 1916aa2dc5..d18eafb933 100644 >> --- a/libavformat/avformat.h >> +++ b/libavformat/avformat.h >> @@ -1007,6 +1007,59 @@ typedef struct AVStream { >> int pts_wrap_bits; >> } AVStream; >> >> +typedef struct AVStreamGroup { >> + /** >> + * A class for @ref avoptions. Set on stream creation. > ^^^^^^ > group > >> + */ >> + const AVClass *av_class; >> + >> + /** >> + * Group index in AVFormatContext. >> + */ >> + int index; > > unsigned? Made it int to have it consistent with AVStream, but ok. > >> + >> + /** >> + * Format-specific group ID. >> + * decoding: set by libavformat >> + * encoding: set by the user, replaced by libavformat if left unset >> + */ >> + int id; > > might want to make this 64bit Ok. > >> + >> + /** >> + * Codec parameters associated with this stream group. Allocated and freed >> + * by libavformat in avformat_new_stream_group() and avformat_free_context() >> + * respectively. >> + * >> + * - demuxing: filled by libavformat on stream group creation or in >> + * avformat_find_stream_info() >> + * - muxing: filled by the caller before avformat_write_header() >> + */ >> + AVCodecParameters *codecpar; >> + >> + void *priv_data; > > Do we really need this? It's a single pointer, and some demuxers may actually make use of it, like they do for the AVStream's counterpart. A git grep "st->priv_data" has a lot of hits. > >> + >> + /** >> + * Number of elements in AVStreamGroup.stream_index. >> + * >> + * Set by av_stream_group_add_stream() and av_stream_group_new_stream(), must not >> + * be modified by any other code. >> + */ >> + int nb_stream_indexes; >> + >> + /** >> + * A list of indexes of streams in the group. New entries are created with >> + * av_stream_group_add_stream() and av_stream_group_new_stream(). >> + * >> + * - demuxing: entries are created by libavformat in avformat_open_input(). >> + * If AVFMTCTX_NOHEADER is set in ctx_flags, then new entries may also >> + * appear in av_read_frame(). >> + * - muxing: entries are created by the user before avformat_write_header(). >> + * >> + * Freed by libavformat in avformat_free_context(). >> + */ >> + int *stream_index; > > unsigned for both? Ok. > >> @@ -1844,6 +1940,51 @@ const AVClass *av_stream_get_class(void); >> */ >> AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c); >> >> +/** >> + * Add a new stream to a stream group. >> + * >> + * When demuxing, it may be called by the demuxer in read_header(). If the >> + * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also >> + * be called in read_packet(). >> + * >> + * When muxing, may be called by the user before avformat_write_header() after >> + * having allocated a new group with avformat_new_stream_group(). >> + * >> + * User is required to call avformat_free_context() to clean up the allocation >> + * by av_stream_group_new_stream(). >> + * >> + * This is functionally the same as avformat_new_stream() while also adding the >> + * newly allocated stream to the group belonging to the media file. >> + * >> + * @param stg stream group belonging to a media file. >> + * >> + * @return newly created stream or NULL on error. >> + * @see av_stream_group_add_stream, avformat_new_stream_group. >> + */ >> +AVStream *av_stream_group_new_stream(AVStreamGroup *stg); > > Is there a big enough advantage to having this as a separate function? I figured it would be nice to have it for the sake of convenience. For formats like HEIF, new streams should in theory be created once the group they will belong to is known. I have no strong attachment to this function, so it can go if you think it's superfluous. > >> + >> +/** >> + * Add an already allocated stream to a stream group. >> + * >> + * When demuxing, it may be called by the demuxer in read_header(). If the >> + * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also >> + * be called in read_packet(). >> + * >> + * When muxing, may be called by the user before avformat_write_header() after >> + * having allocated a new group with avformat_new_stream_group() and stream with >> + * avformat_new_stream(). >> + * >> + * User is required to call avformat_free_context() to clean up the allocation >> + * by av_stream_group_add_stream(). >> + * >> + * @param stg stream group belonging to a media file. >> + * @param st stream in the media file to add to the group. >> + * >> + * @return 0 on success, or a negative AVERROR otherwise. >> + * @see avformat_new_stream, av_stream_group_new_stream, avformat_new_stream_group. >> + */ >> +int av_stream_group_add_stream(AVStreamGroup *stg, const AVStream *st); > > It'd be nice to have the streamgroup-related functions consistenly > namespaced. > > E.g. > * avformat_stream_group_add() > * avformat_stream_group_add_stream() > * ff_stream_group_free() > etc. > > alternatively for the first two: > * avformat_stream_group_create() > * avformat_stream_group_extend() I named avformat_new_stream_group() essentially the same as avformat_new_stream(), then namespaced the functions that take a AVStreamGroup as input. I don't particularly like _extend(), but i guess i could do something like AVStreamGroup *avformat_stream_group_create(AVFormatContext *s) int avformat_stream_group_add_stream(AVStreamGroup *stg, const AVStream *st); _______________________________________________ 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:[~2023-10-02 12:10 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-06 14:38 James Almer 2023-09-06 17:53 ` Tomas Härdin 2023-09-06 19:16 ` James Almer 2023-09-13 9:34 ` Tomas Härdin 2023-09-13 14:33 ` [FFmpeg-devel] J2K in HEIF was: " Pierre-Anthony Lemieux 2023-09-13 20:41 ` Tomas Härdin 2023-09-15 18:10 ` [FFmpeg-devel] [PATCH] " James Almer 2023-09-28 11:27 ` Tomas Härdin 2023-10-02 9:25 ` Anton Khirnov 2023-10-02 19:48 ` James Almer 2023-10-02 9:37 ` Anton Khirnov 2023-10-02 12:10 ` James Almer [this message] 2023-10-03 15:43 ` Anton Khirnov
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=40fa74ce-1d31-4f06-9352-436fdd1c2bef@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