yuv4mpeg.c
Go to the documentation of this file.
1 /*
2  * YUV4MPEG format
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 
22 #include "libavutil/pixdesc.h"
23 #include "avformat.h"
24 #include "internal.h"
25 #include "libavutil/pixdesc.h"
26 
27 #define Y4M_MAGIC "YUV4MPEG2"
28 #define Y4M_FRAME_MAGIC "FRAME"
29 #define Y4M_LINE_MAX 256
30 
31 #if CONFIG_YUV4MPEGPIPE_MUXER
32 static int yuv4_generate_header(AVFormatContext *s, char* buf)
33 {
34  AVStream *st;
35  int width, height;
36  int raten, rated, aspectn, aspectd, n;
37  char inter;
38  const char *colorspace = "";
39 
40  st = s->streams[0];
41  width = st->codec->width;
42  height = st->codec->height;
43 
44  av_reduce(&raten, &rated, st->codec->time_base.den,
45  st->codec->time_base.num, (1UL << 31) - 1);
46 
47  aspectn = st->sample_aspect_ratio.num;
48  aspectd = st->sample_aspect_ratio.den;
49 
50  if (aspectn == 0 && aspectd == 1)
51  aspectd = 0; // 0:0 means unknown
52 
53  inter = 'p'; /* progressive is the default */
55  inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
57  inter = 'p';
58  } else if (st->codec->field_order == AV_FIELD_TB || st->codec->field_order == AV_FIELD_TT) {
59  inter = 't';
60  } else if (st->codec->field_order == AV_FIELD_BT || st->codec->field_order == AV_FIELD_BB) {
61  inter = 'b';
62  }
63 
64  switch (st->codec->pix_fmt) {
65  case AV_PIX_FMT_GRAY8:
66  colorspace = " Cmono";
67  break;
68  case AV_PIX_FMT_GRAY16:
69  colorspace = " Cmono16";
70  break;
71  case AV_PIX_FMT_YUV411P:
72  colorspace = " C411 XYSCSS=411";
73  break;
74  case AV_PIX_FMT_YUV420P:
75  switch (st->codec->chroma_sample_location) {
76  case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break;
77  case AVCHROMA_LOC_LEFT: colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break;
78  default: colorspace = " C420jpeg XYSCSS=420JPEG"; break;
79  }
80  break;
81  case AV_PIX_FMT_YUV422P:
82  colorspace = " C422 XYSCSS=422";
83  break;
84  case AV_PIX_FMT_YUV444P:
85  colorspace = " C444 XYSCSS=444";
86  break;
88  colorspace = " C420p9 XYSCSS=420P9";
89  break;
91  colorspace = " C422p9 XYSCSS=422P9";
92  break;
94  colorspace = " C444p9 XYSCSS=444P9";
95  break;
97  colorspace = " C420p10 XYSCSS=420P10";
98  break;
100  colorspace = " C422p10 XYSCSS=422P10";
101  break;
103  colorspace = " C444p10 XYSCSS=444P10";
104  break;
106  colorspace = " C420p12 XYSCSS=420P12";
107  break;
109  colorspace = " C422p12 XYSCSS=422P12";
110  break;
112  colorspace = " C444p12 XYSCSS=444P12";
113  break;
115  colorspace = " C420p14 XYSCSS=420P14";
116  break;
118  colorspace = " C422p14 XYSCSS=422P14";
119  break;
121  colorspace = " C444p14 XYSCSS=444P14";
122  break;
124  colorspace = " C420p16 XYSCSS=420P16";
125  break;
127  colorspace = " C422p16 XYSCSS=422P16";
128  break;
130  colorspace = " C444p16 XYSCSS=444P16";
131  break;
132  }
133 
134  /* construct stream header, if this is the first frame */
135  n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
136  Y4M_MAGIC, width, height, raten, rated, inter,
137  aspectn, aspectd, colorspace);
138 
139  return n;
140 }
141 
142 static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
143 {
144  AVStream *st = s->streams[pkt->stream_index];
145  AVIOContext *pb = s->pb;
146  AVPicture *picture, picture_tmp;
147  int* first_pkt = s->priv_data;
148  int width, height, h_chroma_shift, v_chroma_shift;
149  int i;
150  char buf2[Y4M_LINE_MAX + 1];
151  char buf1[20];
152  uint8_t *ptr, *ptr1, *ptr2;
153 
154  memcpy(&picture_tmp, pkt->data, sizeof(AVPicture));
155  picture = &picture_tmp;
156 
157  /* for the first packet we have to output the header as well */
158  if (*first_pkt) {
159  *first_pkt = 0;
160  if (yuv4_generate_header(s, buf2) < 0) {
161  av_log(s, AV_LOG_ERROR,
162  "Error. YUV4MPEG stream header write failed.\n");
163  return AVERROR(EIO);
164  } else {
165  avio_write(pb, buf2, strlen(buf2));
166  }
167  }
168 
169  /* construct frame header */
170 
171  snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
172  avio_write(pb, buf1, strlen(buf1));
173 
174  width = st->codec->width;
175  height = st->codec->height;
176 
177  ptr = picture->data[0];
178 
179  switch (st->codec->pix_fmt) {
180  case AV_PIX_FMT_GRAY8:
181  case AV_PIX_FMT_YUV411P:
182  case AV_PIX_FMT_YUV420P:
183  case AV_PIX_FMT_YUV422P:
184  case AV_PIX_FMT_YUV444P:
185  break;
186  case AV_PIX_FMT_GRAY16:
187  case AV_PIX_FMT_YUV420P9:
188  case AV_PIX_FMT_YUV422P9:
189  case AV_PIX_FMT_YUV444P9:
202  width *= 2;
203  break;
204  default:
205  av_log(s, AV_LOG_ERROR, "The pixel format '%s' is not supported.\n",
207  return AVERROR(EINVAL);
208  }
209 
210  for (i = 0; i < height; i++) {
211  avio_write(pb, ptr, width);
212  ptr += picture->linesize[0];
213  }
214 
215  if (st->codec->pix_fmt != AV_PIX_FMT_GRAY8 &&
216  st->codec->pix_fmt != AV_PIX_FMT_GRAY16) {
217  // Adjust for smaller Cb and Cr planes
218  av_pix_fmt_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
219  &v_chroma_shift);
220  width >>= h_chroma_shift;
221  height >>= v_chroma_shift;
222 
223  ptr1 = picture->data[1];
224  ptr2 = picture->data[2];
225  for (i = 0; i < height; i++) { /* Cb */
226  avio_write(pb, ptr1, width);
227  ptr1 += picture->linesize[1];
228  }
229  for (i = 0; i < height; i++) { /* Cr */
230  avio_write(pb, ptr2, width);
231  ptr2 += picture->linesize[2];
232  }
233  }
234 
235  return 0;
236 }
237 
238 static int yuv4_write_header(AVFormatContext *s)
239 {
240  int *first_pkt = s->priv_data;
241 
242  if (s->nb_streams != 1)
243  return AVERROR(EIO);
244 
245  if (s->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) {
246  av_log(s, AV_LOG_ERROR, "ERROR: Only rawvideo supported.\n");
247  return AVERROR_INVALIDDATA;
248  }
249 
250  switch (s->streams[0]->codec->pix_fmt) {
251  case AV_PIX_FMT_YUV411P:
252  av_log(s, AV_LOG_WARNING, "Warning: generating rarely used 4:1:1 YUV "
253  "stream, some mjpegtools might not work.\n");
254  break;
255  case AV_PIX_FMT_GRAY8:
256  case AV_PIX_FMT_GRAY16:
257  case AV_PIX_FMT_YUV420P:
258  case AV_PIX_FMT_YUV422P:
259  case AV_PIX_FMT_YUV444P:
260  break;
261  case AV_PIX_FMT_YUV420P9:
262  case AV_PIX_FMT_YUV422P9:
263  case AV_PIX_FMT_YUV444P9:
277  av_log(s, AV_LOG_ERROR, "'%s' is not a official yuv4mpegpipe pixel format. "
278  "Use '-strict -1' to encode to this pixel format.\n",
280  return AVERROR(EINVAL);
281  }
282  av_log(s, AV_LOG_WARNING, "Warning: generating non standard YUV stream. "
283  "Mjpegtools will not work.\n");
284  break;
285  default:
286  av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg can only handle "
287  "yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. "
288  "And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, "
289  "yuv444p10, yuv422p10, yuv420p10, "
290  "yuv444p12, yuv422p12, yuv420p12, "
291  "yuv444p14, yuv422p14, yuv420p14, "
292  "yuv444p16, yuv422p16, yuv420p16 "
293  "and gray16 pixel formats. "
294  "Use -pix_fmt to select one.\n");
295  return AVERROR(EIO);
296  }
297 
298  *first_pkt = 1;
299  return 0;
300 }
301 
302 AVOutputFormat ff_yuv4mpegpipe_muxer = {
303  .name = "yuv4mpegpipe",
304  .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
305  .extensions = "y4m",
306  .priv_data_size = sizeof(int),
307  .audio_codec = AV_CODEC_ID_NONE,
308  .video_codec = AV_CODEC_ID_RAWVIDEO,
309  .write_header = yuv4_write_header,
310  .write_packet = yuv4_write_packet,
312 };
313 #endif
314 
315 /* Header size increased to allow room for optional flags */
316 #define MAX_YUV4_HEADER 80
317 #define MAX_FRAME_HEADER 80
318 
320 {
321  char header[MAX_YUV4_HEADER + 10]; // Include headroom for
322  // the longest option
323  char *tokstart, *tokend, *header_end, interlaced = '?';
324  int i;
325  AVIOContext *pb = s->pb;
326  int width = -1, height = -1, raten = 0,
327  rated = 0, aspectn = 0, aspectd = 0;
329  enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
330  AVStream *st;
331 
332  for (i = 0; i < MAX_YUV4_HEADER; i++) {
333  header[i] = avio_r8(pb);
334  if (header[i] == '\n') {
335  header[i + 1] = 0x20; // Add a space after last option.
336  // Makes parsing "444" vs "444alpha" easier.
337  header[i + 2] = 0;
338  break;
339  }
340  }
341  if (i == MAX_YUV4_HEADER)
342  return -1;
343  if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)))
344  return -1;
345 
346  header_end = &header[i + 1]; // Include space
347  for (tokstart = &header[strlen(Y4M_MAGIC) + 1];
348  tokstart < header_end; tokstart++) {
349  if (*tokstart == 0x20)
350  continue;
351  switch (*tokstart++) {
352  case 'W': // Width. Required.
353  width = strtol(tokstart, &tokend, 10);
354  tokstart = tokend;
355  break;
356  case 'H': // Height. Required.
357  height = strtol(tokstart, &tokend, 10);
358  tokstart = tokend;
359  break;
360  case 'C': // Color space
361  if (strncmp("420jpeg", tokstart, 7) == 0) {
362  pix_fmt = AV_PIX_FMT_YUV420P;
363  chroma_sample_location = AVCHROMA_LOC_CENTER;
364  } else if (strncmp("420mpeg2", tokstart, 8) == 0) {
365  pix_fmt = AV_PIX_FMT_YUV420P;
366  chroma_sample_location = AVCHROMA_LOC_LEFT;
367  } else if (strncmp("420paldv", tokstart, 8) == 0) {
368  pix_fmt = AV_PIX_FMT_YUV420P;
369  chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
370  } else if (strncmp("420p16", tokstart, 6) == 0) {
371  pix_fmt = AV_PIX_FMT_YUV420P16;
372  } else if (strncmp("422p16", tokstart, 6) == 0) {
373  pix_fmt = AV_PIX_FMT_YUV422P16;
374  } else if (strncmp("444p16", tokstart, 6) == 0) {
375  pix_fmt = AV_PIX_FMT_YUV444P16;
376  } else if (strncmp("420p14", tokstart, 6) == 0) {
377  pix_fmt = AV_PIX_FMT_YUV420P14;
378  } else if (strncmp("422p14", tokstart, 6) == 0) {
379  pix_fmt = AV_PIX_FMT_YUV422P14;
380  } else if (strncmp("444p14", tokstart, 6) == 0) {
381  pix_fmt = AV_PIX_FMT_YUV444P14;
382  } else if (strncmp("420p12", tokstart, 6) == 0) {
383  pix_fmt = AV_PIX_FMT_YUV420P12;
384  } else if (strncmp("422p12", tokstart, 6) == 0) {
385  pix_fmt = AV_PIX_FMT_YUV422P12;
386  } else if (strncmp("444p12", tokstart, 6) == 0) {
387  pix_fmt = AV_PIX_FMT_YUV444P12;
388  } else if (strncmp("420p10", tokstart, 6) == 0) {
389  pix_fmt = AV_PIX_FMT_YUV420P10;
390  } else if (strncmp("422p10", tokstart, 6) == 0) {
391  pix_fmt = AV_PIX_FMT_YUV422P10;
392  } else if (strncmp("444p10", tokstart, 6) == 0) {
393  pix_fmt = AV_PIX_FMT_YUV444P10;
394  } else if (strncmp("420p9", tokstart, 5) == 0) {
395  pix_fmt = AV_PIX_FMT_YUV420P9;
396  } else if (strncmp("422p9", tokstart, 5) == 0) {
397  pix_fmt = AV_PIX_FMT_YUV422P9;
398  } else if (strncmp("444p9", tokstart, 5) == 0) {
399  pix_fmt = AV_PIX_FMT_YUV444P9;
400  } else if (strncmp("420", tokstart, 3) == 0) {
401  pix_fmt = AV_PIX_FMT_YUV420P;
402  chroma_sample_location = AVCHROMA_LOC_CENTER;
403  } else if (strncmp("411", tokstart, 3) == 0) {
404  pix_fmt = AV_PIX_FMT_YUV411P;
405  } else if (strncmp("422", tokstart, 3) == 0) {
406  pix_fmt = AV_PIX_FMT_YUV422P;
407  } else if (strncmp("444alpha", tokstart, 8) == 0 ) {
408  av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 "
409  "YUV4MPEG stream.\n");
410  return -1;
411  } else if (strncmp("444", tokstart, 3) == 0) {
412  pix_fmt = AV_PIX_FMT_YUV444P;
413  } else if (strncmp("mono16", tokstart, 6) == 0) {
414  pix_fmt = AV_PIX_FMT_GRAY16;
415  } else if (strncmp("mono", tokstart, 4) == 0) {
416  pix_fmt = AV_PIX_FMT_GRAY8;
417  } else {
418  av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown "
419  "pixel format.\n");
420  return -1;
421  }
422  while (tokstart < header_end && *tokstart != 0x20)
423  tokstart++;
424  break;
425  case 'I': // Interlace type
426  interlaced = *tokstart++;
427  break;
428  case 'F': // Frame rate
429  sscanf(tokstart, "%d:%d", &raten, &rated); // 0:0 if unknown
430  while (tokstart < header_end && *tokstart != 0x20)
431  tokstart++;
432  break;
433  case 'A': // Pixel aspect
434  sscanf(tokstart, "%d:%d", &aspectn, &aspectd); // 0:0 if unknown
435  while (tokstart < header_end && *tokstart != 0x20)
436  tokstart++;
437  break;
438  case 'X': // Vendor extensions
439  if (strncmp("YSCSS=", tokstart, 6) == 0) {
440  // Older nonstandard pixel format representation
441  tokstart += 6;
442  if (strncmp("420JPEG", tokstart, 7) == 0)
443  alt_pix_fmt = AV_PIX_FMT_YUV420P;
444  else if (strncmp("420MPEG2", tokstart, 8) == 0)
445  alt_pix_fmt = AV_PIX_FMT_YUV420P;
446  else if (strncmp("420PALDV", tokstart, 8) == 0)
447  alt_pix_fmt = AV_PIX_FMT_YUV420P;
448  else if (strncmp("420P9", tokstart, 5) == 0)
449  alt_pix_fmt = AV_PIX_FMT_YUV420P9;
450  else if (strncmp("422P9", tokstart, 5) == 0)
451  alt_pix_fmt = AV_PIX_FMT_YUV422P9;
452  else if (strncmp("444P9", tokstart, 5) == 0)
453  alt_pix_fmt = AV_PIX_FMT_YUV444P9;
454  else if (strncmp("420P10", tokstart, 6) == 0)
455  alt_pix_fmt = AV_PIX_FMT_YUV420P10;
456  else if (strncmp("422P10", tokstart, 6) == 0)
457  alt_pix_fmt = AV_PIX_FMT_YUV422P10;
458  else if (strncmp("444P10", tokstart, 6) == 0)
459  alt_pix_fmt = AV_PIX_FMT_YUV444P10;
460  else if (strncmp("420P12", tokstart, 6) == 0)
461  alt_pix_fmt = AV_PIX_FMT_YUV420P12;
462  else if (strncmp("422P12", tokstart, 6) == 0)
463  alt_pix_fmt = AV_PIX_FMT_YUV422P12;
464  else if (strncmp("444P12", tokstart, 6) == 0)
465  alt_pix_fmt = AV_PIX_FMT_YUV444P12;
466  else if (strncmp("420P14", tokstart, 6) == 0)
467  alt_pix_fmt = AV_PIX_FMT_YUV420P14;
468  else if (strncmp("422P14", tokstart, 6) == 0)
469  alt_pix_fmt = AV_PIX_FMT_YUV422P14;
470  else if (strncmp("444P14", tokstart, 6) == 0)
471  alt_pix_fmt = AV_PIX_FMT_YUV444P14;
472  else if (strncmp("420P16", tokstart, 6) == 0)
473  alt_pix_fmt = AV_PIX_FMT_YUV420P16;
474  else if (strncmp("422P16", tokstart, 6) == 0)
475  alt_pix_fmt = AV_PIX_FMT_YUV422P16;
476  else if (strncmp("444P16", tokstart, 6) == 0)
477  alt_pix_fmt = AV_PIX_FMT_YUV444P16;
478  else if (strncmp("411", tokstart, 3) == 0)
479  alt_pix_fmt = AV_PIX_FMT_YUV411P;
480  else if (strncmp("422", tokstart, 3) == 0)
481  alt_pix_fmt = AV_PIX_FMT_YUV422P;
482  else if (strncmp("444", tokstart, 3) == 0)
483  alt_pix_fmt = AV_PIX_FMT_YUV444P;
484  }
485  while (tokstart < header_end && *tokstart != 0x20)
486  tokstart++;
487  break;
488  }
489  }
490 
491  if (width == -1 || height == -1) {
492  av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
493  return -1;
494  }
495 
496  if (pix_fmt == AV_PIX_FMT_NONE) {
497  if (alt_pix_fmt == AV_PIX_FMT_NONE)
498  pix_fmt = AV_PIX_FMT_YUV420P;
499  else
500  pix_fmt = alt_pix_fmt;
501  }
502 
503  if (raten <= 0 || rated <= 0) {
504  // Frame rate unknown
505  raten = 25;
506  rated = 1;
507  }
508 
509  if (aspectn == 0 && aspectd == 0) {
510  // Pixel aspect unknown
511  aspectd = 1;
512  }
513 
514  st = avformat_new_stream(s, NULL);
515  if (!st)
516  return AVERROR(ENOMEM);
517  st->codec->width = width;
518  st->codec->height = height;
519  av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
520  avpriv_set_pts_info(st, 64, rated, raten);
521  st->codec->pix_fmt = pix_fmt;
524  st->sample_aspect_ratio = (AVRational){ aspectn, aspectd };
525  st->codec->chroma_sample_location = chroma_sample_location;
526 
527  switch (interlaced){
528  case 'p':
530  break;
531  case 't':
533  break;
534  case 'b':
536  break;
537  case 'm':
538  av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed "
539  "interlaced and non-interlaced frames.\n");
540  case '?':
542  break;
543  default:
544  av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
545  return AVERROR(EINVAL);
546  }
547 
548  return 0;
549 }
550 
552 {
553  int i;
554  char header[MAX_FRAME_HEADER+1];
555  int packet_size, width, height, ret;
556  AVStream *st = s->streams[0];
557 
558  for (i = 0; i < MAX_FRAME_HEADER; i++) {
559  header[i] = avio_r8(s->pb);
560  if (header[i] == '\n') {
561  header[i + 1] = 0;
562  break;
563  }
564  }
565  if (s->pb->error)
566  return s->pb->error;
567  else if (s->pb->eof_reached)
568  return AVERROR_EOF;
569  else if (i == MAX_FRAME_HEADER)
570  return AVERROR_INVALIDDATA;
571 
572  if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC)))
573  return AVERROR_INVALIDDATA;
574 
575  width = st->codec->width;
576  height = st->codec->height;
577 
578  packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
579  if (packet_size < 0)
580  return packet_size;
581 
582  ret = av_get_packet(s->pb, pkt, packet_size);
583  if (ret < 0)
584  return ret;
585  else if (ret != packet_size)
586  return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO);
587 
588  pkt->stream_index = 0;
589  return 0;
590 }
591 
592 static int yuv4_probe(AVProbeData *pd)
593 {
594  /* check file header */
595  if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC) - 1) == 0)
596  return AVPROBE_SCORE_MAX;
597  else
598  return 0;
599 }
600 
601 #if CONFIG_YUV4MPEGPIPE_DEMUXER
602 AVInputFormat ff_yuv4mpegpipe_demuxer = {
603  .name = "yuv4mpegpipe",
604  .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
605  .read_probe = yuv4_probe,
606  .read_header = yuv4_read_header,
607  .read_packet = yuv4_read_packet,
608  .extensions = "y4m",
609 };
610 #endif
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define MAX_FRAME_HEADER
Definition: yuv4mpeg.c:317
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:287
mpeg2/4, h264 default
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
AVFrame * coded_frame
the picture in the bitstream
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
static int write_packet(AVFormatContext *s, AVPacket *pkt)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
int num
numerator
Definition: rational.h:44
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:282
AVChromaLocation
X X 3 4 X X are luma samples, 1 2 1-6 are possible chroma positions X X 5 6 X 0 is undefined/unknown ...
four components are given, that&#39;s all.
static int yuv4_probe(AVProbeData *pd)
Definition: yuv4mpeg.c:592
#define Y4M_LINE_MAX
Definition: yuv4mpeg.c:29
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Format I/O context.
Definition: avformat.h:944
uint8_t
uint8_t * data[AV_NUM_DATA_POINTERS]
static AVPacket pkt
Definition: demuxing.c:56
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
mpeg1, jpeg, h263
#define Y4M_MAGIC
Definition: yuv4mpeg.c:27
uint8_t * data
#define AVERROR_EOF
End of file.
Definition: error.h:55
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:290
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:283
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#define MAX_YUV4_HEADER
Definition: yuv4mpeg.c:316
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:1806
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define FF_COMPLIANCE_NORMAL
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:281
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:277
struct AVRational AVRational
rational number numerator/denominator
#define Y4M_FRAME_MAGIC
Definition: yuv4mpeg.c:28
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:266
ret
Definition: avfilter.c:821
int width
picture width / height.
const char * name
Definition: avformat.h:378
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:278
Stream structure.
Definition: avformat.h:643
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:288
NULL
Definition: eval.c:55
static int width
Definition: tests/utils.c:158
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:285
enum AVMediaType codec_type
enum AVCodecID codec_id
AVIOContext * pb
I/O context.
Definition: avformat.h:977
static int yuv4_read_header(AVFormatContext *s)
Definition: yuv4mpeg.c:319
#define AVFMT_RAWPICTURE
Format wants AVPicture structure for raw picture data.
Definition: avformat.h:348
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:279
synthesis window for stochastic i
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:276
#define snprintf
Definition: snprintf.h:34
int error
contains the error code or 0 if no error happened
Definition: avio.h:102
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:286
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:280
static int flags
Definition: cpu.c:23
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:284
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
Main libavformat public API header.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
Y , 8bpp.
Definition: pixfmt.h:76
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:75
int den
denominator
Definition: rational.h:45
int eof_reached
true if eof reached
Definition: avio.h:96
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
void * priv_data
Format private data.
Definition: avformat.h:964
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:49
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:470
enum AVFieldOrder field_order
Field order.
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: yuv4mpeg.c:551
enum AVColorSpace colorspace
Definition: dirac.c:98
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1700
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:289