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);
99 uint8_t *ptr, *ptr1, *ptr2;
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++) {
165 "stream, some mjpegtools might not work.\n");
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),
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(
"411", tokstart, 3) == 0)
254 else if (strncmp(
"422", tokstart, 3) == 0)
256 else if (strncmp(
"444alpha", tokstart, 8) == 0 ) {
258 "YUV4MPEG stream.\n");
260 }
else if (strncmp(
"444", tokstart, 3) == 0)
262 else if (strncmp(
"mono", tokstart, 4) == 0) {
269 while (tokstart < header_end && *tokstart != 0x20)
273 switch (*tokstart++){
289 "interlaced and non-interlaced frames.\n");
297 sscanf(tokstart,
"%d:%d", &raten, &rated);
298 while (tokstart < header_end && *tokstart != 0x20)
302 sscanf(tokstart,
"%d:%d", &aspectn, &aspectd);
303 while (tokstart < header_end && *tokstart != 0x20)
307 if (strncmp(
"YSCSS=", tokstart, 6) == 0) {
310 if (strncmp(
"420JPEG", tokstart, 7) == 0)
312 else if (strncmp(
"420MPEG2", tokstart, 8) == 0)
314 else if (strncmp(
"420PALDV", tokstart, 8) == 0)
316 else if (strncmp(
"411", tokstart, 3) == 0)
318 else if (strncmp(
"422", tokstart, 3) == 0)
320 else if (strncmp(
"444", tokstart, 3) == 0)
323 while (tokstart < header_end && *tokstart != 0x20)
329 if (width == -1 || height == -1) {
338 pix_fmt = alt_pix_fmt;
341 if (raten <= 0 || rated <= 0) {
347 if (aspectn == 0 && aspectd == 0) {
357 av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
378 if (header[i] ==
'\n') {
387 else if (i == MAX_FRAME_HEADER)
403 else if (ret != packet_size)
424 #if CONFIG_YUV4MPEGPIPE_DEMUXER
426 .
name =
"yuv4mpegpipe",