v4l2.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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 PIX_FMT_*
  11. *
  12. *
  13. * This file is part of FFmpeg.
  14. *
  15. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include "config.h"
  30. #include "avformat.h"
  31. #include <unistd.h>
  32. #include <fcntl.h>
  33. #include <sys/ioctl.h>
  34. #include <sys/mman.h>
  35. #include <sys/time.h>
  36. #include <asm/types.h>
  37. #include <linux/videodev2.h>
  38. #include <time.h>
  39. static const int desired_video_buffers = 256;
  40. enum io_method {
  41. io_read,
  42. io_mmap,
  43. io_userptr
  44. };
  45. struct video_data {
  46. int fd;
  47. int frame_format; /* V4L2_PIX_FMT_* */
  48. enum io_method io_method;
  49. int width, height;
  50. int frame_rate;
  51. int frame_rate_base;
  52. int frame_size;
  53. int top_field_first;
  54. int buffers;
  55. void **buf_start;
  56. unsigned int *buf_len;
  57. };
  58. struct buff_data {
  59. int index;
  60. int fd;
  61. };
  62. struct fmt_map {
  63. enum PixelFormat ff_fmt;
  64. int32_t v4l2_fmt;
  65. };
  66. static struct fmt_map fmt_conversion_table[] = {
  67. {
  68. .ff_fmt = PIX_FMT_YUV420P,
  69. .v4l2_fmt = V4L2_PIX_FMT_YUV420,
  70. },
  71. {
  72. .ff_fmt = PIX_FMT_YUV422P,
  73. .v4l2_fmt = V4L2_PIX_FMT_YUV422P,
  74. },
  75. {
  76. .ff_fmt = PIX_FMT_YUYV422,
  77. .v4l2_fmt = V4L2_PIX_FMT_YUYV,
  78. },
  79. {
  80. .ff_fmt = PIX_FMT_UYVY422,
  81. .v4l2_fmt = V4L2_PIX_FMT_UYVY,
  82. },
  83. {
  84. .ff_fmt = PIX_FMT_YUV411P,
  85. .v4l2_fmt = V4L2_PIX_FMT_YUV411P,
  86. },
  87. {
  88. .ff_fmt = PIX_FMT_YUV410P,
  89. .v4l2_fmt = V4L2_PIX_FMT_YUV410,
  90. },
  91. {
  92. .ff_fmt = PIX_FMT_BGR24,
  93. .v4l2_fmt = V4L2_PIX_FMT_BGR24,
  94. },
  95. {
  96. .ff_fmt = PIX_FMT_RGB24,
  97. .v4l2_fmt = V4L2_PIX_FMT_RGB24,
  98. },
  99. /*
  100. {
  101. .ff_fmt = PIX_FMT_RGB32,
  102. .v4l2_fmt = V4L2_PIX_FMT_BGR32,
  103. },
  104. */
  105. {
  106. .ff_fmt = PIX_FMT_GRAY8,
  107. .v4l2_fmt = V4L2_PIX_FMT_GREY,
  108. },
  109. };
  110. static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
  111. {
  112. struct v4l2_capability cap;
  113. int fd;
  114. int res;
  115. int flags = O_RDWR;
  116. if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
  117. flags |= O_NONBLOCK;
  118. }
  119. fd = open(ctx->filename, flags, 0);
  120. if (fd < 0) {
  121. av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n",
  122. ctx->filename, strerror(errno));
  123. return -1;
  124. }
  125. res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
  126. // ENOIOCTLCMD definition only availble on __KERNEL__
  127. if (res < 0 && errno == 515)
  128. {
  129. av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n");
  130. close(fd);
  131. return -1;
  132. }
  133. if (res < 0) {
  134. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
  135. strerror(errno));
  136. close(fd);
  137. return -1;
  138. }
  139. if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
  140. av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n");
  141. close(fd);
  142. return -1;
  143. }
  144. *capabilities = cap.capabilities;
  145. return fd;
  146. }
  147. static int device_init(AVFormatContext *ctx, int *width, int *height, int pix_fmt)
  148. {
  149. struct video_data *s = ctx->priv_data;
  150. int fd = s->fd;
  151. struct v4l2_format fmt;
  152. int res;
  153. memset(&fmt, 0, sizeof(struct v4l2_format));
  154. fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  155. fmt.fmt.pix.width = *width;
  156. fmt.fmt.pix.height = *height;
  157. fmt.fmt.pix.pixelformat = pix_fmt;
  158. fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
  159. res = ioctl(fd, VIDIOC_S_FMT, &fmt);
  160. if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
  161. av_log(ctx, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);
  162. *width = fmt.fmt.pix.width;
  163. *height = fmt.fmt.pix.height;
  164. }
  165. return res;
  166. }
  167. static int first_field(int fd)
  168. {
  169. int res;
  170. v4l2_std_id std;
  171. res = ioctl(fd, VIDIOC_G_STD, &std);
  172. if (res < 0) {
  173. return 0;
  174. }
  175. if (std & V4L2_STD_NTSC) {
  176. return 0;
  177. }
  178. return 1;
  179. }
  180. static uint32_t fmt_ff2v4l(enum PixelFormat pix_fmt)
  181. {
  182. int i;
  183. for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) {
  184. if (fmt_conversion_table[i].ff_fmt == pix_fmt) {
  185. return fmt_conversion_table[i].v4l2_fmt;
  186. }
  187. }
  188. return 0;
  189. }
  190. static enum PixelFormat fmt_v4l2ff(uint32_t pix_fmt)
  191. {
  192. int i;
  193. for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) {
  194. if (fmt_conversion_table[i].v4l2_fmt == pix_fmt) {
  195. return fmt_conversion_table[i].ff_fmt;
  196. }
  197. }
  198. return -1;
  199. }
  200. static int mmap_init(AVFormatContext *ctx)
  201. {
  202. struct video_data *s = ctx->priv_data;
  203. struct v4l2_requestbuffers req;
  204. int i, res;
  205. memset(&req, 0, sizeof(struct v4l2_requestbuffers));
  206. req.count = desired_video_buffers;
  207. req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  208. req.memory = V4L2_MEMORY_MMAP;
  209. res = ioctl (s->fd, VIDIOC_REQBUFS, &req);
  210. if (res < 0) {
  211. if (errno == EINVAL) {
  212. av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
  213. } else {
  214. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
  215. }
  216. return -1;
  217. }
  218. if (req.count < 2) {
  219. av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
  220. return -1;
  221. }
  222. s->buffers = req.count;
  223. s->buf_start = av_malloc(sizeof(void *) * s->buffers);
  224. if (s->buf_start == NULL) {
  225. av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
  226. return -1;
  227. }
  228. s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
  229. if (s->buf_len == NULL) {
  230. av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
  231. av_free(s->buf_start);
  232. return -1;
  233. }
  234. for (i = 0; i < req.count; i++) {
  235. struct v4l2_buffer buf;
  236. memset(&buf, 0, sizeof(struct v4l2_buffer));
  237. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  238. buf.memory = V4L2_MEMORY_MMAP;
  239. buf.index = i;
  240. res = ioctl (s->fd, VIDIOC_QUERYBUF, &buf);
  241. if (res < 0) {
  242. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
  243. return -1;
  244. }
  245. s->buf_len[i] = buf.length;
  246. if (s->buf_len[i] < s->frame_size) {
  247. av_log(ctx, AV_LOG_ERROR, "Buffer len [%d] = %d != %d\n", i, s->buf_len[i], s->frame_size);
  248. return -1;
  249. }
  250. s->buf_start[i] = mmap (NULL, buf.length,
  251. PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset);
  252. if (s->buf_start[i] == MAP_FAILED) {
  253. av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
  254. return -1;
  255. }
  256. }
  257. return 0;
  258. }
  259. static int read_init(AVFormatContext *ctx)
  260. {
  261. return -1;
  262. }
  263. static void mmap_release_buffer(AVPacket *pkt)
  264. {
  265. struct v4l2_buffer buf;
  266. int res, fd;
  267. struct buff_data *buf_descriptor = pkt->priv;
  268. memset(&buf, 0, sizeof(struct v4l2_buffer));
  269. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  270. buf.memory = V4L2_MEMORY_MMAP;
  271. buf.index = buf_descriptor->index;
  272. fd = buf_descriptor->fd;
  273. av_free(buf_descriptor);
  274. res = ioctl (fd, VIDIOC_QBUF, &buf);
  275. if (res < 0) {
  276. av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
  277. }
  278. pkt->data = NULL;
  279. pkt->size = 0;
  280. }
  281. static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
  282. {
  283. struct video_data *s = ctx->priv_data;
  284. struct v4l2_buffer buf;
  285. struct buff_data *buf_descriptor;
  286. int res;
  287. memset(&buf, 0, sizeof(struct v4l2_buffer));
  288. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  289. buf.memory = V4L2_MEMORY_MMAP;
  290. /* FIXME: Some special treatment might be needed in case of loss of signal... */
  291. while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
  292. if (res < 0) {
  293. if (errno == EAGAIN) {
  294. pkt->size = 0;
  295. return AVERROR(EAGAIN);
  296. }
  297. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
  298. return -1;
  299. }
  300. assert (buf.index < s->buffers);
  301. if (buf.bytesused != s->frame_size) {
  302. av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size);
  303. return -1;
  304. }
  305. /* Image is at s->buff_start[buf.index] */
  306. pkt->data= s->buf_start[buf.index];
  307. pkt->size = buf.bytesused;
  308. pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
  309. pkt->destruct = mmap_release_buffer;
  310. buf_descriptor = av_malloc(sizeof(struct buff_data));
  311. if (buf_descriptor == NULL) {
  312. /* Something went wrong... Since av_malloc() failed, we cannot even
  313. * allocate a buffer for memcopying into it
  314. */
  315. av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
  316. res = ioctl (s->fd, VIDIOC_QBUF, &buf);
  317. return -1;
  318. }
  319. buf_descriptor->fd = s->fd;
  320. buf_descriptor->index = buf.index;
  321. pkt->priv = buf_descriptor;
  322. return s->buf_len[buf.index];
  323. }
  324. static int read_frame(AVFormatContext *ctx, AVPacket *pkt)
  325. {
  326. return -1;
  327. }
  328. static int mmap_start(AVFormatContext *ctx)
  329. {
  330. struct video_data *s = ctx->priv_data;
  331. enum v4l2_buf_type type;
  332. int i, res;
  333. for (i = 0; i < s->buffers; i++) {
  334. struct v4l2_buffer buf;
  335. memset(&buf, 0, sizeof(struct v4l2_buffer));
  336. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  337. buf.memory = V4L2_MEMORY_MMAP;
  338. buf.index = i;
  339. res = ioctl (s->fd, VIDIOC_QBUF, &buf);
  340. if (res < 0) {
  341. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno));
  342. return -1;
  343. }
  344. }
  345. type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  346. res = ioctl (s->fd, VIDIOC_STREAMON, &type);
  347. if (res < 0) {
  348. av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno));
  349. return -1;
  350. }
  351. return 0;
  352. }
  353. static void mmap_close(struct video_data *s)
  354. {
  355. enum v4l2_buf_type type;
  356. int i;
  357. type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  358. /* We do not check for the result, because we could
  359. * not do anything about it anyway...
  360. */
  361. ioctl(s->fd, VIDIOC_STREAMOFF, &type);
  362. for (i = 0; i < s->buffers; i++) {
  363. munmap(s->buf_start[i], s->buf_len[i]);
  364. }
  365. av_free(s->buf_start);
  366. av_free(s->buf_len);
  367. }
  368. static int v4l2_set_parameters( AVFormatContext *s1, AVFormatParameters *ap )
  369. {
  370. struct video_data *s = s1->priv_data;
  371. struct v4l2_input input;
  372. struct v4l2_standard standard;
  373. int i;
  374. if(ap->channel>=0) {
  375. /* set tv video input */
  376. memset (&input, 0, sizeof (input));
  377. input.index = ap->channel;
  378. if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
  379. av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
  380. return AVERROR(EIO);
  381. }
  382. av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
  383. ap->channel, input.name);
  384. if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) {
  385. av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n",
  386. ap->channel);
  387. return AVERROR(EIO);
  388. }
  389. }
  390. if(ap->standard) {
  391. av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
  392. ap->standard );
  393. /* set tv standard */
  394. memset (&standard, 0, sizeof (standard));
  395. for(i=0;;i++) {
  396. standard.index = i;
  397. if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
  398. av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
  399. ap->standard);
  400. return AVERROR(EIO);
  401. }
  402. if(!strcasecmp(standard.name, ap->standard)) {
  403. break;
  404. }
  405. }
  406. av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
  407. ap->standard, standard.id);
  408. if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
  409. av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
  410. ap->standard);
  411. return AVERROR(EIO);
  412. }
  413. }
  414. return 0;
  415. }
  416. static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
  417. {
  418. struct video_data *s = s1->priv_data;
  419. AVStream *st;
  420. int width, height;
  421. int res, frame_rate, frame_rate_base;
  422. uint32_t desired_format, capabilities;
  423. if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
  424. av_log(s1, AV_LOG_ERROR, "Missing/Wrong width, height or framerate\n");
  425. return -1;
  426. }
  427. width = ap->width;
  428. height = ap->height;
  429. frame_rate = ap->time_base.den;
  430. frame_rate_base = ap->time_base.num;
  431. if((unsigned)width > 32767 || (unsigned)height > 32767) {
  432. av_log(s1, AV_LOG_ERROR, "Wrong size %dx%d\n", width, height);
  433. return -1;
  434. }
  435. st = av_new_stream(s1, 0);
  436. if (!st) {
  437. return AVERROR(ENOMEM);
  438. }
  439. av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
  440. s->width = width;
  441. s->height = height;
  442. s->frame_rate = frame_rate;
  443. s->frame_rate_base = frame_rate_base;
  444. capabilities = 0;
  445. s->fd = device_open(s1, &capabilities);
  446. if (s->fd < 0) {
  447. av_free(st);
  448. return AVERROR(EIO);
  449. }
  450. av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities);
  451. desired_format = fmt_ff2v4l(ap->pix_fmt);
  452. if (desired_format == 0 || (device_init(s1, &width, &height, desired_format) < 0)) {
  453. int i, done;
  454. done = 0; i = 0;
  455. while (!done) {
  456. desired_format = fmt_conversion_table[i].v4l2_fmt;
  457. if (device_init(s1, &width, &height, desired_format) < 0) {
  458. desired_format = 0;
  459. i++;
  460. } else {
  461. done = 1;
  462. }
  463. if (i == sizeof(fmt_conversion_table) / sizeof(struct fmt_map)) {
  464. done = 1;
  465. }
  466. }
  467. }
  468. if (desired_format == 0) {
  469. av_log(s1, AV_LOG_ERROR, "Cannot find a proper format.\n");
  470. close(s->fd);
  471. av_free(st);
  472. return AVERROR(EIO);
  473. }
  474. s->frame_format = desired_format;
  475. if( v4l2_set_parameters( s1, ap ) < 0 )
  476. return AVERROR(EIO);
  477. st->codec->pix_fmt = fmt_v4l2ff(desired_format);
  478. s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height);
  479. if (capabilities & V4L2_CAP_STREAMING) {
  480. s->io_method = io_mmap;
  481. res = mmap_init(s1);
  482. if (res == 0) {
  483. res = mmap_start(s1);
  484. }
  485. } else {
  486. s->io_method = io_read;
  487. res = read_init(s1);
  488. }
  489. if (res < 0) {
  490. close(s->fd);
  491. av_free(st);
  492. return AVERROR(EIO);
  493. }
  494. s->top_field_first = first_field(s->fd);
  495. st->codec->codec_type = CODEC_TYPE_VIDEO;
  496. st->codec->codec_id = CODEC_ID_RAWVIDEO;
  497. st->codec->width = width;
  498. st->codec->height = height;
  499. st->codec->time_base.den = frame_rate;
  500. st->codec->time_base.num = frame_rate_base;
  501. st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
  502. return 0;
  503. }
  504. static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)
  505. {
  506. struct video_data *s = s1->priv_data;
  507. int res;
  508. if (s->io_method == io_mmap) {
  509. av_init_packet(pkt);
  510. res = mmap_read_frame(s1, pkt);
  511. } else if (s->io_method == io_read) {
  512. if (av_new_packet(pkt, s->frame_size) < 0)
  513. return AVERROR(EIO);
  514. res = read_frame(s1, pkt);
  515. } else {
  516. return AVERROR(EIO);
  517. }
  518. if (res < 0) {
  519. return res;
  520. }
  521. if (s1->streams[0]->codec->coded_frame) {
  522. s1->streams[0]->codec->coded_frame->interlaced_frame = 1;
  523. s1->streams[0]->codec->coded_frame->top_field_first = s->top_field_first;
  524. }
  525. return s->frame_size;
  526. }
  527. static int v4l2_read_close(AVFormatContext *s1)
  528. {
  529. struct video_data *s = s1->priv_data;
  530. if (s->io_method == io_mmap) {
  531. mmap_close(s);
  532. }
  533. close(s->fd);
  534. return 0;
  535. }
  536. AVInputFormat v4l2_demuxer = {
  537. "video4linux2",
  538. "video grab",
  539. sizeof(struct video_data),
  540. NULL,
  541. v4l2_read_header,
  542. v4l2_read_packet,
  543. v4l2_read_close,
  544. .flags = AVFMT_NOFILE,
  545. };