* newbie programming help: grabbing image(s) from /dev/video0, example code?
@ 2008-03-01 21:33 Elvis Chen
2008-03-01 22:21 ` Carl Karsten
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Elvis Chen @ 2008-03-01 21:33 UTC (permalink / raw)
To: video4linux-list
Greetings,
I'm a researcher in computer-science. I'm very new to V4L2 but am reasonably proficient in C++ programming. I seek your help in getting something simple done, in the meanwhile I'm trying to learn V4L2 programming API (http://v4l2spec.bytesex.org/)
We have 2 Hauppauge WInTV PVR-150 installed on a ubuntu 7.10 x86_64 machine. They appear to the linux as /dev/video0 and /dev/video1, respectively. What we like to do is to capture still images (or video) via s-video inputs on each card, and perform image-processing algorithms on them (in C++) and display the resultant images on the screen (C++/OpenGL). Basically what I want to do is very simple: open a linux/video device, capture an image, store it as a C array/buffer, display it, and refresh the C array/buffer.
Both cards work with kdetv and mplayer, so hardware-wise they work fine.
My first attempt was to find a small/simple API to access the linux/video device. I came across videodog (http://linux.softpedia.com/get/Multimedia/Video/VideoDog-9261.shtml) but it looks like it isn't been developed anymore (no source either). Currently I'm trying to learn V4L2 (and trying to utilize the sample capture.c).
Can anyone please give me a pointer on where I should start learning the V4L2 API? Are there more example codes available?
any help is very much appreciated,
_________________________________________________________________
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: newbie programming help: grabbing image(s) from /dev/video0, example code? 2008-03-01 21:33 newbie programming help: grabbing image(s) from /dev/video0, example code? Elvis Chen @ 2008-03-01 22:21 ` Carl Karsten 2008-03-01 22:49 ` question Michael Williamson 2008-03-01 23:48 ` newbie programming help: grabbing image(s) from /dev/video0, example code? Daniel Glöckner 2 siblings, 0 replies; 8+ messages in thread From: Carl Karsten @ 2008-03-01 22:21 UTC (permalink / raw) Cc: video4linux-list Elvis Chen wrote: > Greetings, > > I'm a researcher in computer-science. I'm very new to V4L2 but am reasonably proficient in C++ programming. I seek your help in getting something simple done, in the meanwhile I'm trying to learn V4L2 programming API (http://v4l2spec.bytesex.org/) > > We have 2 Hauppauge WInTV PVR-150 installed on a ubuntu 7.10 x86_64 machine. They appear to the linux as /dev/video0 and /dev/video1, respectively. What we like to do is to capture still images (or video) via s-video inputs on each card, and perform image-processing algorithms on them (in C++) and display the resultant images on the screen (C++/OpenGL). Basically what I want to do is very simple: open a linux/video device, capture an image, store it as a C array/buffer, display it, and refresh the C array/buffer. > > Both cards work with kdetv and mplayer, so hardware-wise they work fine. > > My first attempt was to find a small/simple API to access the linux/video device. I came across videodog (http://linux.softpedia.com/get/Multimedia/Video/VideoDog-9261.shtml) but it looks like it isn't been developed anymore (no source either). Currently I'm trying to learn V4L2 (and trying to utilize the sample capture.c). > > > Can anyone please give me a pointer on where I should start learning the V4L2 API? Are there more example codes available? http://lwn.net/Articles/203924/ I think the code you need may be in http://www.video4linux.org/browser/v4l2-apps/test btw - I am on a campaign to get better tests, so if you are in the mood, use one or more of those apps to test your driver, and improve the tests (they are currently not very extensive.) Carl K -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* question 2008-03-01 21:33 newbie programming help: grabbing image(s) from /dev/video0, example code? Elvis Chen 2008-03-01 22:21 ` Carl Karsten @ 2008-03-01 22:49 ` Michael Williamson 2008-03-02 0:24 ` question Daniel Glöckner 2008-03-01 23:48 ` newbie programming help: grabbing image(s) from /dev/video0, example code? Daniel Glöckner 2 siblings, 1 reply; 8+ messages in thread From: Michael Williamson @ 2008-03-01 22:49 UTC (permalink / raw) To: video4linux-list Hi, With CX100 frame grabbers, it is possible to poll the even/odd video field bit through the ISA bus. This is useful to have for cameras with electronic shutters to make long exposures. Is it possible to do with v4l2/bt848 PCI devices? Thanks, -Mike ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: question 2008-03-01 22:49 ` question Michael Williamson @ 2008-03-02 0:24 ` Daniel Glöckner 0 siblings, 0 replies; 8+ messages in thread From: Daniel Glöckner @ 2008-03-02 0:24 UTC (permalink / raw) To: Michael Williamson; +Cc: video4linux-list On Sat, Mar 01, 2008 at 02:49:42PM -0800, Michael Williamson wrote: > With CX100 frame grabbers, it is possible to poll the > even/odd video field bit through the ISA bus. > This is useful to have for cameras with electronic > shutters to make long exposures. Is it possible to do > with v4l2/bt848 PCI devices? This information is available in the DSTATUS and INT_STAT register of the bt848 but it is not exposed to userspace by the driver. You can capture fields seperately to be informed of field changes. Daniel -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: newbie programming help: grabbing image(s) from /dev/video0, example code? 2008-03-01 21:33 newbie programming help: grabbing image(s) from /dev/video0, example code? Elvis Chen 2008-03-01 22:21 ` Carl Karsten 2008-03-01 22:49 ` question Michael Williamson @ 2008-03-01 23:48 ` Daniel Glöckner 2008-03-03 20:09 ` Elvis Chen 2008-09-29 20:58 ` Elvis Chen 2 siblings, 2 replies; 8+ messages in thread From: Daniel Glöckner @ 2008-03-01 23:48 UTC (permalink / raw) To: Elvis Chen; +Cc: video4linux-list On Sat, Mar 01, 2008 at 09:33:08PM +0000, Elvis Chen wrote: > We have 2 Hauppauge WInTV PVR-150 installed on a ubuntu 7.10 x86_64 machine. > They appear to the linux as /dev/video0 and /dev/video1, respectively. On this card video0 and video1 are for MPEG captures. Use video32 and video33 for YUV captures. The only possible YUV format is 4:2:0 with rearranged bytes. Read Documentation/video4linux/cx2341x/README.hm12. > My first attempt was to find a small/simple API to access the linux/video device. No need to find another API, V4L2 is small enough: #include <linux/videodev2.h> #include <sys/ioctl.h> #include <fcntl.h> #include <unistd.h> static unsigned char image[720*480*3/2]; int main() { struct v4l2_format vf; int i=1,fd=open("/dev/video32",O_RDWR); ioctl(fd,VIDIOC_S_INPUT,&i); memset(&vf,0,sizeof(vf)); vf.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; vf.fmt.pix.width=720; vf.fmt.pix.height=480; vf.fmt.pix.pixelformat=V4L2_PIX_FMT_HM12; vf.fmt.pix.field=V4L2_FIELD_INTERLACED; vf.fmt.pix.bytesperline=vf.fmt.pix.width; ioctl(fd,VIDIOC_S_FMT,&vf); write(1,image,read(fd,image,sizeof(image))); return 0; } You may want to insert some error checks :-) And if you want better performance, use memory mapped I/O. Daniel -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: newbie programming help: grabbing image(s) from /dev/video0, example code? 2008-03-01 23:48 ` newbie programming help: grabbing image(s) from /dev/video0, example code? Daniel Glöckner @ 2008-03-03 20:09 ` Elvis Chen 2008-09-29 20:58 ` Elvis Chen 1 sibling, 0 replies; 8+ messages in thread From: Elvis Chen @ 2008-03-03 20:09 UTC (permalink / raw) To: Daniel Glöckner; +Cc: video4linux-list Thank you all. With the following code and the documentation for hm12, I managed to grab a video from /dev/video32 (YUV) and converted the input YUV image to RGB output. I was then able to view it using imagemagick. My code turned out to be similar to hm12toyuv (available at http://highlab.com/~seb/hm12toyuv/ ) so I won't bother posting it here. It isn't surprising since hm12toyuv is based on the example on the same documention (for hm12) as well. I do find the grabbing process slow and may not be suitable for my application. I'll investigate on using memory mapped I/O once the rest of my application is at a reasonable state. Thanks again, Elvis > Date: Sun, 2 Mar 2008 00:48:21 +0100 > From: daniel-gl@gmx.net > To: chene77@hotmail.com > CC: video4linux-list@redhat.com > Subject: Re: newbie programming help: grabbing image(s) from /dev/video0, example code? > > On Sat, Mar 01, 2008 at 09:33:08PM +0000, Elvis Chen wrote: > > We have 2 Hauppauge WInTV PVR-150 installed on a ubuntu 7.10 x86_64 machine. > > They appear to the linux as /dev/video0 and /dev/video1, respectively. > > On this card video0 and video1 are for MPEG captures. > Use video32 and video33 for YUV captures. > > The only possible YUV format is 4:2:0 with rearranged bytes. > Read Documentation/video4linux/cx2341x/README.hm12. > > > My first attempt was to find a small/simple API to access the linux/video device. > > No need to find another API, V4L2 is small enough: > > #include <linux/videodev2.h> > #include <sys/ioctl.h> > #include <fcntl.h> > #include <unistd.h> > > static unsigned char image[720*480*3/2]; > > int main() > { > struct v4l2_format vf; > int i=1,fd=open("/dev/video32",O_RDWR); > ioctl(fd,VIDIOC_S_INPUT,&i); > memset(&vf,0,sizeof(vf)); > vf.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; > vf.fmt.pix.width=720; > vf.fmt.pix.height=480; > vf.fmt.pix.pixelformat=V4L2_PIX_FMT_HM12; > vf.fmt.pix.field=V4L2_FIELD_INTERLACED; > vf.fmt.pix.bytesperline=vf.fmt.pix.width; > ioctl(fd,VIDIOC_S_FMT,&vf); > write(1,image,read(fd,image,sizeof(image))); > return 0; > } > > You may want to insert some error checks :-) > And if you want better performance, use memory mapped I/O. > > Daniel _________________________________________________________________ -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: newbie programming help: grabbing image(s) from /dev/video0, example code? 2008-03-01 23:48 ` newbie programming help: grabbing image(s) from /dev/video0, example code? Daniel Glöckner 2008-03-03 20:09 ` Elvis Chen @ 2008-09-29 20:58 ` Elvis Chen 2008-09-30 12:45 ` Daniel Glöckner 1 sibling, 1 reply; 8+ messages in thread From: Elvis Chen @ 2008-09-29 20:58 UTC (permalink / raw) To: Daniel Glöckner; +Cc: video4linux-list hi Daniel and others, First off, thanks for your reply. I have written a small c application that basically is your code, I'm able to capture an image, decode the yuv frame, and display it on the screen. However, I think it drops frame once a while. Can you please tell me if pvr-150 support memory mapped IO? I have tried to run the capture_example from http://www.video4linux.org/browser/v4l2-apps/test and it appears that the Hauppauge pvr-150 does not: or1float [4:51pm]>./capture_example -m -d /dev/video32 /dev/video32 does not support streaming i/o or1float [4:51pm]>./capture_example -m -d /dev/video0 /dev/video0 does not support streaming i/o is there another way to increase the performance? thanks, > Date: Sun, 2 Mar 2008 00:48:21 +0100 > From: daniel-gl@gmx.net > To: chene77@hotmail.com > CC: video4linux-list@redhat.com > Subject: Re: newbie programming help: grabbing image(s) from /dev/video0, example code? > > On Sat, Mar 01, 2008 at 09:33:08PM +0000, Elvis Chen wrote: > > We have 2 Hauppauge WInTV PVR-150 installed on a ubuntu 7.10 x86_64 machine. > > They appear to the linux as /dev/video0 and /dev/video1, respectively. > > On this card video0 and video1 are for MPEG captures. > Use video32 and video33 for YUV captures. > > The only possible YUV format is 4:2:0 with rearranged bytes. > Read Documentation/video4linux/cx2341x/README.hm12. > > > My first attempt was to find a small/simple API to access the linux/video device. > > No need to find another API, V4L2 is small enough: > > #include <linux/videodev2.h> > #include <sys/ioctl.h> > #include <fcntl.h> > #include <unistd.h> > > static unsigned char image[720*480*3/2]; > > int main() > { > struct v4l2_format vf; > int i=1,fd=open("/dev/video32",O_RDWR); > ioctl(fd,VIDIOC_S_INPUT,&i); > memset(&vf,0,sizeof(vf)); > vf.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; > vf.fmt.pix.width=720; > vf.fmt.pix.height=480; > vf.fmt.pix.pixelformat=V4L2_PIX_FMT_HM12; > vf.fmt.pix.field=V4L2_FIELD_INTERLACED; > vf.fmt.pix.bytesperline=vf.fmt.pix.width; > ioctl(fd,VIDIOC_S_FMT,&vf); > write(1,image,read(fd,image,sizeof(image))); > return 0; > } > > You may want to insert some error checks :-) > And if you want better performance, use memory mapped I/O. > > Daniel _________________________________________________________________ -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: newbie programming help: grabbing image(s) from /dev/video0, example code? 2008-09-29 20:58 ` Elvis Chen @ 2008-09-30 12:45 ` Daniel Glöckner 0 siblings, 0 replies; 8+ messages in thread From: Daniel Glöckner @ 2008-09-30 12:45 UTC (permalink / raw) To: Elvis Chen; +Cc: video4linux-list On Mon, Sep 29, 2008 at 08:58:05PM +0000, Elvis Chen wrote: > and it appears that the Hauppauge pvr-150 does not: You are right, ivtv supports only read/write access. > is there another way to increase the performance? Have you tried reading in a thread separate from the image processing (with multiple frame buffers)? Daniel -- video4linux-list mailing list Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-09-30 12:45 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-01 21:33 newbie programming help: grabbing image(s) from /dev/video0, example code? Elvis Chen 2008-03-01 22:21 ` Carl Karsten 2008-03-01 22:49 ` question Michael Williamson 2008-03-02 0:24 ` question Daniel Glöckner 2008-03-01 23:48 ` newbie programming help: grabbing image(s) from /dev/video0, example code? Daniel Glöckner 2008-03-03 20:09 ` Elvis Chen 2008-09-29 20:58 ` Elvis Chen 2008-09-30 12:45 ` Daniel Glöckner
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox