Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [Fwd: Re: USB video driver]



Donald T Hayford wrote:
I really must do something about the "netbsd-current%netbsd.org@localhost" that ended up in my address book.

-------- Original Message --------
Subject:     Re: USB video driver
Date:     Sat, 07 Feb 2009 15:01:13 -0500
From:     Donald T Hayford <don%donhayford.com@localhost>
To:     Jared D. McNeill <jmcneill%invisible.ca@localhost>
CC:     netbsd-current%netbsd.org@localhost
References: <498DCF6A.9010105%donhayford.com@localhost> <498DD121.5060508%invisible.ca@localhost>



Jared D. McNeill wrote:
Donald T Hayford wrote:
I'm trying to get the new USB video drivers to work on an embedded (non-GUI) Arm processor (NSLU2). I built a kernel (20081215), added the appropriate drivers (uvideo, video), see the driver when it boots up, and can capture video using "cat /dev/video0 >test.avi". I can move the avi file to another machine and play the video. So the basic driver is essentially working.

But I can't get anything else to work from that point. I built xawtv so I could use webcam, but get the error message:

-bash-3.2$ webcam reading config file: /home/hayford/.webcamrc no grabber device available

.webcamrc has in it:
device=/dev/video0


when I run v4lctl, I get:
-bash-3.2$ v4lctl -c /dev/video0 -v 2 snap video/testpic1 vid-open: trying: bktr... bktr: ioctl METEORGSUPPIXFMT: Invalid argument vid-open: failed: bktr no grabber device available

The comment about the brooktree device confuses me, since I thought the uvideo device was the equivalent.

This may not be a NetBSD problem, so a referral to a better source of info would also be greatly appreciated.

Hi Don --

I'm not sure that our xawtv package builds the v4l2 support code in; you might want to give one of the following applications a shot:

  graphics/cheese
  graphics/ucview
  multimedia/mplayer

Hope this helps,
Jared

Thanks for the info. These seem to be either X11 based, or in the case of mplayer, too math-intensive for a little arm processor. What I was looking for was a simple command-line interface that would grab a few frames (as specified) and store them to a file. I haven't seen much in the way of command-line stuff other than those that come with xawtv. Sort of ironic, given the recent spate of emails about Desktop NetBSD.
At any rate, I'll keep looking.

If that's all you need, you can write a simple application to do this for you. When you open /dev/video0 the device should be setup in its default format; you can query the current format with VIDIOC_G_FMT and then read in a single frame's worth of data to a file.

The attached application (totally untested) should help you get started.

Cheers,
Jared
/* $NetBSD$ */

/*
 * 2009 Jared D. McNeill <jmcneill%invisible.ca@localhost>
 * Public domain.
 */

#include <sys/ioctl.h>
#include <sys/videoio.h>

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

static void
usage(void)
{
        fprintf(stderr, "usage: %s device filename\n", getprogname());
        exit(EXIT_FAILURE);
}

int
main(int argc, char *argv[])
{
        struct v4l2_format fmt;
        uint8_t *buf;
        int ifd, ofd;
        int error;
        size_t frlen;
        ssize_t rdlen, wrlen;

        if (argc != 3)
                usage();
                /* NOTREACHED */

        ifd = open(argv[1], O_RDONLY);
        if (ifd < 0) {
                perror("open camera");
                return EXIT_FAILURE;
        }
        ofd = open(argv[2], O_WRONLY|O_CREAT|O_EXCL, 0644);
        if (ofd < 0) {
                perror("open output");
                return EXIT_FAILURE;
        }

        error = ioctl(ifd, VIDIOC_G_FMT, &fmt);
        if (error) {
                perror("VIDIOC_G_FMT");
                return EXIT_FAILURE;
        }

        frlen = fmt.fmt.pix.width * fmt.fmt.pix.bytesperline;
        buf = malloc(frlen);
        if (buf == NULL) {
                perror("malloc");
                return EXIT_FAILURE;
        }

        rdlen = read(ifd, buf, frlen);
        if (rdlen == -1) {
                perror("read camera");
                return EXIT_FAILURE;
        }

        close(ifd);

        wrlen = write(ofd, buf, rdlen);
        if (wrlen == -1) {
                perror("write output");
                return EXIT_FAILURE;
        }

        close(ofd);

        printf("grabbed %z bytes\n", rdlen);

        return EXIT_SUCCESS;
}


Home | Main Index | Thread Index | Old Index