MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / write_header

Function write_header

libavdevice/v4l2enc.c:32–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30} V4L2Context;
31
32static av_cold int write_header(AVFormatContext *s1)
33{
34 int res = 0, flags = O_RDWR;
35 struct v4l2_format fmt = {
36 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT
37 };
38 V4L2Context *s = s1->priv_data;
39 AVCodecParameters *par;
40 uint32_t v4l2_pixfmt;
41
42 if (s1->flags & AVFMT_FLAG_NONBLOCK)
43 flags |= O_NONBLOCK;
44
45 s->fd = open(s1->url, flags);
46 if (s->fd < 0) {
47 res = AVERROR(errno);
48 av_log(s1, AV_LOG_ERROR, "Unable to open V4L2 device '%s'\n", s1->url);
49 return res;
50 }
51
52 if (s1->nb_streams != 1 ||
53 s1->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
54 av_log(s1, AV_LOG_ERROR,
55 "V4L2 output device supports only a single raw video stream\n");
56 return AVERROR(EINVAL);
57 }
58
59 par = s1->streams[0]->codecpar;
60
61 if(par->codec_id == AV_CODEC_ID_RAWVIDEO) {
62 v4l2_pixfmt = ff_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO);
63 } else {
64 v4l2_pixfmt = ff_fmt_ff2v4l(AV_PIX_FMT_NONE, par->codec_id);
65 }
66
67 if (!v4l2_pixfmt) { // XXX: try to force them one by one?
68 av_log(s1, AV_LOG_ERROR, "Unknown V4L2 pixel format equivalent for %s\n",
69 av_get_pix_fmt_name(par->format));
70 return AVERROR(EINVAL);
71 }
72
73 if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
74 res = AVERROR(errno);
75 av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_err2str(res));
76 return res;
77 }
78
79 fmt.fmt.pix.width = par->width;
80 fmt.fmt.pix.height = par->height;
81 fmt.fmt.pix.pixelformat = v4l2_pixfmt;
82 fmt.fmt.pix.sizeimage = av_image_get_buffer_size(par->format, par->width, par->height, 1);
83
84 if (ioctl(s->fd, VIDIOC_S_FMT, &fmt) < 0) {
85 res = AVERROR(errno);
86 av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_S_FMT): %s\n", av_err2str(res));
87 return res;
88 }
89

Callers

nothing calls this directly

Calls 4

av_logFunction · 0.85
ff_fmt_ff2v4lFunction · 0.85
av_get_pix_fmt_nameFunction · 0.85
av_image_get_buffer_sizeFunction · 0.85

Tested by

no test coverage detected