Skip to content

Commit e504247

Browse files
committed
avcodec: add a ffv1 parser
Only setting frame and stream properties. No packetization is performed. Signed-off-by: James Almer <[email protected]>
1 parent 3d3ce96 commit e504247

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ version 7.1:
5151
and av1_nvenc encoders
5252
- libswresample now accepts custom order channel layouts as input, with some
5353
constrains
54+
- FFV1 parser
5455

5556

5657
version 7.0:

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,6 +3472,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec"
34723472
aac_parser_select="adts_header mpeg4audio"
34733473
av1_parser_select="cbs_av1"
34743474
evc_parser_select="evcparse"
3475+
ffv1_parser_select="rangecoder"
34753476
ftr_parser_select="adts_header mpeg4audio"
34763477
h264_parser_select="golomb h264dsp h264parse h264_sei"
34773478
hevc_parser_select="hevcparse hevc_sei"

libavcodec/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o
12101210
OBJS-$(CONFIG_DVD_NAV_PARSER) += dvd_nav_parser.o
12111211
OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o
12121212
OBJS-$(CONFIG_EVC_PARSER) += evc_parser.o
1213+
OBJS-$(CONFIG_FFV1_PARSER) += ffv1_parser.o ffv1_parse.o ffv1.o
12131214
OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o
12141215
OBJS-$(CONFIG_FTR_PARSER) += ftr_parser.o
12151216
OBJS-$(CONFIG_G723_1_PARSER) += g723_1_parser.o

libavcodec/ffv1_parser.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This file is part of FFmpeg.
3+
*
4+
* FFmpeg is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* FFmpeg is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with FFmpeg; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "avcodec.h"
20+
#include "ffv1.h"
21+
#include "rangecoder.h"
22+
23+
typedef struct FFV1ParseContext {
24+
FFV1Context f;
25+
int got_first;
26+
} FFV1ParseContext;
27+
28+
static int parse(AVCodecParserContext *s,
29+
AVCodecContext *avctx,
30+
const uint8_t **poutbuf, int *poutbuf_size,
31+
const uint8_t *buf, int buf_size)
32+
{
33+
FFV1ParseContext *p = s->priv_data;
34+
FFV1Context *f = &p->f;
35+
RangeCoder c;
36+
uint8_t keystate = 128;
37+
38+
*poutbuf = buf;
39+
*poutbuf_size = buf_size;
40+
41+
if (!p->got_first) {
42+
int ret = ff_ffv1_common_init(avctx, f);
43+
p->got_first = 1;
44+
if (ret < 0)
45+
return buf_size;
46+
47+
if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0)
48+
return buf_size;
49+
}
50+
51+
ff_init_range_decoder(&c, buf, buf_size);
52+
ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
53+
54+
f->avctx = avctx;
55+
s->key_frame = get_rac(&c, &keystate);
56+
s->pict_type = AV_PICTURE_TYPE_I;
57+
s->field_order = AV_FIELD_UNKNOWN;
58+
s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
59+
60+
if (s->key_frame) {
61+
uint8_t state[CONTEXT_SIZE];
62+
memset(state, 128, sizeof(state));
63+
ff_ffv1_parse_header(f, &c, state);
64+
}
65+
66+
s->width = f->width;
67+
s->height = f->height;
68+
s->format = f->pix_fmt;
69+
70+
return buf_size;
71+
}
72+
73+
static void close(AVCodecParserContext *s)
74+
{
75+
FFV1ParseContext *p = s->priv_data;
76+
77+
p->f.avctx = NULL;
78+
ff_ffv1_close(&p->f);
79+
}
80+
81+
const AVCodecParser ff_ffv1_parser = {
82+
.codec_ids = { AV_CODEC_ID_FFV1 },
83+
.priv_data_size = sizeof(FFV1ParseContext),
84+
.parser_parse = parse,
85+
.parser_close = close,
86+
};

libavcodec/parsers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern const AVCodecParser ff_dvd_nav_parser;
4545
extern const AVCodecParser ff_evc_parser;
4646
extern const AVCodecParser ff_flac_parser;
4747
extern const AVCodecParser ff_ftr_parser;
48+
extern const AVCodecParser ff_ffv1_parser;
4849
extern const AVCodecParser ff_g723_1_parser;
4950
extern const AVCodecParser ff_g729_parser;
5051
extern const AVCodecParser ff_gif_parser;

libavcodec/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
#include "version_major.h"
3131

32-
#define LIBAVCODEC_VERSION_MINOR 32
33-
#define LIBAVCODEC_VERSION_MICRO 101
32+
#define LIBAVCODEC_VERSION_MINOR 33
33+
#define LIBAVCODEC_VERSION_MICRO 100
3434

3535
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636
LIBAVCODEC_VERSION_MINOR, \

0 commit comments

Comments
 (0)