Hi all, here is a preview of the video4linux input format I am developing. The code still has to be cleaned up a bit, and the only access method currently supported is mmap(), but I've been able to succesfully capture audio and video without problems. Video format selection seems to work well. I am interested in hearing some feedback, so anyone who has a video capture card is invited to test this new code - just copy v4l2.c over grab.c, recompile, and try something like ./ffmpeg -s 352x288 -pix_fmt <some pixel format> test.avi Thanks, Luca -- _____________________________________________________________________________ Copy this in your signature, if you think it is important: N O W A R ! ! ! -- Email.it, the professional e-mail, gratis per te: http://www.email.it/f Sponsor: Prova GRATIS per 15 giorni! DVDNetRent e ricevi a casa 3 film. Puoi scegliere tra migliaia di titoli Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=4632&d=27-1
On Fri, 2006-01-27 at 12:56 +0100, Luca Abeni wrote:
./ffmpeg -s 352x288 -pix_fmt <some pixel format> test.avi
I'd suggest testing with 720x576 or 720x480 (choose according to your region). Of course this will give much better quality but also is a better candidate for stress-testing. -----------
typedef struct video_data { int fd; int frame_format; /* V4L2_PIX_FMT_* */ #define USE_READ 0 #define USE_MMAP 1 #define USE_POINTERS 2 int io_method;
Ouch... I'd suggest: typedef enum { use_read, use_mmap, use_pointers } io_method_t; typedef struct video_data { ... io_method_t io_method; ... } ------------------------
int buffers; void *buf_start[4]; int buf_len[4]; } VideoData;
------------------------- You never want to make the number of buffers static because this can very largely, depending on the driver/card used and the resolution, the available buffers can vary between 1 and ~256. Of course you will always want to use the maximum number of buffers available.
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; res = ioctl(fd, VIDIOC_CROPCAP, &cropcap); if (res < 0) { /* Errors ignored. */ } else { crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; crop.c = cropcap.defrect; /* reset to default */
res = ioctl(fd, VIDIOC_S_CROP, &crop); if (res < 0) { switch (errno) { case EINVAL: /* Cropping not supported. */ break; default: /* Errors ignored. */ break; } } }
FWIW, AFAIK only the saa7134 driver supports cropping (so you might not be able to test it). It is a very nice feature though, because the saa7134 hardware takes great care to do the cropping (and scaling!) correctly, even for interlaced material. Not to mention it does it in realtime ;-) It's great for removing unnecessary black borders.
req.count = 4; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP;
As mentioned before, you will always want to acquire as much buffers as possible. You will need them.
*ts = buf.timestamp.tv_sec * int64_t_C(1000000) + buf.timestamp.tv_usec;
Neat!
res = ioctl (s->fd, VIDIOC_QBUF, &buf);
Please note that at least the saa7134 (but probably the other drivers as well) need some extra treatment for (temporary) loss of signal/sync. In that case the driver tends to get stuck in a state where all QBUF and DQBUF operations fail. Great work!
Luca Abeni wrote:
fd = open(devname, O_RDWR /*| O_NONBLOCK*/, 0); if (fd < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open video device %s : %s\n", devname, strerror(errno));
return -1; }
// In my v4l2 app I added a memset here... memset(&cap, 0, sizeof(cap));
static int device_init(int fd, int width, int height, int pix_fmt) { struct v4l2_format fmt;
memset(&fmt, 0, sizeof(struct v4l2_format)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = width; fmt.fmt.pix.height = height; fmt.fmt.pix.pixelformat = pix_fmt; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
// I use V4L2_FIELD_ANY here, it should be more flexible Hope it could help. I have little experience with V4L2 and FFmpeg but I made a small app that works with them and I would like to improve my knowledge so when you go on with your module post it here, it is appreciated. P.S. Italiano anche tu immagino :)
participants (3)
-
erik@slagter.name -
heavensdoor78@gmail.com -
lucabe72@email.it