63
63
int video_fd, frame_size;
64
64
int ret, frame_rate, frame_rate_base;
65
int desired_palette, desired_depth;
66
66
struct video_tuner tuner;
67
67
struct video_audio audio;
68
struct video_picture pict;
68
69
const char *video_device;
71
if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
72
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
73
av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
74
ap->width, ap->height, ap->time_base.den);
75
80
height = ap->height;
76
81
frame_rate = ap->time_base.den;
77
82
frame_rate_base = ap->time_base.num;
79
if((unsigned)width > 32767 || (unsigned)height > 32767)
84
if((unsigned)width > 32767 || (unsigned)height > 32767) {
85
av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
82
91
st = av_new_stream(s1, 0);
111
120
desired_palette = -1;
112
if (st->codec->pix_fmt == PIX_FMT_YUV420P) {
122
if (ap->pix_fmt == PIX_FMT_YUV420P) {
113
123
desired_palette = VIDEO_PALETTE_YUV420P;
114
} else if (st->codec->pix_fmt == PIX_FMT_YUV422) {
125
} else if (ap->pix_fmt == PIX_FMT_YUV422) {
115
126
desired_palette = VIDEO_PALETTE_YUV422;
116
} else if (st->codec->pix_fmt == PIX_FMT_BGR24) {
128
} else if (ap->pix_fmt == PIX_FMT_BGR24) {
117
129
desired_palette = VIDEO_PALETTE_RGB24;
120
133
/* set tv standard */
135
148
audio.flags &= ~VIDEO_AUDIO_MUTE;
136
149
ioctl(video_fd, VIDIOCSAUDIO, &audio);
151
ioctl(video_fd, VIDIOCGPICT, &pict);
153
printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
160
/* try to choose a suitable video format */
161
pict.palette = desired_palette;
162
pict.depth= desired_depth;
163
if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
164
pict.palette=VIDEO_PALETTE_YUV420P;
166
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
168
pict.palette=VIDEO_PALETTE_YUV422;
170
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
172
pict.palette=VIDEO_PALETTE_RGB24;
174
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
176
pict.palette=VIDEO_PALETTE_GREY;
178
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
138
185
ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
140
187
/* try to use read based access */
141
188
struct video_window win;
142
struct video_picture pict;
152
198
ioctl(video_fd, VIDIOCSWIN, &win);
154
ioctl(video_fd, VIDIOCGPICT, &pict);
156
printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
163
/* try to choose a suitable video format */
164
pict.palette = desired_palette;
165
if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
166
pict.palette=VIDEO_PALETTE_YUV420P;
167
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
169
pict.palette=VIDEO_PALETTE_YUV422;
170
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
172
pict.palette=VIDEO_PALETTE_RGB24;
173
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
180
200
s->frame_format = pict.palette;
207
227
s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
208
228
s->gb_buf.height = height;
209
229
s->gb_buf.width = width;
210
s->gb_buf.format = desired_palette;
212
if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
213
s->gb_buf.format = VIDEO_PALETTE_YUV420P;
215
ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
216
if (ret < 0 && errno != EAGAIN) {
218
s->gb_buf.format = VIDEO_PALETTE_YUV422;
220
ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
221
if (ret < 0 && errno != EAGAIN) {
223
s->gb_buf.format = VIDEO_PALETTE_RGB24;
224
ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
230
s->gb_buf.format = pict.palette;
232
ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
229
234
if (errno != EAGAIN) {
255
260
frame_size = width * height * 3;
256
261
st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
263
case VIDEO_PALETTE_GREY:
264
frame_size = width * height * 1;
265
st->codec->pix_fmt = PIX_FMT_GRAY8;