27 #define Y4M_MAGIC "YUV4MPEG2"
28 #define Y4M_FRAME_MAGIC "FRAME"
29 #define Y4M_LINE_MAX 256
31 #if CONFIG_YUV4MPEGPIPE_MUXER
36 int raten, rated, aspectn, aspectd, n;
50 if (aspectn == 0 && aspectd == 1)
66 colorspace =
" Cmono";
69 colorspace =
" Cmono16";
72 colorspace =
" C411 XYSCSS=411";
78 default: colorspace =
" C420jpeg XYSCSS=420JPEG";
break;
82 colorspace =
" C422 XYSCSS=422";
85 colorspace =
" C444 XYSCSS=444";
88 colorspace =
" C420p9 XYSCSS=420P9";
91 colorspace =
" C422p9 XYSCSS=422P9";
94 colorspace =
" C444p9 XYSCSS=444P9";
97 colorspace =
" C420p10 XYSCSS=420P10";
100 colorspace =
" C422p10 XYSCSS=422P10";
103 colorspace =
" C444p10 XYSCSS=444P10";
106 colorspace =
" C420p12 XYSCSS=420P12";
109 colorspace =
" C422p12 XYSCSS=422P12";
112 colorspace =
" C444p12 XYSCSS=444P12";
115 colorspace =
" C420p14 XYSCSS=420P14";
118 colorspace =
" C422p14 XYSCSS=422P14";
121 colorspace =
" C444p14 XYSCSS=444P14";
124 colorspace =
" C420p16 XYSCSS=420P16";
127 colorspace =
" C422p16 XYSCSS=422P16";
130 colorspace =
" C444p16 XYSCSS=444P16";
136 Y4M_MAGIC, width, height, raten, rated, inter,
137 aspectn, aspectd, colorspace);
155 picture = &picture_tmp;
160 if (yuv4_generate_header(s, buf2) < 0) {
162 "Error. YUV4MPEG stream header write failed.\n");
177 ptr = picture->
data[0];
210 for (i = 0; i <
height; i++) {
220 width >>= h_chroma_shift;
221 height >>= v_chroma_shift;
223 ptr1 = picture->
data[1];
224 ptr2 = picture->
data[2];
225 for (i = 0; i <
height; i++) {
229 for (i = 0; i <
height; i++) {
254 "stream, some mjpegtools might not work.\n");
279 "Use '-strict -1' to encode to this pixel format.\n",
284 "Mjpegtools will not work.\n");
288 "yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. "
289 "And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, "
290 "yuv444p10, yuv422p10, yuv420p10, "
291 "yuv444p12, yuv422p12, yuv420p12, "
292 "yuv444p14, yuv422p14, yuv420p14, "
293 "yuv444p16, yuv422p16, yuv420p16 "
294 "and gray16 pixel formats. "
295 "Use -pix_fmt to select one.\n");
304 .
name =
"yuv4mpegpipe",
307 .priv_data_size =
sizeof(int),
317 #define MAX_YUV4_HEADER 80
318 #define MAX_FRAME_HEADER 80
324 char *tokstart, *tokend, *header_end, interlaced =
'?';
327 int width = -1, height = -1, raten = 0,
328 rated = 0, aspectn = 0, aspectd = 0;
335 if (header[i] ==
'\n') {
336 header[i + 1] = 0x20;
342 if (i == MAX_YUV4_HEADER)
347 header_end = &header[i + 1];
348 for (tokstart = &header[strlen(
Y4M_MAGIC) + 1];
349 tokstart < header_end; tokstart++) {
350 if (*tokstart == 0x20)
352 switch (*tokstart++) {
354 width = strtol(tokstart, &tokend, 10);
358 height = strtol(tokstart, &tokend, 10);
362 if (strncmp(
"420jpeg", tokstart, 7) == 0) {
365 }
else if (strncmp(
"420mpeg2", tokstart, 8) == 0) {
368 }
else if (strncmp(
"420paldv", tokstart, 8) == 0) {
371 }
else if (strncmp(
"420p16", tokstart, 6) == 0) {
373 }
else if (strncmp(
"422p16", tokstart, 6) == 0) {
375 }
else if (strncmp(
"444p16", tokstart, 6) == 0) {
377 }
else if (strncmp(
"420p14", tokstart, 6) == 0) {
379 }
else if (strncmp(
"422p14", tokstart, 6) == 0) {
381 }
else if (strncmp(
"444p14", tokstart, 6) == 0) {
383 }
else if (strncmp(
"420p12", tokstart, 6) == 0) {
385 }
else if (strncmp(
"422p12", tokstart, 6) == 0) {
387 }
else if (strncmp(
"444p12", tokstart, 6) == 0) {
389 }
else if (strncmp(
"420p10", tokstart, 6) == 0) {
391 }
else if (strncmp(
"422p10", tokstart, 6) == 0) {
393 }
else if (strncmp(
"444p10", tokstart, 6) == 0) {
395 }
else if (strncmp(
"420p9", tokstart, 5) == 0) {
397 }
else if (strncmp(
"422p9", tokstart, 5) == 0) {
399 }
else if (strncmp(
"444p9", tokstart, 5) == 0) {
401 }
else if (strncmp(
"420", tokstart, 3) == 0) {
404 }
else if (strncmp(
"411", tokstart, 3) == 0) {
406 }
else if (strncmp(
"422", tokstart, 3) == 0) {
408 }
else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
410 "YUV4MPEG stream.\n");
412 }
else if (strncmp(
"444", tokstart, 3) == 0) {
414 }
else if (strncmp(
"mono16", tokstart, 6) == 0) {
416 }
else if (strncmp(
"mono", tokstart, 4) == 0) {
423 while (tokstart < header_end && *tokstart != 0x20)
427 interlaced = *tokstart++;
430 sscanf(tokstart,
"%d:%d", &raten, &rated);
431 while (tokstart < header_end && *tokstart != 0x20)
435 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
436 while (tokstart < header_end && *tokstart != 0x20)
440 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
443 if (strncmp(
"420JPEG", tokstart, 7) == 0)
445 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
447 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
449 else if (strncmp(
"420P9", tokstart, 5) == 0)
451 else if (strncmp(
"422P9", tokstart, 5) == 0)
453 else if (strncmp(
"444P9", tokstart, 5) == 0)
455 else if (strncmp(
"420P10", tokstart, 6) == 0)
457 else if (strncmp(
"422P10", tokstart, 6) == 0)
459 else if (strncmp(
"444P10", tokstart, 6) == 0)
461 else if (strncmp(
"420P12", tokstart, 6) == 0)
463 else if (strncmp(
"422P12", tokstart, 6) == 0)
465 else if (strncmp(
"444P12", tokstart, 6) == 0)
467 else if (strncmp(
"420P14", tokstart, 6) == 0)
469 else if (strncmp(
"422P14", tokstart, 6) == 0)
471 else if (strncmp(
"444P14", tokstart, 6) == 0)
473 else if (strncmp(
"420P16", tokstart, 6) == 0)
475 else if (strncmp(
"422P16", tokstart, 6) == 0)
477 else if (strncmp(
"444P16", tokstart, 6) == 0)
479 else if (strncmp(
"411", tokstart, 3) == 0)
481 else if (strncmp(
"422", tokstart, 3) == 0)
483 else if (strncmp(
"444", tokstart, 3) == 0)
486 while (tokstart < header_end && *tokstart != 0x20)
492 if (width == -1 || height == -1) {
501 pix_fmt = alt_pix_fmt;
504 if (raten <= 0 || rated <= 0) {
510 if (aspectn == 0 && aspectd == 0) {
520 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
540 "interlaced and non-interlaced frames.\n");
561 if (header[i] ==
'\n') {
570 else if (i == MAX_FRAME_HEADER)
586 else if (ret != packet_size)
602 #if CONFIG_YUV4MPEGPIPE_DEMUXER
604 .
name =
"yuv4mpegpipe",