26 #define Y4M_MAGIC "YUV4MPEG2"
27 #define Y4M_FRAME_MAGIC "FRAME"
28 #define Y4M_LINE_MAX 256
35 #if CONFIG_YUV4MPEGPIPE_MUXER
40 int raten, rated, aspectn, aspectd, n;
54 if (aspectn == 0 && aspectd == 1)
63 colorspace =
" Cmono";
66 colorspace =
" C411 XYSCSS=411";
72 default: colorspace =
" C420jpeg XYSCSS=420JPEG";
break;
76 colorspace =
" C422 XYSCSS=422";
79 colorspace =
" C444 XYSCSS=444";
84 n = snprintf(buf,
Y4M_LINE_MAX,
"%s W%d H%d F%d:%d I%c A%d:%d%s\n",
85 Y4M_MAGIC, width, height, raten, rated, inter,
86 aspectn, aspectd, colorspace);
108 if (yuv4_generate_header(s, buf2) < 0) {
110 "Error. YUV4MPEG stream header write failed.\n");
125 ptr = picture->
data[0];
126 for (i = 0; i <
height; i++) {
136 width = -(-width >> h_chroma_shift);
137 height = -(-height >> v_chroma_shift);
139 ptr1 = picture->
data[1];
140 ptr2 = picture->
data[2];
141 for (i = 0; i <
height; i++) {
145 for (i = 0; i <
height; i++) {
167 "stream, some mjpegtools might not work.\n");
173 "yuv422p, yuv420p, yuv411p and gray pixel formats. "
174 "Use -pix_fmt to select one.\n");
183 .
name =
"yuv4mpegpipe",
187 .priv_data_size =
sizeof(int),
197 #define MAX_YUV4_HEADER 80
198 #define MAX_FRAME_HEADER 80
204 char *tokstart, *tokend, *header_end;
207 int width = -1, height = -1, raten = 0,
208 rated = 0, aspectn = 0, aspectd = 0;
216 if (header[i] ==
'\n') {
217 header[i + 1] = 0x20;
223 if (i == MAX_YUV4_HEADER)
230 header_end = &header[i + 1];
231 for (tokstart = &header[strlen(
Y4M_MAGIC) + 1];
232 tokstart < header_end; tokstart++) {
233 if (*tokstart == 0x20)
235 switch (*tokstart++) {
237 width = strtol(tokstart, &tokend, 10);
241 height = strtol(tokstart, &tokend, 10);
245 if (strncmp(
"420jpeg", tokstart, 7) == 0) {
248 }
else if (strncmp(
"420mpeg2", tokstart, 8) == 0) {
251 }
else if (strncmp(
"420paldv", tokstart, 8) == 0) {
254 }
else if (strncmp(
"420", tokstart, 3) == 0) {
257 }
else if (strncmp(
"411", tokstart, 3) == 0)
259 else if (strncmp(
"422", tokstart, 3) == 0)
261 else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
263 "YUV4MPEG stream.\n");
265 }
else if (strncmp(
"444", tokstart, 3) == 0)
267 else if (strncmp(
"mono", tokstart, 4) == 0) {
274 while (tokstart < header_end && *tokstart != 0x20)
278 switch (*tokstart++){
294 "interlaced and non-interlaced frames.\n");
302 sscanf(tokstart,
"%d:%d", &raten, &rated);
303 while (tokstart < header_end && *tokstart != 0x20)
307 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
308 while (tokstart < header_end && *tokstart != 0x20)
312 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
315 if (strncmp(
"420JPEG", tokstart, 7) == 0)
317 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
319 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
321 else if (strncmp(
"411", tokstart, 3) == 0)
323 else if (strncmp(
"422", tokstart, 3) == 0)
325 else if (strncmp(
"444", tokstart, 3) == 0)
328 while (tokstart < header_end && *tokstart != 0x20)
334 if (width == -1 || height == -1) {
343 pix_fmt = alt_pix_fmt;
346 if (raten <= 0 || rated <= 0) {
352 if (aspectn == 0 && aspectd == 0) {
362 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
384 if (header[i] ==
'\n') {
393 else if (i == MAX_FRAME_HEADER)
409 else if (ret != packet_size)
430 #if CONFIG_YUV4MPEGPIPE_DEMUXER
432 .
name =
"yuv4mpegpipe",