[Ffmpeg-devel] [PATCH] grabbing with V4L

Flavio Pimentel Duarte flaviop
Mon Feb 20 17:26:06 CET 2006



On Fri, 17 Feb 2006, Luca Abeni wrote:

> Hi Flavio,
>
> On Wed, 2006-02-15 at 14:34 +0100, Luca Abeni wrote:
> [...]
>>> The patch I've sent didn't create a single new line, it only moves some
>>> image settings initialization to outside the if statement. It was also
>>> not my idea, I borrowed from mplayer ;)
>> Yes, looking at the patch I agree that it should not create problems.
>> I'll test it tomorrow, just as a confirmation.
> I tested your patch, and verified that it does not create any regression.
> Uhmm... I still do not understand why it is needed by your webcam driver
> but the "regular" bttv driver does not need it...
>
> Anyway, I think your patch is good because it permits to avoid some code
> duplication (in fact, after applying your patch all the code around line
> 212 becomes useless). So, I went ahead and I removed some code that (I
> think) is obsoleted by your patch (since desired_palette is already set
> by previous code).
>
> Does the attached patch (your patch + some useless code removal) work
> for you?
 	The patch you sent me did not work. It issues the following error:
$ ./ffmpeg -s 320x240 -an -vd /dev/video0 output.mpg
FFmpeg version CVS, Copyright (c) 2000-2004 Fabrice Bellard
   configuration:  --disable-v4l2
   libavutil version: 49.0.0
   libavcodec version: 51.7.0
   libavformat version: 50.3.0
   built on Feb 20 2006 11:05:32, gcc: 3.4.3 (Mandrakelinux 10.2 
3.4.3-7mdk)
File 'output.mpg' already exists. Overwrite ? [y/N] y
[video4linux @ 0x82c8ef4]Fatal: grab device does not support suitable 
format
Could not find video grab device

 	I had to add just one line to make it work. The modified patch is 
attached.

 	I also have one question: how do I force ffmpeg to use v4l instead 
v4l2 ? Is there an option for it ? In my tests I had to compile ffmpeg 
using '--disable-v4l2' option, otherwise it uses v4l2.


Flavio
-------------- next part --------------
--- ffmpeg/libavformat/grab.c	2006-02-20 12:21:43.000000000 -0500
+++ ffmpeg.new/libavformat/grab.c	2006-02-20 13:15:20.000000000 -0500
@@ -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,37 @@ 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;
+            }
+        }
+    }
+    desired_palette = pict.palette;
+
     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 +178,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;
@@ -209,22 +210,7 @@ static int grab_read_header(AVFormatCont
         s->gb_buf.width = width;
         s->gb_buf.format = desired_palette;
 
-        if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
-            s->gb_buf.format = VIDEO_PALETTE_YUV420P;
-
-            ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
-            if (ret < 0 && errno != EAGAIN) {
-                /* try YUV422 */
-                s->gb_buf.format = VIDEO_PALETTE_YUV422;
-
-                ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
-                if (ret < 0 && errno != EAGAIN) {
-                    /* try RGB24 */
-                    s->gb_buf.format = VIDEO_PALETTE_RGB24;
-                    ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
-                }
-            }
-        }
+        ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
         if (ret < 0) {
             if (errno != EAGAIN) {
             fail1:



More information about the ffmpeg-devel mailing list