1 /*
2 * YUV4MPEG demuxer
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
24
29
30 /* Header size increased to allow room for optional flags */
31 #define MAX_YUV4_HEADER 128
32 #define MAX_FRAME_HEADER 80
33
35 {
37 // the longest option
38 char *tokstart, *tokend, *header_end;
42 rated = 0, aspectn = 0, aspectd = 0;
49
53 header[
i + 1] = 0x20;
// Add a space after last option.
54 // Makes parsing "444" vs "444alpha" easier.
56 break;
57 }
58 }
62 }
66 }
67
68 header_end = &
header[
i + 1];
// Include space
70 tokstart < header_end; tokstart++) {
71 if (*tokstart == 0x20)
72 continue;
73 switch (*tokstart++) {
74 case 'W': // Width. Required.
75 width = strtol(tokstart, &tokend, 10);
76 tokstart = tokend;
77 break;
78 case 'H': // Height. Required.
79 height = strtol(tokstart, &tokend, 10);
80 tokstart = tokend;
81 break;
82 case 'C': // Color space
83 {
84 static const struct {
85 #define MAX_PIX_FMT_LENGTH 8
87 #undef MAX_PIX_FMT_LENGTH
90 } pix_fmt_array[] = {
119 };
124 chroma_sample_location = pix_fmt_array[
i].chroma_loc;
125 break;
126 }
127 }
130 "pixel format.\n");
132 }
133 while (tokstart < header_end && *tokstart != 0x20)
134 tokstart++;
135 break;
136 }
137 case 'I': // Interlace type
138 switch (*tokstart++){
139 case '?':
141 break;
142 case 'p':
144 break;
145 case 't':
147 break;
148 case 'b':
150 break;
151 case 'm':
153 "interlaced and non-interlaced frames.\n");
154 default:
157 }
158 break;
159 case 'F': // Frame rate
160 sscanf(tokstart, "%d:%d", &raten, &rated); // 0:0 if unknown
161 while (tokstart < header_end && *tokstart != 0x20)
162 tokstart++;
163 break;
164 case 'A': // Pixel aspect
165 sscanf(tokstart, "%d:%d", &aspectn, &aspectd); // 0:0 if unknown
166 while (tokstart < header_end && *tokstart != 0x20)
167 tokstart++;
168 break;
169 case 'X': // Vendor extensions
170 if (strncmp("YSCSS=", tokstart, 6) == 0) {
171 static const struct {
172 #define MAX_PIX_FMT_LENGTH 8
174 #undef MAX_PIX_FMT_LENGTH
176 } pix_fmt_array[] = {
197 };
198 // Older nonstandard pixel format representation
199 tokstart += 6;
202 alt_pix_fmt = pix_fmt_array[
i].pix_fmt;
203 break;
204 }
205 } else if (strncmp("COLORRANGE=", tokstart, 11) == 0) {
206 tokstart += 11;
207 if (strncmp("FULL",tokstart, 4) == 0)
209 else if (strncmp("LIMITED", tokstart, 7) == 0)
211 }
212 while (tokstart < header_end && *tokstart != 0x20)
213 tokstart++;
214 break;
215 }
216 }
217
221 }
222
226 else
228 }
229
230 if (raten <= 0 || rated <= 0) {
231 // Frame rate unknown
232 raten = 25;
233 rated = 1;
234 }
235
236 if (aspectn == 0 && aspectd == 0) {
237 // Pixel aspect unknown
238 aspectd = 1;
239 }
240
242 if (!st)
246 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
257 if ((
int)
s->packet_size < 0)
258 return s->packet_size;
260
262
263 return 0;
264 }
265
267 {
272
277 break;
278 }
279 }
282 else if (
s->pb->eof_reached)
286
289
295 }
299 return 0;
300 }
301
304 {
306
310 return -1;
312
314 return -1;
315 return 0;
316 }
317
319 {
320 /* check file header */
323 else
324 return 0;
325 }
326
328 .
p.
name =
"yuv4mpegpipe",
330 .p.extensions = "y4m",
335 };