Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec: add a simple ffv1 parser
@ 2025-02-01 14:48 James Almer
  2025-02-02  6:49 ` Lynne
  0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2025-02-01 14:48 UTC (permalink / raw)
  To: ffmpeg-devel

Only setting key frames.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 configure                |  1 +
 libavcodec/Makefile      |  1 +
 libavcodec/ffv1_parser.c | 45 ++++++++++++++++++++++++++++++++++++++++
 libavcodec/parsers.c     |  1 +
 4 files changed, 48 insertions(+)
 create mode 100644 libavcodec/ffv1_parser.c

diff --git a/configure b/configure
index 06f641ead0..f09faaf505 100755
--- a/configure
+++ b/configure
@@ -3469,6 +3469,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec"
 aac_parser_select="adts_header mpeg4audio"
 av1_parser_select="cbs_av1"
 evc_parser_select="evcparse"
+ffv1_parser_select="rangecoder"
 ftr_parser_select="adts_header mpeg4audio"
 h264_parser_select="golomb h264dsp h264parse h264_sei"
 hevc_parser_select="hevcparse hevc_sei"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a3ef11a258..1df595d58f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1207,6 +1207,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
 OBJS-$(CONFIG_DVD_NAV_PARSER)          += dvd_nav_parser.o
 OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
 OBJS-$(CONFIG_EVC_PARSER)              += evc_parser.o
+OBJS-$(CONFIG_FFV1_PARSER)             += ffv1_parser.o
 OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o
 OBJS-$(CONFIG_FTR_PARSER)              += ftr_parser.o
 OBJS-$(CONFIG_G723_1_PARSER)           += g723_1_parser.o
diff --git a/libavcodec/ffv1_parser.c b/libavcodec/ffv1_parser.c
new file mode 100644
index 0000000000..f9fd1152d0
--- /dev/null
+++ b/libavcodec/ffv1_parser.c
@@ -0,0 +1,45 @@
+/*
+ * 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 "avcodec.h"
+#include "rangecoder.h"
+
+static int parse(AVCodecParserContext *s,
+                 AVCodecContext *avctx,
+                 const uint8_t **poutbuf, int *poutbuf_size,
+                 const uint8_t *buf, int buf_size)
+{
+    RangeCoder c;
+    uint8_t keystate = 128;
+    ff_init_range_decoder(&c, buf, buf_size);
+    ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
+
+    *poutbuf      = buf;
+    *poutbuf_size = buf_size;
+    s->key_frame = get_rac(&c, &keystate);
+    s->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P, see ffv1dec.c
+    s->field_order = AV_FIELD_UNKNOWN;
+    s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
+
+    return buf_size;
+}
+
+const AVCodecParser ff_ffv1_parser = {
+    .codec_ids    = { AV_CODEC_ID_FFV1 },
+    .parser_parse = parse,
+};
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 8bfd2dbce0..5387351fd0 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -45,6 +45,7 @@ extern const AVCodecParser ff_dvd_nav_parser;
 extern const AVCodecParser ff_evc_parser;
 extern const AVCodecParser ff_flac_parser;
 extern const AVCodecParser ff_ftr_parser;
+extern const AVCodecParser ff_ffv1_parser;
 extern const AVCodecParser ff_g723_1_parser;
 extern const AVCodecParser ff_g729_parser;
 extern const AVCodecParser ff_gif_parser;
-- 
2.48.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] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec: add a simple ffv1 parser
  2025-02-01 14:48 [FFmpeg-devel] [PATCH] avcodec: add a simple ffv1 parser James Almer
@ 2025-02-02  6:49 ` Lynne
  0 siblings, 0 replies; 2+ messages in thread
From: Lynne @ 2025-02-02  6:49 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1.1: Type: text/plain, Size: 3632 bytes --]

On 01/02/2025 15:48, James Almer wrote:
> Only setting key frames.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   configure                |  1 +
>   libavcodec/Makefile      |  1 +
>   libavcodec/ffv1_parser.c | 45 ++++++++++++++++++++++++++++++++++++++++
>   libavcodec/parsers.c     |  1 +
>   4 files changed, 48 insertions(+)
>   create mode 100644 libavcodec/ffv1_parser.c
> 
> diff --git a/configure b/configure
> index 06f641ead0..f09faaf505 100755
> --- a/configure
> +++ b/configure
> @@ -3469,6 +3469,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec"
>   aac_parser_select="adts_header mpeg4audio"
>   av1_parser_select="cbs_av1"
>   evc_parser_select="evcparse"
> +ffv1_parser_select="rangecoder"
>   ftr_parser_select="adts_header mpeg4audio"
>   h264_parser_select="golomb h264dsp h264parse h264_sei"
>   hevc_parser_select="hevcparse hevc_sei"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index a3ef11a258..1df595d58f 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1207,6 +1207,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
>   OBJS-$(CONFIG_DVD_NAV_PARSER)          += dvd_nav_parser.o
>   OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
>   OBJS-$(CONFIG_EVC_PARSER)              += evc_parser.o
> +OBJS-$(CONFIG_FFV1_PARSER)             += ffv1_parser.o
>   OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o
>   OBJS-$(CONFIG_FTR_PARSER)              += ftr_parser.o
>   OBJS-$(CONFIG_G723_1_PARSER)           += g723_1_parser.o
> diff --git a/libavcodec/ffv1_parser.c b/libavcodec/ffv1_parser.c
> new file mode 100644
> index 0000000000..f9fd1152d0
> --- /dev/null
> +++ b/libavcodec/ffv1_parser.c
> @@ -0,0 +1,45 @@
> +/*
> + * 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 "avcodec.h"
> +#include "rangecoder.h"
> +
> +static int parse(AVCodecParserContext *s,
> +                 AVCodecContext *avctx,
> +                 const uint8_t **poutbuf, int *poutbuf_size,
> +                 const uint8_t *buf, int buf_size)
> +{
> +    RangeCoder c;
> +    uint8_t keystate = 128;
> +    ff_init_range_decoder(&c, buf, buf_size);
> +    ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
> +
> +    *poutbuf      = buf;
> +    *poutbuf_size = buf_size;
> +    s->key_frame = get_rac(&c, &keystate);
> +    s->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P, see ffv1dec.c
> +    s->field_order = AV_FIELD_UNKNOWN;
> +    s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
> +
> +    return buf_size;

You should consider exposing expose read_header() from ffv1dec.c, or 
maybe decode_header(), which would give you everything else.
This patch would also help with hardware decoding, as a software decoder 
wouldn't be spun up during probing.

[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 2+ messages in thread

end of thread, other threads:[~2025-02-02  6:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-01 14:48 [FFmpeg-devel] [PATCH] avcodec: add a simple ffv1 parser James Almer
2025-02-02  6:49 ` Lynne

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