FFmpeg
Loading...
Searching...
No Matches
prores_parser.c
Go to the documentation of this file.
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
20#include "bytestream.h"
21
22#include "avcodec.h"
23#include "parser_internal.h"
24
26 AVCodecContext *avctx,
27 const uint8_t **poutbuf, int *poutbuf_size,
28 const uint8_t *buf, int buf_size)
29{
31 uint8_t flags, depth, chroma_format, alpha_channel_type;
32
33 *poutbuf = buf;
34 *poutbuf_size = buf_size;
35
36 /* Frame fields + frame header size */
37 if (buf_size < 28)
38 return buf_size;
39
40 bytestream2_init(&gb, buf, buf_size);
41
42 /* Frame size */
43 if (bytestream2_get_be32(&gb) != buf_size)
44 return buf_size;
45
46 /* Frame identifier */
47 if (bytestream2_get_le32(&gb) != MKTAG('i','c','p','f'))
48 return buf_size;
49
50 /* Frame header size */
51 if (bytestream2_get_be16(&gb) < 20)
52 return buf_size;
53
54 bytestream2_skip(&gb, 6); /* Bitstream version, encoder identifier */
55
56 s->key_frame = 1;
57 s->pict_type = AV_PICTURE_TYPE_I;
58
59 s->width = bytestream2_get_be16(&gb);
60 s->height = bytestream2_get_be16(&gb);
61 s->coded_width = FFALIGN(s->width, 16);
62 s->coded_height = FFALIGN(s->height, 16);
63
64 flags = bytestream2_get_byte(&gb);
65
66 /* Interlace mode */
67 switch (flags >> 2 & 3) {
68 case 0:
69 s->field_order = AV_FIELD_PROGRESSIVE;
70 s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
71 break;
72 case 1:
73 s->field_order = AV_FIELD_TT;
74 s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
75 break;
76 case 2:
77 s->field_order = AV_FIELD_BB;
78 s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
79 break;
80 default:
81 break;
82 }
83
84 bytestream2_skip(&gb, 4); /* Aspect ratio information, frame rate code, color primaries, transfer characteristic, matrix coefficients */
85
86 /* Determine pixel format based on color depth, chroma format and alpha type */
87 switch (avctx->codec_tag) {
88 case MKTAG('a','p','c','o'):
89 case MKTAG('a','p','c','s'):
90 case MKTAG('a','p','c','n'):
91 case MKTAG('a','p','c','h'):
92 depth = 10;
93 break;
94 case MKTAG('a','p','4','h'):
95 case MKTAG('a','p','4','x'):
96 depth = 12;
97 break;
98 default:
99 return buf_size;
100 }
101
102 chroma_format = flags >> 6 & 3;
103 if (chroma_format < 2)
104 return buf_size;
105
106 alpha_channel_type = bytestream2_get_byte(&gb) & 0xf;
107
108 switch (depth | (chroma_format << 4) | (alpha_channel_type << 8)) {
109 case 10 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P10; break;
110 case 10 | (2 << 4) | (1 << 8):
111 case 10 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P10; break;
112 case 10 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P10; break;
113 case 10 | (3 << 4) | (1 << 8):
114 case 10 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P10; break;
115 case 12 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P12; break;
116 case 12 | (2 << 4) | (1 << 8):
117 case 12 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P12; break;
118 case 12 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P12; break;
119 case 12 | (3 << 4) | (1 << 8):
120 case 12 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P12; break;
121 }
122
123 return buf_size;
124}
125
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition apv_parser.c:92
Libavcodec external API header.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
@ AV_FIELD_TT
Top coded_first, top displayed first.
Definition defs.h:214
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
Definition defs.h:215
@ AV_FIELD_PROGRESSIVE
Definition defs.h:213
@ AV_CODEC_ID_PRORES
Definition codec_id.h:198
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
Definition avcodec.h:2614
@ AV_PICTURE_STRUCTURE_BOTTOM_FIELD
coded as bottom field
Definition avcodec.h:2613
@ AV_PICTURE_STRUCTURE_TOP_FIELD
coded as top field
Definition avcodec.h:2612
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFALIGN(x, a)
Definition macros.h:78
#define PARSER_CODEC_LIST(...)
const FFCodecParser ff_prores_parser
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
#define AV_PIX_FMT_YUVA422P12
Definition pixfmt.h:599
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:600
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
main external API structure.
Definition avcodec.h:443
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468