PR #22352 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22352 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22352.patch
Including a parser to assemble entire Access Units. >From ea587066055828b5b7711228a2939614415df316 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Mon, 2 Mar 2026 18:10:39 -0300 Subject: [PATCH 1/2] avcodec: add an LCEVC parser Signed-off-by: James Almer <[email protected]> --- libavcodec/lcevc_parser.c | 88 +++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 2 files changed, 89 insertions(+) create mode 100644 libavcodec/lcevc_parser.c diff --git a/libavcodec/lcevc_parser.c b/libavcodec/lcevc_parser.c new file mode 100644 index 0000000000..c737fada59 --- /dev/null +++ b/libavcodec/lcevc_parser.c @@ -0,0 +1,88 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdint.h> + +#include "libavutil/mem.h" + +#include "avcodec.h" +#include "lcevc.h" +#include "parser.h" +#include "parser_internal.h" + +#define START_CODE 0x000001 ///< start_code_prefix_one_3bytes + +static int lcevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, + int buf_size) +{ + ParseContext *pc = s->priv_data; + + for (int i = 0; i < buf_size; i++) { + int nut; + + pc->state = (pc->state << 8) | buf[i]; + + if (((pc->state >> 8) & 0xFFFFFF) != START_CODE) + continue; + + nut = (pc->state >> 1) & 0x1F; + + // Beginning of access unit + if (nut == LCEVC_IDR_NUT || nut == LCEVC_NON_IDR_NUT) { + if (!pc->frame_start_found) + pc->frame_start_found = 1; + else { + pc->frame_start_found = 0; + return i - 3; + } + } + } + + return END_NOT_FOUND; +} + +static int lcevc_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + next = lcevc_find_frame_end(s, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +const FFCodecParser ff_lcevc_parser = { + PARSER_CODEC_LIST(AV_CODEC_ID_LCEVC), + .priv_data_size = sizeof(ParseContext), + .parse = lcevc_parse, + .close = ff_parse_close, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 4561f6eb3d..162b96cb69 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -78,6 +78,7 @@ extern const FFCodecParser ff_ipu_parser; extern const FFCodecParser ff_jpeg2000_parser; extern const FFCodecParser ff_jpegxl_parser; extern const FFCodecParser ff_jpegxs_parser; +extern const FFCodecParser ff_lcevc_parser; extern const FFCodecParser ff_misc4_parser; extern const FFCodecParser ff_mjpeg_parser; extern const FFCodecParser ff_mlp_parser; -- 2.52.0 >From 5ee0872519c416a8f59ccebc8eb91f4f0ee88303 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Mon, 2 Mar 2026 19:49:57 -0300 Subject: [PATCH 2/2] avformat/mpegts: add basic support for LCEVC streams As defined in ITU-T H.222.0 v9. LCEVC streams use the "Byte stream format" defined in Annex B of ISO/IEC 23094-2:2021. Signed-off-by: James Almer <[email protected]> --- libavformat/mpegts.c | 1 + libavformat/mpegts.h | 1 + 2 files changed, 2 insertions(+) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index a9094ab55b..40153c7c9a 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -816,6 +816,7 @@ static const StreamType ISO_types[] = { { STREAM_TYPE_VIDEO_JPEG2000, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_JPEG2000 }, { STREAM_TYPE_VIDEO_HEVC, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC }, { STREAM_TYPE_VIDEO_JPEGXS, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_JPEGXS }, + { STREAM_TYPE_VIDEO_LCEVC, AVMEDIA_TYPE_DATA, AV_CODEC_ID_LCEVC }, { STREAM_TYPE_VIDEO_VVC, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VVC }, { STREAM_TYPE_VIDEO_CAVS, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_CAVS }, { STREAM_TYPE_VIDEO_DIRAC, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC }, diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h index 223962d18e..baaf9365eb 100644 --- a/libavformat/mpegts.h +++ b/libavformat/mpegts.h @@ -146,6 +146,7 @@ #define STREAM_TYPE_VIDEO_HEVC 0x24 #define STREAM_TYPE_VIDEO_JPEGXS 0x32 #define STREAM_TYPE_VIDEO_VVC 0x33 +#define STREAM_TYPE_VIDEO_LCEVC 0x36 #define STREAM_TYPE_VIDEO_CAVS 0x42 #define STREAM_TYPE_VIDEO_AVS2 0xd2 #define STREAM_TYPE_VIDEO_AVS3 0xd4 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
