FFmpeg
prores_raw_parser.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 Lynne <dev@lynne.ee>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "parser.h"
22 #include "bytestream.h"
23 
25  const uint8_t **poutbuf, int *poutbuf_size,
26  const uint8_t *buf, int buf_size)
27 {
28  GetByteContext gb;
29 
30  switch (avctx->codec_tag) {
31  case 0:
32  break;
33  case MKTAG('a','p','r','n'):
35  break;
36  case MKTAG('a','p','r','h'):
38  break;
39  default:
40  avpriv_request_sample(avctx, "Profile %d", avctx->codec_tag);
41  return buf_size;
42  break;
43  }
44 
45  bytestream2_init(&gb, buf, buf_size);
46  if (bytestream2_get_be32(&gb) != buf_size) /* Packet size */
47  return buf_size;
48 
49  if (bytestream2_get_le32(&gb) != MKTAG('p','r','r','f')) /* Frame header */
50  return buf_size;
51 
52  int header_size = bytestream2_get_be16(&gb);
53  if (header_size < 62)
54  return buf_size;
55 
56  bytestream2_skip(&gb, 1);
57  int version = bytestream2_get_byte(&gb);
58  if (version > 1) {
59  avpriv_request_sample(avctx, "Version %d", version);
60  return buf_size;
61  }
62 
63  /* Vendor header (e.g. "peac" for Panasonic or "atm0" for Atmos) */
64  bytestream2_skip(&gb, 4);
65 
66  s->width = bytestream2_get_be16(&gb);
67  s->height = bytestream2_get_be16(&gb);
68  s->coded_width = FFALIGN(s->width, 16);
69  s->coded_height = FFALIGN(s->height, 16);
70  s->format = AV_PIX_FMT_BAYER_RGGB16;
71  s->key_frame = 1;
72  s->pict_type = AV_PICTURE_TYPE_I;
73  s->field_order = AV_FIELD_PROGRESSIVE;
74  s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
75 
76  /* This parser only performs analysis */
77  *poutbuf = buf;
78  *poutbuf_size = buf_size;
79 
80  return buf_size;
81 }
82 
85  .parser_parse = prores_raw_parse,
86 };
GetByteContext
Definition: bytestream.h:33
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: defs.h:213
AV_PROFILE_PRORES_RAW_HQ
#define AV_PROFILE_PRORES_RAW_HQ
Definition: defs.h:189
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
AV_PROFILE_PRORES_RAW
#define AV_PROFILE_PRORES_RAW
Definition: defs.h:188
AV_CODEC_ID_PRORES_RAW
@ AV_CODEC_ID_PRORES_RAW
Definition: codec_id.h:333
AV_PICTURE_STRUCTURE_FRAME
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
Definition: avcodec.h:2572
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
AVCodecParser::codec_ids
int codec_ids[7]
Definition: avcodec.h:2735
ff_prores_raw_parser
const AVCodecParser ff_prores_raw_parser
Definition: prores_raw_parser.c:83
version
version
Definition: libkvazaar.c:315
parser.h
AVCodecParserContext
Definition: avcodec.h:2575
AVCodecContext
main external API structure.
Definition: avcodec.h:431
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1618
prores_raw_parse
static int prores_raw_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: prores_raw_parser.c:24
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:456
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecParser
Definition: avcodec.h:2734
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AV_PIX_FMT_BAYER_RGGB16
#define AV_PIX_FMT_BAYER_RGGB16
Definition: pixfmt.h:572