[FFmpeg-devel] [PATCH v2 07/13] lavc: add a ProRes RAW parser
Lynne
dev at lynne.ee
Sat Jul 12 21:51:16 EEST 2025
Simple parser that only parses frame information.
This helps avoid requiring the software decoder on init to decode a
single frame, since the decoder can be quite slow.
---
libavcodec/Makefile | 1 +
libavcodec/parsers.c | 1 +
libavcodec/prores_raw_parser.c | 72 ++++++++++++++++++++++++++++++++++
libavformat/mov.c | 1 +
4 files changed, 75 insertions(+)
create mode 100644 libavcodec/prores_raw_parser.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 215577f7c9..78e099ce5d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1250,6 +1250,7 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \
OBJS-$(CONFIG_OPUS_PARSER) += vorbis_data.o
OBJS-$(CONFIG_PNG_PARSER) += png_parser.o
OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
+OBJS-$(CONFIG_PRORES_RAW_PARSER) += prores_raw_parser.o
OBJS-$(CONFIG_QOI_PARSER) += qoi_parser.o
OBJS-$(CONFIG_RV34_PARSER) += rv34_parser.o
OBJS-$(CONFIG_SBC_PARSER) += sbc_parser.o
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 21164f3751..b12c48f79f 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -68,6 +68,7 @@ extern const AVCodecParser ff_mpegvideo_parser;
extern const AVCodecParser ff_opus_parser;
extern const AVCodecParser ff_png_parser;
extern const AVCodecParser ff_pnm_parser;
+extern const AVCodecParser ff_prores_raw_parser;
extern const AVCodecParser ff_qoi_parser;
extern const AVCodecParser ff_rv34_parser;
extern const AVCodecParser ff_sbc_parser;
diff --git a/libavcodec/prores_raw_parser.c b/libavcodec/prores_raw_parser.c
new file mode 100644
index 0000000000..a286d674b2
--- /dev/null
+++ b/libavcodec/prores_raw_parser.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2025 Lynne <dev at lynne.ee>
+ *
+ * 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 "parser.h"
+#include "bytestream.h"
+
+static int prores_raw_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ GetByteContext gb;
+ uint32_t header_size;
+ int version;
+
+ bytestream2_init(&gb, buf, buf_size);
+ if (bytestream2_get_be32(&gb) != buf_size) /* Packet size */
+ return buf_size;
+
+ if (bytestream2_get_le32(&gb) != MKTAG('p','r','r','f')) /* Frame header */
+ return buf_size;
+
+ header_size = bytestream2_get_be16(&gb) + 8;
+ version = bytestream2_get_be16(&gb);
+ if (version > 1) {
+ avpriv_request_sample(avctx, "Version %d", version);
+ return buf_size;
+ }
+
+ if (header_size < (version == 0 ? 144 : 96))
+ return buf_size;
+
+ /* Vendor header (e.g. "peac" for Panasonic or "atm0" for Atmos) */
+ bytestream2_skip(&gb, 4);
+
+ s->width = bytestream2_get_be16(&gb);
+ s->height = bytestream2_get_be16(&gb);
+ s->coded_width = FFALIGN(s->width, 16);
+ s->coded_height = FFALIGN(s->height, 16);
+ s->format = AV_PIX_FMT_BAYER_RGGB16;
+ s->key_frame = 1;
+ s->pict_type = AV_PICTURE_TYPE_I;
+ s->field_order = AV_FIELD_PROGRESSIVE;
+ s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
+
+ /* This parser only performs analysis */
+ *poutbuf = buf;
+ *poutbuf_size = buf_size;
+
+ return buf_size;
+}
+
+const AVCodecParser ff_prores_raw_parser = {
+ .codec_ids = { AV_CODEC_ID_PRORES_RAW },
+ .parser_parse = prores_raw_parse,
+};
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c935bbf0bf..39c1d6c286 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2987,6 +2987,7 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb,
case AV_CODEC_ID_VP9:
sti->need_parsing = AVSTREAM_PARSE_FULL;
break;
+ case AV_CODEC_ID_PRORES_RAW:
case AV_CODEC_ID_APV:
case AV_CODEC_ID_EVC:
case AV_CODEC_ID_AV1:
--
2.50.0
More information about the ffmpeg-devel
mailing list