Libav
v4l2.c
Go to the documentation of this file.
1 /*
2  * Video4Linux2 grab interface
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * Copyright (c) 2006 Luca Abeni
5  *
6  * Part of this file is based on the V4L2 video capture example
7  * (http://v4l2spec.bytesex.org/v4l2spec/capture.c)
8  *
9  * Thanks to Michael Niedermayer for providing the mapping between
10  * V4L2_PIX_FMT_* and AV_PIX_FMT_*
11  *
12  *
13  * This file is part of Libav.
14  *
15  * Libav is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU Lesser General Public
17  * License as published by the Free Software Foundation; either
18  * version 2.1 of the License, or (at your option) any later version.
19  *
20  * Libav is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with Libav; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 
30 #undef __STRICT_ANSI__ //workaround due to broken kernel headers
31 #include "config.h"
32 #include "libavformat/avformat.h"
33 #include "libavformat/internal.h"
34 #include <unistd.h>
35 #include <fcntl.h>
36 #include <sys/ioctl.h>
37 #include <sys/mman.h>
38 #include <sys/time.h>
39 #include <poll.h>
40 #if HAVE_SYS_VIDEOIO_H
41 #include <sys/videoio.h>
42 #else
43 #include <linux/videodev2.h>
44 #endif
45 #include "libavutil/atomic.h"
46 #include "libavutil/avassert.h"
47 #include "libavutil/imgutils.h"
48 #include "libavutil/internal.h"
49 #include "libavutil/log.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/parseutils.h"
52 #include "libavutil/pixdesc.h"
53 #include "libavutil/avstring.h"
54 #include "libavutil/mathematics.h"
55 
56 static const int desired_video_buffers = 256;
57 
58 #define V4L_ALLFORMATS 3
59 #define V4L_RAWFORMATS 1
60 #define V4L_COMPFORMATS 2
61 
62 struct video_data {
63  AVClass *class;
64  int fd;
65  int frame_format; /* V4L2_PIX_FMT_* */
66  int width, height;
68  int timeout;
71 
72  int buffers;
73  volatile int buffers_queued;
74  void **buf_start;
75  unsigned int *buf_len;
76  char *standard;
77  int channel;
78  char *video_size;
80  char *pixel_format;
82  char *framerate;
83 };
84 
85 struct buff_data {
86  struct video_data *s;
87  int index;
88  int fd;
89 };
90 
91 struct fmt_map {
92  enum AVPixelFormat ff_fmt;
94  uint32_t v4l2_fmt;
95 };
96 
97 static struct fmt_map fmt_conversion_table[] = {
98  //ff_fmt codec_id v4l2_fmt
99  { AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420 },
100  { AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P },
101  { AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV },
102  { AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY },
103  { AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
104  { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410 },
105  { AV_PIX_FMT_RGB555, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555 },
106  { AV_PIX_FMT_RGB565, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565 },
107  { AV_PIX_FMT_BGR24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24 },
108  { AV_PIX_FMT_RGB24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24 },
109  { AV_PIX_FMT_BGRA, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32 },
110  { AV_PIX_FMT_GRAY8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY },
111  { AV_PIX_FMT_NV12, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12 },
112  { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_MJPEG },
113  { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG },
114 #ifdef V4L2_PIX_FMT_H264
115  { AV_PIX_FMT_NONE, AV_CODEC_ID_H264, V4L2_PIX_FMT_H264 },
116 #endif
117 };
118 
120 {
121  struct v4l2_capability cap;
122  int fd;
123  int res, err;
124  int flags = O_RDWR;
125  char errbuf[128];
126 
127  if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
128  flags |= O_NONBLOCK;
129  }
130 
131  fd = avpriv_open(ctx->filename, flags);
132  if (fd < 0) {
133  err = AVERROR(errno);
134  av_strerror(err, errbuf, sizeof(errbuf));
135 
136  av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
137  ctx->filename, errbuf);
138 
139  return err;
140  }
141 
142  res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
143  if (res < 0) {
144  err = AVERROR(errno);
145  av_strerror(err, errbuf, sizeof(errbuf));
146  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
147  errbuf);
148 
149  goto fail;
150  }
151 
152  av_log(ctx, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n",
153  fd, cap.capabilities);
154 
155  if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
156  av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
157  err = AVERROR(ENODEV);
158 
159  goto fail;
160  }
161 
162  if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
163  av_log(ctx, AV_LOG_ERROR,
164  "The device does not support the streaming I/O method.\n");
165  err = AVERROR(ENOSYS);
166 
167  goto fail;
168  }
169 
170  return fd;
171 
172 fail:
173  close(fd);
174  return err;
175 }
176 
177 static int device_init(AVFormatContext *ctx, int *width, int *height,
178  uint32_t pix_fmt)
179 {
180  struct video_data *s = ctx->priv_data;
181  int fd = s->fd;
182  struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
183  struct v4l2_pix_format *pix = &fmt.fmt.pix;
184 
185  int res;
186 
187  pix->width = *width;
188  pix->height = *height;
189  pix->pixelformat = pix_fmt;
190  pix->field = V4L2_FIELD_ANY;
191 
192  res = ioctl(fd, VIDIOC_S_FMT, &fmt);
193 
194  if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
195  av_log(ctx, AV_LOG_INFO,
196  "The V4L2 driver changed the video from %dx%d to %dx%d\n",
197  *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);
198  *width = fmt.fmt.pix.width;
199  *height = fmt.fmt.pix.height;
200  }
201 
202  if (pix_fmt != fmt.fmt.pix.pixelformat) {
203  av_log(ctx, AV_LOG_DEBUG,
204  "The V4L2 driver changed the pixel format "
205  "from 0x%08X to 0x%08X\n",
206  pix_fmt, fmt.fmt.pix.pixelformat);
207  res = -1;
208  }
209 
210  if (fmt.fmt.pix.field == V4L2_FIELD_INTERLACED) {
211  av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode");
212  s->interlaced = 1;
213  }
214 
215  return res;
216 }
217 
218 static int first_field(int fd)
219 {
220  int res;
221  v4l2_std_id std;
222 
223  res = ioctl(fd, VIDIOC_G_STD, &std);
224  if (res < 0) {
225  return 0;
226  }
227  if (std & V4L2_STD_NTSC) {
228  return 0;
229  }
230 
231  return 1;
232 }
233 
234 static uint32_t fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id)
235 {
236  int i;
237 
238  for (i = 0; i < FF_ARRAY_ELEMS(fmt_conversion_table); i++) {
239  if ((codec_id == AV_CODEC_ID_NONE ||
240  fmt_conversion_table[i].codec_id == codec_id) &&
241  (pix_fmt == AV_PIX_FMT_NONE ||
242  fmt_conversion_table[i].ff_fmt == pix_fmt)) {
243  return fmt_conversion_table[i].v4l2_fmt;
244  }
245  }
246 
247  return 0;
248 }
249 
250 static enum AVPixelFormat fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id)
251 {
252  int i;
253 
254  for (i = 0; i < FF_ARRAY_ELEMS(fmt_conversion_table); i++) {
255  if (fmt_conversion_table[i].v4l2_fmt == v4l2_fmt &&
256  fmt_conversion_table[i].codec_id == codec_id) {
257  return fmt_conversion_table[i].ff_fmt;
258  }
259  }
260 
261  return AV_PIX_FMT_NONE;
262 }
263 
264 static enum AVCodecID fmt_v4l2codec(uint32_t v4l2_fmt)
265 {
266  int i;
267 
268  for (i = 0; i < FF_ARRAY_ELEMS(fmt_conversion_table); i++) {
269  if (fmt_conversion_table[i].v4l2_fmt == v4l2_fmt) {
270  return fmt_conversion_table[i].codec_id;
271  }
272  }
273 
274  return AV_CODEC_ID_NONE;
275 }
276 
277 #if HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE
278 static void list_framesizes(AVFormatContext *ctx, int fd, uint32_t pixelformat)
279 {
280  struct v4l2_frmsizeenum vfse = { .pixel_format = pixelformat };
281 
282  while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) {
283  switch (vfse.type) {
284  case V4L2_FRMSIZE_TYPE_DISCRETE:
285  av_log(ctx, AV_LOG_INFO, " %ux%u",
286  vfse.discrete.width, vfse.discrete.height);
287  break;
288  case V4L2_FRMSIZE_TYPE_CONTINUOUS:
289  case V4L2_FRMSIZE_TYPE_STEPWISE:
290  av_log(ctx, AV_LOG_INFO, " {%u-%u, %u}x{%u-%u, %u}",
291  vfse.stepwise.min_width,
292  vfse.stepwise.max_width,
293  vfse.stepwise.step_width,
294  vfse.stepwise.min_height,
295  vfse.stepwise.max_height,
296  vfse.stepwise.step_height);
297  }
298  vfse.index++;
299  }
300 }
301 #endif
302 
303 static void list_formats(AVFormatContext *ctx, int fd, int type)
304 {
305  struct v4l2_fmtdesc vfd = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
306 
307  while(!ioctl(fd, VIDIOC_ENUM_FMT, &vfd)) {
308  enum AVCodecID codec_id = fmt_v4l2codec(vfd.pixelformat);
309  enum AVPixelFormat pix_fmt = fmt_v4l2ff(vfd.pixelformat, codec_id);
310 
311  vfd.index++;
312 
313  if (!(vfd.flags & V4L2_FMT_FLAG_COMPRESSED) &&
314  type & V4L_RAWFORMATS) {
315  const char *fmt_name = av_get_pix_fmt_name(pix_fmt);
316  av_log(ctx, AV_LOG_INFO, "R : %9s : %20s :",
317  fmt_name ? fmt_name : "Unsupported",
318  vfd.description);
319  } else if (vfd.flags & V4L2_FMT_FLAG_COMPRESSED &&
320  type & V4L_COMPFORMATS) {
321  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
322  av_log(ctx, AV_LOG_INFO, "C : %9s : %20s :",
323  desc ? desc->name : "Unsupported",
324  vfd.description);
325  } else {
326  continue;
327  }
328 
329 #ifdef V4L2_FMT_FLAG_EMULATED
330  if (vfd.flags & V4L2_FMT_FLAG_EMULATED) {
331  av_log(ctx, AV_LOG_WARNING, "%s", "Emulated");
332  continue;
333  }
334 #endif
335 #if HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE
336  list_framesizes(ctx, fd, vfd.pixelformat);
337 #endif
338  av_log(ctx, AV_LOG_INFO, "\n");
339  }
340 }
341 
342 static int mmap_init(AVFormatContext *ctx)
343 {
344  int i, res;
345  struct video_data *s = ctx->priv_data;
346  struct v4l2_requestbuffers req = {
347  .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
348  .count = desired_video_buffers,
349  .memory = V4L2_MEMORY_MMAP
350  };
351 
352  res = ioctl(s->fd, VIDIOC_REQBUFS, &req);
353  if (res < 0) {
354  res = AVERROR(errno);
355  if (res == AVERROR(EINVAL)) {
356  av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
357  } else {
358  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
359  }
360 
361  return res;
362  }
363 
364  if (req.count < 2) {
365  av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
366 
367  return AVERROR(ENOMEM);
368  }
369  s->buffers = req.count;
370  s->buf_start = av_malloc(sizeof(void *) * s->buffers);
371  if (!s->buf_start) {
372  av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
373 
374  return AVERROR(ENOMEM);
375  }
376  s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
377  if (!s->buf_len) {
378  av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
379  av_free(s->buf_start);
380 
381  return AVERROR(ENOMEM);
382  }
383 
384  for (i = 0; i < req.count; i++) {
385  struct v4l2_buffer buf = {
386  .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
387  .index = i,
388  .memory = V4L2_MEMORY_MMAP
389  };
390 
391  res = ioctl(s->fd, VIDIOC_QUERYBUF, &buf);
392  if (res < 0) {
393  res = AVERROR(errno);
394  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
395 
396  return res;
397  }
398 
399  s->buf_len[i] = buf.length;
400  if (s->frame_size > 0 && s->buf_len[i] < s->frame_size) {
401  av_log(ctx, AV_LOG_ERROR,
402  "Buffer len [%d] = %d != %d\n",
403  i, s->buf_len[i], s->frame_size);
404 
405  return -1;
406  }
407  s->buf_start[i] = mmap(NULL, buf.length,
408  PROT_READ | PROT_WRITE, MAP_SHARED,
409  s->fd, buf.m.offset);
410 
411  if (s->buf_start[i] == MAP_FAILED) {
412  char errbuf[128];
413  res = AVERROR(errno);
414  av_strerror(res, errbuf, sizeof(errbuf));
415  av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", errbuf);
416 
417  return res;
418  }
419  }
420 
421  return 0;
422 }
423 
424 static void mmap_release_buffer(void *opaque, uint8_t *data)
425 {
426  struct v4l2_buffer buf = { 0 };
427  int res, fd;
428  struct buff_data *buf_descriptor = opaque;
429  struct video_data *s = buf_descriptor->s;
430  char errbuf[128];
431 
432  buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
433  buf.memory = V4L2_MEMORY_MMAP;
434  buf.index = buf_descriptor->index;
435  fd = buf_descriptor->fd;
436  av_free(buf_descriptor);
437 
438  res = ioctl(fd, VIDIOC_QBUF, &buf);
439  if (res < 0) {
440  av_strerror(AVERROR(errno), errbuf, sizeof(errbuf));
441  av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
442  errbuf);
443  }
445 }
446 
448 {
449  struct video_data *s = ctx->priv_data;
450  struct v4l2_buffer buf = {
451  .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
452  .memory = V4L2_MEMORY_MMAP
453  };
454  struct pollfd p = { .fd = s->fd, .events = POLLIN };
455  int res;
456 
457  res = poll(&p, 1, s->timeout);
458  if (res < 0)
459  return AVERROR(errno);
460 
461  if (!(p.revents & (POLLIN | POLLERR | POLLHUP)))
462  return AVERROR(EAGAIN);
463 
464  /* FIXME: Some special treatment might be needed in case of loss of signal... */
465  while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
466  if (res < 0) {
467  char errbuf[128];
468  if (errno == EAGAIN) {
469  pkt->size = 0;
470 
471  return AVERROR(EAGAIN);
472  }
473  res = AVERROR(errno);
474  av_strerror(res, errbuf, sizeof(errbuf));
475  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
476  errbuf);
477 
478  return res;
479  }
480 
481  if (buf.index >= s->buffers) {
482  av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n");
483  return AVERROR(EINVAL);
484  }
486  // always keep at least one buffer queued
488 
489  if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
490  av_log(ctx, AV_LOG_ERROR,
491  "The v4l2 frame is %d bytes, but %d bytes are expected\n",
492  buf.bytesused, s->frame_size);
493 
494  return AVERROR_INVALIDDATA;
495  }
496 
497  /* Image is at s->buff_start[buf.index] */
498  if (avpriv_atomic_int_get(&s->buffers_queued) == FFMAX(s->buffers / 8, 1)) {
499  /* when we start getting low on queued buffers, fall back on copying data */
500  res = av_new_packet(pkt, buf.bytesused);
501  if (res < 0) {
502  av_log(ctx, AV_LOG_ERROR, "Error allocating a packet.\n");
503  return res;
504  }
505  memcpy(pkt->data, s->buf_start[buf.index], buf.bytesused);
506 
507  res = ioctl(s->fd, VIDIOC_QBUF, &buf);
508  if (res < 0) {
509  res = AVERROR(errno);
510  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
511  av_packet_unref(pkt);
512  return res;
513  }
515  } else {
516  struct buff_data *buf_descriptor;
517 
518  pkt->data = s->buf_start[buf.index];
519  pkt->size = buf.bytesused;
520 
521  buf_descriptor = av_malloc(sizeof(struct buff_data));
522  if (!buf_descriptor) {
523  /* Something went wrong... Since av_malloc() failed, we cannot even
524  * allocate a buffer for memcpying into it
525  */
526  av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
527  res = ioctl(s->fd, VIDIOC_QBUF, &buf);
528 
529  return AVERROR(ENOMEM);
530  }
531  buf_descriptor->fd = s->fd;
532  buf_descriptor->index = buf.index;
533  buf_descriptor->s = s;
534 
535  pkt->buf = av_buffer_create(pkt->data, pkt->size, mmap_release_buffer,
536  buf_descriptor, 0);
537  if (!pkt->buf) {
538  av_freep(&buf_descriptor);
539  return AVERROR(ENOMEM);
540  }
541  }
542  pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
543 
544  return s->buf_len[buf.index];
545 }
546 
547 static int mmap_start(AVFormatContext *ctx)
548 {
549  struct video_data *s = ctx->priv_data;
550  enum v4l2_buf_type type;
551  int i, res, err;
552  char errbuf[128];
553 
554  for (i = 0; i < s->buffers; i++) {
555  struct v4l2_buffer buf = {
556  .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
557  .index = i,
558  .memory = V4L2_MEMORY_MMAP
559  };
560 
561  res = ioctl(s->fd, VIDIOC_QBUF, &buf);
562  if (res < 0) {
563  err = AVERROR(errno);
564  av_strerror(err, errbuf, sizeof(errbuf));
565  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
566  errbuf);
567 
568  return err;
569  }
570  }
571  s->buffers_queued = s->buffers;
572 
573  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
574  res = ioctl(s->fd, VIDIOC_STREAMON, &type);
575  if (res < 0) {
576  err = AVERROR(errno);
577  av_strerror(err, errbuf, sizeof(errbuf));
578  av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n",
579  errbuf);
580 
581  return err;
582  }
583 
584  return 0;
585 }
586 
587 static void mmap_close(struct video_data *s)
588 {
589  enum v4l2_buf_type type;
590  int i;
591 
592  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
593  /* We do not check for the result, because we could
594  * not do anything about it anyway...
595  */
596  ioctl(s->fd, VIDIOC_STREAMOFF, &type);
597  for (i = 0; i < s->buffers; i++) {
598  munmap(s->buf_start[i], s->buf_len[i]);
599  }
600  av_free(s->buf_start);
601  av_free(s->buf_len);
602 }
603 
605 {
606  struct video_data *s = s1->priv_data;
607  struct v4l2_input input = { 0 };
608  struct v4l2_standard standard = { 0 };
609  struct v4l2_streamparm streamparm = { 0 };
610  struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
611  AVRational framerate_q = { 0 };
612  int i, ret;
613 
614  streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
615 
616  if (s->framerate &&
617  (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) {
618  av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n",
619  s->framerate);
620  return ret;
621  }
622 
623  /* set tv video input */
624  input.index = s->channel;
625  if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
626  av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
627  return AVERROR(EIO);
628  }
629 
630  av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
631  s->channel, input.name);
632  if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {
633  av_log(s1, AV_LOG_ERROR,
634  "The V4L2 driver ioctl set input(%d) failed\n",
635  s->channel);
636  return AVERROR(EIO);
637  }
638 
639  if (s->standard) {
640  av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
641  s->standard);
642  /* set tv standard */
643  for(i=0;;i++) {
644  standard.index = i;
645  if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
646  av_log(s1, AV_LOG_ERROR,
647  "The V4L2 driver ioctl set standard(%s) failed\n",
648  s->standard);
649  return AVERROR(EIO);
650  }
651 
652  if (!av_strcasecmp(standard.name, s->standard)) {
653  break;
654  }
655  }
656 
657  av_log(s1, AV_LOG_DEBUG,
658  "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
659  s->standard, (uint64_t)standard.id);
660  if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
661  av_log(s1, AV_LOG_ERROR,
662  "The V4L2 driver ioctl set standard(%s) failed\n",
663  s->standard);
664  return AVERROR(EIO);
665  }
666  }
667 
668  if (framerate_q.num && framerate_q.den) {
669  av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
670  framerate_q.den, framerate_q.num);
671  tpf->numerator = framerate_q.den;
672  tpf->denominator = framerate_q.num;
673 
674  if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {
675  av_log(s1, AV_LOG_ERROR,
676  "ioctl set time per frame(%d/%d) failed\n",
677  framerate_q.den, framerate_q.num);
678  return AVERROR(EIO);
679  }
680 
681  if (framerate_q.num != tpf->denominator ||
682  framerate_q.den != tpf->numerator) {
683  av_log(s1, AV_LOG_INFO,
684  "The driver changed the time per frame from "
685  "%d/%d to %d/%d\n",
686  framerate_q.den, framerate_q.num,
687  tpf->numerator, tpf->denominator);
688  }
689  } else {
690  if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {
691  char errbuf[128];
692  ret = AVERROR(errno);
693  av_strerror(ret, errbuf, sizeof(errbuf));
694  av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",
695  errbuf);
696  return ret;
697  }
698  }
699  s1->streams[0]->avg_frame_rate.num = tpf->denominator;
700  s1->streams[0]->avg_frame_rate.den = tpf->numerator;
701 
702  s->timeout = 100 +
704  (AVRational){1, 1000});
705 
706  return 0;
707 }
708 
709 static uint32_t device_try_init(AVFormatContext *s1,
710  enum AVPixelFormat pix_fmt,
711  int *width,
712  int *height,
713  enum AVCodecID *codec_id)
714 {
715  uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id);
716 
717  if (desired_format == 0 ||
718  device_init(s1, width, height, desired_format) < 0) {
719  int i;
720 
721  desired_format = 0;
722  for (i = 0; i<FF_ARRAY_ELEMS(fmt_conversion_table); i++) {
723  if (s1->video_codec_id == AV_CODEC_ID_NONE ||
724  fmt_conversion_table[i].codec_id == s1->video_codec_id) {
725  desired_format = fmt_conversion_table[i].v4l2_fmt;
726  if (device_init(s1, width, height, desired_format) >= 0) {
727  break;
728  }
729  desired_format = 0;
730  }
731  }
732  }
733 
734  if (desired_format != 0) {
735  *codec_id = fmt_v4l2codec(desired_format);
736  assert(*codec_id != AV_CODEC_ID_NONE);
737  }
738 
739  return desired_format;
740 }
741 
743 {
744  struct video_data *s = s1->priv_data;
745  AVStream *st;
746  int res = 0;
747  uint32_t desired_format;
748  enum AVCodecID codec_id;
750 
751  st = avformat_new_stream(s1, NULL);
752  if (!st)
753  return AVERROR(ENOMEM);
754 
755  s->fd = device_open(s1);
756  if (s->fd < 0)
757  return s->fd;
758 
759  if (s->list_format) {
760  list_formats(s1, s->fd, s->list_format);
761  return AVERROR_EXIT;
762  }
763 
764  avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
765 
766  if (s->video_size &&
767  (res = av_parse_video_size(&s->width, &s->height, s->video_size)) < 0) {
768  av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n",
769  s->video_size);
770  return res;
771  }
772 
773  if (s->pixel_format) {
775 
776  if (codec) {
777  s1->video_codec_id = codec->id;
779  }
780 
781  pix_fmt = av_get_pix_fmt(s->pixel_format);
782 
783  if (pix_fmt == AV_PIX_FMT_NONE && !codec) {
784  av_log(s1, AV_LOG_ERROR, "No such input format: %s.\n",
785  s->pixel_format);
786 
787  return AVERROR(EINVAL);
788  }
789  }
790 
791  if (!s->width && !s->height) {
792  struct v4l2_format fmt;
793 
795  "Querying the device for the current frame size\n");
796  fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
797  if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
798  char errbuf[128];
799  res = AVERROR(errno);
800  av_strerror(res, errbuf, sizeof(errbuf));
801  av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n",
802  errbuf);
803  return res;
804  }
805 
806  s->width = fmt.fmt.pix.width;
807  s->height = fmt.fmt.pix.height;
809  "Setting frame size to %dx%d\n", s->width, s->height);
810  }
811 
812  desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height,
813  &codec_id);
814  if (desired_format == 0) {
815  av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
816  "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt);
817  close(s->fd);
818 
819  return AVERROR(EIO);
820  }
821 
822  if ((res = av_image_check_size(s->width, s->height, 0, s1) < 0))
823  return res;
824 
825  s->frame_format = desired_format;
826 
827  if ((res = v4l2_set_parameters(s1) < 0))
828  return res;
829 
830  st->codecpar->format = fmt_v4l2ff(desired_format, codec_id);
832  s->width, s->height, 1);
833 
834  if ((res = mmap_init(s1)) ||
835  (res = mmap_start(s1)) < 0) {
836  close(s->fd);
837  return res;
838  }
839 
840  s->top_field_first = first_field(s->fd);
841 
843  st->codecpar->codec_id = codec_id;
844  if (codec_id == AV_CODEC_ID_RAWVIDEO)
845  st->codecpar->codec_tag =
847  st->codecpar->width = s->width;
848  st->codecpar->height = s->height;
849  st->codecpar->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
850 
851  return 0;
852 }
853 
855 {
856 #if FF_API_CODED_FRAME && FF_API_LAVF_AVCTX
858  struct video_data *s = s1->priv_data;
859  AVFrame *frame = s1->streams[0]->codec->coded_frame;
861 #endif
862  int res;
863 
864  if ((res = mmap_read_frame(s1, pkt)) < 0) {
865  return res;
866  }
867 
868 #if FF_API_CODED_FRAME && FF_API_LAVF_AVCTX
870  if (frame && s->interlaced) {
871  frame->interlaced_frame = 1;
872  frame->top_field_first = s->top_field_first;
873  }
875 #endif
876 
877  return pkt->size;
878 }
879 
881 {
882  struct video_data *s = s1->priv_data;
883 
885  av_log(s1, AV_LOG_WARNING, "Some buffers are still owned by the caller on "
886  "close.\n");
887 
888  mmap_close(s);
889 
890  close(s->fd);
891  return 0;
892 }
893 
894 #define OFFSET(x) offsetof(struct video_data, x)
895 #define DEC AV_OPT_FLAG_DECODING_PARAM
896 static const AVOption options[] = {
897  { "standard", "TV standard, used only by analog frame grabber", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC },
898  { "channel", "TV channel, used only by frame grabber", OFFSET(channel), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
899  { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
900  { "pixel_format", "Preferred pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
901  { "input_format", "Preferred pixel format (for raw video) or codec name", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
902  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
903  { "list_formats", "List available formats and exit", OFFSET(list_format), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC, "list_formats" },
904  { "all", "Show all available formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_ALLFORMATS }, 0, INT_MAX, DEC, "list_formats" },
905  { "raw", "Show only non-compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_RAWFORMATS }, 0, INT_MAX, DEC, "list_formats" },
906  { "compressed", "Show only compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.i64 = V4L_COMPFORMATS }, 0, INT_MAX, DEC, "list_formats" },
907  { NULL },
908 };
909 
910 static const AVClass v4l2_class = {
911  .class_name = "V4L2 indev",
912  .item_name = av_default_item_name,
913  .option = options,
914  .version = LIBAVUTIL_VERSION_INT,
915 };
916 
918  .name = "video4linux2",
919  .long_name = NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
920  .priv_data_size = sizeof(struct video_data),
921  .read_header = v4l2_read_header,
922  .read_packet = v4l2_read_packet,
923  .read_close = v4l2_read_close,
924  .flags = AVFMT_NOFILE,
925  .priv_class = &v4l2_class,
926 };
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:78
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define avpriv_atomic_int_add_and_fetch
Definition: atomic_gcc.h:42
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int frame_size
Definition: v4l2.c:67
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:127
AVOption.
Definition: opt.h:234
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:100
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
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.
Definition: utils.c:2986
const char * desc
Definition: nvenc.c:101
char * pixel_format
Set by a private option.
Definition: v4l2.c:80
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
enum AVCodecID codec_id
Definition: v4l2.c:93
#define FF_ARRAY_ELEMS(a)
unsigned int * buf_len
Definition: v4l2.c:75
AVCodec.
Definition: avcodec.h:3120
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
Format I/O context.
Definition: avformat.h:940
int channel
Definition: v4l2.c:77
volatile int buffers_queued
Definition: v4l2.c:73
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:39
static uint32_t device_try_init(AVFormatContext *s1, enum AVPixelFormat pix_fmt, int *width, int *height, enum AVCodecID *codec_id)
Definition: v4l2.c:709
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1054
uint8_t
int width
Video only.
Definition: avcodec.h:3525
static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
Definition: v4l2.c:447
AVOptions.
unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt)
Return a value representing the fourCC code associated to the pixel format pix_fmt, or 0 if no associated fourCC code can be found.
Definition: raw.c:176
enum AVStreamParseType need_parsing
Definition: avformat.h:879
static int mmap_start(AVFormatContext *ctx)
Definition: v4l2.c:547
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2648
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
static void list_formats(AVFormatContext *ctx, int fd, int type)
Definition: v4l2.c:303
int avpriv_open(const char *filename, int flags,...)
A wrapper for open() setting O_CLOEXEC.
Definition: file_open.c:66
char * standard
Definition: v4l2.c:76
static const int desired_video_buffers
Definition: v4l2.c:56
const char data[16]
Definition: mxf.c:70
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1051
uint8_t * data
Definition: avcodec.h:1346
static int flags
Definition: log.c:50
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:140
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:263
int frame_format
Definition: v4l2.c:65
static int device_open(AVFormatContext *ctx)
Definition: v4l2.c:119
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1094
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:99
int height
Definition: v4l2.c:66
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:84
int interlaced
Definition: v4l2.c:69
enum AVCodecID id
Definition: avcodec.h:3134
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:323
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:193
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2.c:854
#define AVERROR(e)
Definition: error.h:43
#define avpriv_atomic_int_get
Definition: atomic_gcc.h:28
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:92
static const AVOption options[]
Definition: v4l2.c:896
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
int fd
Definition: v4l2.c:88
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1329
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:86
void ** buf_start
Definition: v4l2.c:74
simple assert() macros that are a bit more flexible than ISO C assert().
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:28
#define OFFSET(x)
Definition: v4l2.c:894
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:781
static uint32_t fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id)
Definition: v4l2.c:234
#define FFMAX(a, b)
Definition: common.h:64
#define fail()
Definition: checkasm.h:80
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2462
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63
Only parse headers, do not repack.
Definition: avformat.h:658
int bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3512
common internal API header
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:223
char filename[1024]
input or output filename
Definition: avformat.h:1016
int av_strcasecmp(const char *a, const char *b)
Definition: avstring.c:156
enum AVCodecID codec_id
Definition: avconv_vaapi.c:149
static void mmap_close(struct video_data *s)
Definition: v4l2.c:587
AVFormatContext * ctx
Definition: movenc.c:48
static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t pix_fmt)
Definition: v4l2.c:177
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
enum AVPixelFormat pix_fmt
Definition: movenc.c:853
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:52
int list_format
Set by a private option.
Definition: v4l2.c:81
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static enum AVPixelFormat fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id)
Definition: v4l2.c:250
Stream structure.
Definition: avformat.h:705
char * video_size
String describing video size, set by a private option.
Definition: v4l2.c:78
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:135
#define V4L_ALLFORMATS
Definition: v4l2.c:58
av_default_item_name
Definition: dnxhdenc.c:55
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:347
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
int fd
Definition: v4l2.c:64
struct video_data * s
Definition: v4l2.c:86
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:65
Describe the class of an AVClass context structure.
Definition: log.h:34
int timeout
Definition: v4l2.c:68
rational number numerator/denominator
Definition: rational.h:43
int width
Definition: v4l2.c:66
Definition: v4l2.c:91
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:588
misc parsing utilities
static int mmap_init(AVFormatContext *ctx)
Definition: v4l2.c:342
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:580
static const AVClass v4l2_class
Definition: v4l2.c:910
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:2034
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:23
int index
Definition: v4l2.c:87
Main libavformat public API header.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
Y , 8bpp.
Definition: pixfmt.h:67
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
int buffers
Definition: v4l2.c:72
static int v4l2_set_parameters(AVFormatContext *s1)
Definition: v4l2.c:604
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:412
char * framerate
Set by a private option.
Definition: v4l2.c:82
#define V4L_COMPFORMATS
Definition: v4l2.c:60
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:251
static enum AVCodecID fmt_v4l2codec(uint32_t v4l2_fmt)
Definition: v4l2.c:264
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:66
int den
denominator
Definition: rational.h:45
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
#define V4L_RAWFORMATS
Definition: v4l2.c:59
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:268
static int v4l2_read_header(AVFormatContext *s1)
Definition: v4l2.c:742
void * priv_data
Format private data.
Definition: avformat.h:968
enum AVPixelFormat ff_fmt
Definition: v4l2.c:92
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:250
AVInputFormat ff_v4l2_demuxer
Definition: v4l2.c:917
#define DEC
Definition: v4l2.c:895
static int v4l2_read_close(AVFormatContext *s1)
Definition: v4l2.c:880
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:529
uint32_t v4l2_fmt
Definition: v4l2.c:94
static void mmap_release_buffer(void *opaque, uint8_t *data)
Definition: v4l2.c:424
AVCodecParameters * codecpar
Definition: avformat.h:831
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3487
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:1716
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:1704
static int first_field(int fd)
Definition: v4l2.c:218
static struct fmt_map fmt_conversion_table[]
Definition: v4l2.c:97
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
This structure stores compressed data.
Definition: avcodec.h:1323
Definition: v4l2.c:85
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
int top_field_first
Definition: v4l2.c:70