24 #define Y4M_MAGIC "YUV4MPEG2"
25 #define Y4M_FRAME_MAGIC "FRAME"
26 #define Y4M_LINE_MAX 256
33 #if CONFIG_YUV4MPEGPIPE_MUXER
38 int raten, rated, aspectn, aspectd, n;
52 if (aspectn == 0 && aspectd == 1)
61 colorspace =
" Cmono";
64 colorspace =
" C411 XYSCSS=411";
70 default: colorspace =
" C420jpeg XYSCSS=420JPEG";
break;
74 colorspace =
" C422 XYSCSS=422";
77 colorspace =
" C444 XYSCSS=444";
82 n = snprintf(buf,
Y4M_LINE_MAX,
"%s W%d H%d F%d:%d I%c A%d:%d%s\n",
83 Y4M_MAGIC, width, height, raten, rated, inter,
84 aspectn, aspectd, colorspace);
106 if (yuv4_generate_header(s, buf2) < 0) {
108 "Error. YUV4MPEG stream header write failed.\n");
123 ptr = picture->
data[0];
124 for (i = 0; i <
height; i++) {
133 width >>= h_chroma_shift;
134 height >>= v_chroma_shift;
136 ptr1 = picture->
data[1];
137 ptr2 = picture->
data[2];
138 for (i = 0; i <
height; i++) {
142 for (i = 0; i <
height; i++) {
159 av_log(s, AV_LOG_ERROR,
"ERROR: Only rawvideo supported.\n");
164 av_log(s, AV_LOG_ERROR,
"Warning: generating rarely used 4:1:1 YUV "
165 "stream, some mjpegtools might not work.\n");
170 av_log(s, AV_LOG_ERROR,
"ERROR: yuv4mpeg only handles yuv444p, "
171 "yuv422p, yuv420p, yuv411p and gray pixel formats. "
172 "Use -pix_fmt to select one.\n");
181 .
name =
"yuv4mpegpipe",
185 .priv_data_size =
sizeof(int),
190 .
flags = AVFMT_RAWPICTURE,
195 #define MAX_YUV4_HEADER 80
196 #define MAX_FRAME_HEADER 80
202 char *tokstart, *tokend, *header_end;
205 int width = -1, height = -1, raten = 0,
206 rated = 0, aspectn = 0, aspectd = 0;
214 if (header[i] ==
'\n') {
215 header[i + 1] = 0x20;
221 if (i == MAX_YUV4_HEADER)
228 header_end = &header[i + 1];
229 for (tokstart = &header[strlen(
Y4M_MAGIC) + 1];
230 tokstart < header_end; tokstart++) {
231 if (*tokstart == 0x20)
233 switch (*tokstart++) {
235 width = strtol(tokstart, &tokend, 10);
239 height = strtol(tokstart, &tokend, 10);
243 if (strncmp(
"420jpeg", tokstart, 7) == 0) {
246 }
else if (strncmp(
"420mpeg2", tokstart, 8) == 0) {
249 }
else if (strncmp(
"420paldv", tokstart, 8) == 0) {
252 }
else if (strncmp(
"420", tokstart, 3) == 0) {
255 }
else if (strncmp(
"411", tokstart, 3) == 0)
257 else if (strncmp(
"422", tokstart, 3) == 0)
259 else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
261 "YUV4MPEG stream.\n");
263 }
else if (strncmp(
"444", tokstart, 3) == 0)
265 else if (strncmp(
"mono", tokstart, 4) == 0) {
272 while (tokstart < header_end && *tokstart != 0x20)
276 switch (*tokstart++){
292 "interlaced and non-interlaced frames.\n");
300 sscanf(tokstart,
"%d:%d", &raten, &rated);
301 while (tokstart < header_end && *tokstart != 0x20)
305 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
306 while (tokstart < header_end && *tokstart != 0x20)
310 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
313 if (strncmp(
"420JPEG", tokstart, 7) == 0)
315 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
317 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
319 else if (strncmp(
"411", tokstart, 3) == 0)
321 else if (strncmp(
"422", tokstart, 3) == 0)
323 else if (strncmp(
"444", tokstart, 3) == 0)
326 while (tokstart < header_end && *tokstart != 0x20)
332 if (width == -1 || height == -1) {
341 pix_fmt = alt_pix_fmt;
344 if (raten <= 0 || rated <= 0) {
350 if (aspectn == 0 && aspectd == 0) {
360 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
381 if (header[i] ==
'\n') {
390 else if (i == MAX_FRAME_HEADER)
406 else if (ret != packet_size)
427 #if CONFIG_YUV4MPEGPIPE_DEMUXER
429 .
name =
"yuv4mpegpipe",