The existing function allows access the first instance of a given type. Mostly that is OK, but some types can occur multiple times (e.g. libx264 can write version info, VANC and UMID related data as user data unregistered SEI.
This adds API to access additional instances of a given SEI type. --- libavutil/frame.c | 19 +++++++++++++++++++ libavutil/frame.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 31a2117b82..662fcfd452 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -748,6 +748,25 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, return NULL; } +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance) +{ + int i; + int n = 0; + + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) { + if (n == side_data_instance) { + return frame->side_data[i]; + } else { + n++; + } + } + } + return NULL; +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { const uint8_t *src_data[4]; diff --git a/libavutil/frame.h b/libavutil/frame.h index a5ed91b20a..76dd14cbd5 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -943,12 +943,32 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, AVBufferRef *buf); /** + * Find the first instance of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * * @return a pointer to the side data of a given type on success, NULL if there * is no side data with such type in this frame. */ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type); +/** + * Find a specified instance of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * @param side_data_instance instance of the side data to return (0 base). + * + * @return a pointer to the n'th instance of side data of a given type on + * success, NULL if there are less than side_data_instance instances of the + * given type. + */ +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance); + /** * Remove and free all side data instances of the given type. */ -- 2.27.0 _______________________________________________ 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".