* [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser
@ 2023-07-26 9:27 hung kuishing
2023-07-26 13:01 ` Paul B Mahol
0 siblings, 1 reply; 3+ messages in thread
From: hung kuishing @ 2023-07-26 9:27 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: clarkh <hungkuishing@outlook.com>
---
libavcodec/Makefile | 1 +
libavcodec/parsers.c | 1 +
libavcodec/prores_parser.c | 107 +++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+)
create mode 100644 libavcodec/prores_parser.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1b0226c089..21cd28c9ac 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_OPUS_PARSER) += opus_parser.o opus_parse.o \
vorbis_data.o
OBJS-$(CONFIG_PNG_PARSER) += png_parser.o
OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
+OBJS-$(CONFIG_PRORES_PARSER) += prores_parser.o
OBJS-$(CONFIG_QOI_PARSER) += qoi_parser.o
OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o
OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 285f81a901..131867686a 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -64,6 +64,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_parser;
extern const AVCodecParser ff_qoi_parser;
extern const AVCodecParser ff_rv30_parser;
extern const AVCodecParser ff_rv40_parser;
diff --git a/libavcodec/prores_parser.c b/libavcodec/prores_parser.c
new file mode 100644
index 0000000000..1299c7b642
--- /dev/null
+++ b/libavcodec/prores_parser.c
@@ -0,0 +1,107 @@
+/*
+ * ProRes bitstream parser
+ * Copyright (c) 2023 clarkh <hungkuishing@outlook.com>
+ *
+ * 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 "libavutil/intreadwrite.h"
+#include "libavcodec/proresdata.h"
+
+typedef struct {
+ ParseContext pc;
+ int remaining;
+ int overwrite;
+} ProResParserContext;
+
+static int prores_find_frame_end(ProResParserContext *pctx, const uint8_t *buf, int buf_size)
+{
+ ParseContext *pc = &pctx->pc;
+ uint64_t state64 = pc->state64;
+ int pic_found = pc->frame_start_found;
+ int i = 0;
+
+ if (!pic_found) {
+ for (i = 0; i < buf_size; i++) {
+ state64 = (state64 << 8) | buf[i];
+ if ((state64 & 0xFFFFFFFF) == FRAME_ID) {
+ i++;
+ pic_found = 1;
+ pctx->remaining = state64 >> 32;
+ pctx->remaining -= pctx->overwrite;
+ break;
+ }
+ }
+ }
+
+ if (pic_found) {
+ if (!buf_size)
+ return END_NOT_FOUND;
+
+ if (pctx->remaining > buf_size) {
+ pctx->remaining -= buf_size;
+ } else {
+ int remaining = pctx->remaining;
+
+ pc->frame_start_found = 0;
+ pc->state64 = -1;
+ pctx->remaining = 0;
+ pctx->overwrite = 0;
+ return remaining;
+ }
+ } else {
+ pctx->overwrite += buf_size;
+ }
+
+ pc->frame_start_found = pic_found;
+ pc->state64 = state64;
+
+ return END_NOT_FOUND;
+}
+
+static int prores_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ ProResParserContext *pctx = s->priv_data;
+ ParseContext *pc = &pctx->pc;
+ int next;
+
+ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ next = buf_size;
+ } else {
+ next = prores_find_frame_end(pctx, 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 AVCodecParser ff_prores_parser = {
+ .codec_ids = { AV_CODEC_ID_PRORES },
+ .priv_data_size = sizeof(ProResParserContext),
+ .parser_parse = prores_parse,
+ .parser_close = ff_parse_close
+};
--
2.34.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser
2023-07-26 9:27 [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser hung kuishing
@ 2023-07-26 13:01 ` Paul B Mahol
2023-07-26 14:55 ` hung kuishing
0 siblings, 1 reply; 3+ messages in thread
From: Paul B Mahol @ 2023-07-26 13:01 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Wed, Jul 26, 2023 at 11:27 AM hung kuishing <hungkuishing@outlook.com>
wrote:
> Signed-off-by: clarkh <hungkuishing@outlook.com>
> ---
> libavcodec/Makefile | 1 +
> libavcodec/parsers.c | 1 +
> libavcodec/prores_parser.c | 107 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 109 insertions(+)
> create mode 100644 libavcodec/prores_parser.c
>
What is usage for this?
Which streams/files need this?
Have parser be tested rigorously with random noise data?
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 1b0226c089..21cd28c9ac 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_OPUS_PARSER) +=
> opus_parser.o opus_parse.o \
> vorbis_data.o
> OBJS-$(CONFIG_PNG_PARSER) += png_parser.o
> OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
> +OBJS-$(CONFIG_PRORES_PARSER) += prores_parser.o
> OBJS-$(CONFIG_QOI_PARSER) += qoi_parser.o
> OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o
> OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o
> diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
> index 285f81a901..131867686a 100644
> --- a/libavcodec/parsers.c
> +++ b/libavcodec/parsers.c
> @@ -64,6 +64,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_parser;
> extern const AVCodecParser ff_qoi_parser;
> extern const AVCodecParser ff_rv30_parser;
> extern const AVCodecParser ff_rv40_parser;
> diff --git a/libavcodec/prores_parser.c b/libavcodec/prores_parser.c
> new file mode 100644
> index 0000000000..1299c7b642
> --- /dev/null
> +++ b/libavcodec/prores_parser.c
> @@ -0,0 +1,107 @@
> +/*
> + * ProRes bitstream parser
> + * Copyright (c) 2023 clarkh <hungkuishing@outlook.com>
> + *
> + * 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 "libavutil/intreadwrite.h"
> +#include "libavcodec/proresdata.h"
> +
> +typedef struct {
> + ParseContext pc;
> + int remaining;
> + int overwrite;
> +} ProResParserContext;
> +
> +static int prores_find_frame_end(ProResParserContext *pctx, const uint8_t
> *buf, int buf_size)
> +{
> + ParseContext *pc = &pctx->pc;
> + uint64_t state64 = pc->state64;
> + int pic_found = pc->frame_start_found;
> + int i = 0;
> +
> + if (!pic_found) {
> + for (i = 0; i < buf_size; i++) {
> + state64 = (state64 << 8) | buf[i];
> + if ((state64 & 0xFFFFFFFF) == FRAME_ID) {
> + i++;
> + pic_found = 1;
> + pctx->remaining = state64 >> 32;
> + pctx->remaining -= pctx->overwrite;
> + break;
> + }
> + }
> + }
> +
> + if (pic_found) {
> + if (!buf_size)
> + return END_NOT_FOUND;
> +
> + if (pctx->remaining > buf_size) {
> + pctx->remaining -= buf_size;
> + } else {
> + int remaining = pctx->remaining;
> +
> + pc->frame_start_found = 0;
> + pc->state64 = -1;
> + pctx->remaining = 0;
> + pctx->overwrite = 0;
> + return remaining;
> + }
> + } else {
> + pctx->overwrite += buf_size;
> + }
> +
> + pc->frame_start_found = pic_found;
> + pc->state64 = state64;
> +
> + return END_NOT_FOUND;
> +}
> +
> +static int prores_parse(AVCodecParserContext *s, AVCodecContext *avctx,
> + const uint8_t **poutbuf, int *poutbuf_size,
> + const uint8_t *buf, int buf_size)
> +{
> + ProResParserContext *pctx = s->priv_data;
> + ParseContext *pc = &pctx->pc;
> + int next;
> +
> + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
> + next = buf_size;
> + } else {
> + next = prores_find_frame_end(pctx, 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 AVCodecParser ff_prores_parser = {
> + .codec_ids = { AV_CODEC_ID_PRORES },
> + .priv_data_size = sizeof(ProResParserContext),
> + .parser_parse = prores_parse,
> + .parser_close = ff_parse_close
> +};
> --
> 2.34.1
>
> _______________________________________________
> 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".
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser
2023-07-26 13:01 ` Paul B Mahol
@ 2023-07-26 14:55 ` hung kuishing
0 siblings, 0 replies; 3+ messages in thread
From: hung kuishing @ 2023-07-26 14:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, July 26, 2023 9:02 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream
> parser
>
> On Wed, Jul 26, 2023 at 11:27 AM hung kuishing
> <hungkuishing@outlook.com>
> wrote:
>
> > Signed-off-by: clarkh <hungkuishing@outlook.com>
> > ---
> > libavcodec/Makefile | 1 +
> > libavcodec/parsers.c | 1 +
> > libavcodec/prores_parser.c | 107
> > +++++++++++++++++++++++++++++++++++++
> > 3 files changed, 109 insertions(+)
> > create mode 100644 libavcodec/prores_parser.c
> >
>
> What is usage for this?
> Which streams/files need this?
This patch originated from a need in my work to wrap the ProRes bitstream generated by ffmpeg into another mov wrapper.
If it doesn't add value to the community, just ignore it with ease.
> Have parser be tested rigorously with random noise data?
I tested with some random data, ffmpeg can handle them correctly.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-26 14:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 9:27 [FFmpeg-devel] [PATCH v3 1/2] lavc: add prores bitstream parser hung kuishing
2023-07-26 13:01 ` Paul B Mahol
2023-07-26 14:55 ` hung kuishing
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