[Ffmpeg-devel] [PATCH] grabbing with V4L
Flavio Pimentel Duarte
flaviop
Mon Jan 9 19:45:22 CET 2006
I have reported that capturing movies with ffmpeg and Creative Notebook
Webcam produces a very dark movie. Later I saw the same problem with
Creative NX PRO. I took a look at V4L documentation and at the mplayer
source code and realized that the problem was some initialization was
missing or misplaced. I reorganized the code in grab.c to solve the
problem. The patch is attached.
Flavio
-------------- next part --------------
Index: libavformat/grab.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/grab.c,v
retrieving revision 1.39
diff -u -p -r1.39 grab.c
--- libavformat/grab.c 22 Dec 2005 01:10:11 -0000 1.39
+++ libavformat/grab.c 9 Jan 2006 18:25:34 -0000
@@ -65,6 +65,7 @@ static int grab_read_header(AVFormatCont
int desired_palette;
struct video_tuner tuner;
struct video_audio audio;
+ struct video_picture pict;
const char *video_device;
int j;
@@ -135,11 +136,36 @@ static int grab_read_header(AVFormatCont
audio.flags &= ~VIDEO_AUDIO_MUTE;
ioctl(video_fd, VIDIOCSAUDIO, &audio);
+ ioctl(video_fd, VIDIOCGPICT, &pict);
+#if 0
+ printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
+ pict.colour,
+ pict.hue,
+ pict.brightness,
+ pict.contrast,
+ pict.whiteness);
+#endif
+ /* try to choose a suitable video format */
+ pict.palette = desired_palette;
+ if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
+ pict.palette=VIDEO_PALETTE_YUV420P;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0) {
+ pict.palette=VIDEO_PALETTE_YUV422;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0) {
+ pict.palette=VIDEO_PALETTE_RGB24;
+ ret = ioctl(video_fd, VIDIOCSPICT, &pict);
+ if (ret < 0)
+ goto fail1;
+ }
+ }
+ }
+
ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
if (ret < 0) {
/* try to use read based access */
struct video_window win;
- struct video_picture pict;
int val;
win.x = 0;
@@ -151,32 +177,6 @@ static int grab_read_header(AVFormatCont
ioctl(video_fd, VIDIOCSWIN, &win);
- ioctl(video_fd, VIDIOCGPICT, &pict);
-#if 0
- printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
- pict.colour,
- pict.hue,
- pict.brightness,
- pict.contrast,
- pict.whiteness);
-#endif
- /* try to choose a suitable video format */
- pict.palette = desired_palette;
- if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
- pict.palette=VIDEO_PALETTE_YUV420P;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_YUV422;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_RGB24;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0)
- goto fail1;
- }
- }
- }
-
s->frame_format = pict.palette;
val = 1;
More information about the ffmpeg-devel
mailing list