PDA

View Full Version : Phonon and webcam



Radagast
6th November 2008, 20:07
I'm using MSVS 2008 and Qt 4.4.1 (configure blablabla -phonon yep)
And as Phonon in Windows is based on DirectShow and usually Windows C++ programmers use DirectShow to get access to a webcam, I suppose that there must be a trivial (but not mentioned neither at the Phonon official website nor nowhere else in google :( ) way to present a webcam device as a Phonon::MediaSource::Stream or something like that?
Thanks in advance.

P.S. I know about OpenCV, but I'd like to try tools that I already have.

muellerp
7th November 2008, 08:56
Phonon is abstracted in the way that you will have following structure (Phonon talks here of path based approach):

MediaSource -> MediaObject -> VideoOutput(i.e. VideoWidget).

So what is already there is MediaObject and VideoWidget, no need to do here much about it. The DS approach helps here only for the VideoWidget.

But Phonon has no direct support for a MediaSource of webcams.
So you need to reimplement a MediaSource for your webcam.

I have no clue if you have the API to get the raw data from your webcam, but in case you have the task would be to write the custom MediaSource.
In order to get your MediaSource you will need to write a custom QIODevice for it.

When the QIODevice is ready then it is an easy taks to get the rest done.

Radagast
7th November 2008, 10:49
Thanks, but I just don't know, from what point to start. Is there in WinAPI functions to access a webcam (regardless of its manufacturer)? Isn't the DirectShow that _modern_ API that is used to access a webcam?

muellerp
7th November 2008, 11:34
For the DirectShow API for Webcams I cannot help. I'm on the Linux side of the force.
But Google maybe your friend.

How to implement a QIODevice I can help then.
E.g.
- You need to take care for reentrancy, as Phonon backend may give you a second read request while still waiting for getting the first read.
- I would use a QThread for reading class in order to get wait conditions
- You most probabely need a ringbuffer, as the webcam will give you constant data and you cannot just write them directly to Phonon videoWidget.

aaslannn
29th November 2008, 14:06
I also have some problems at that point, I am reading a frame from the webcam using opencv but now how am I going to implement readData function?

If I use ringBuffer, I will have many frames in the buffer but what is expected to return from readData function? a buffer filled with frames? in which order or the format of the image RGB, RGBA or GRBA?

muellerp
30th November 2008, 15:36
I also have some problems at that point, I am reading a frame from the webcam using opencv but now how am I going to implement readData function?

If I use ringBuffer, I will have many frames in the buffer but what is expected to return from readData function? a buffer filled with frames? in which order or the format of the image RGB, RGBA or GRBA?

In my application (streamed TV), the stream is just the plain DVB stream (TS or PES). So the frames are already encapsulated in a datastream.
The "only" thing I needed to do is to pass this datastream as is to the media object via the QIODevice.

So there is no phonon or QIODevice special format needed. It just needs to be a format that your Phonon backend (DS or GStreamer or Xine or ...) can understand.

To ensure that your backend can read your format, I would first just save the data as is to harddisk and open the file with your favorite platform or Phonon application. If this works, then I would work on the QIODevice.

I have no experience with converting the opencv datastream into something like MPEG2.

aaslannn
30th November 2008, 17:24
Yeah, you are right. I am using gstreamer and I should look for its format.

I played with QImage and QIODevice objects a bit and currently can play(show) a png file in phonon :D, in fact I keep an QBuffer object in QIODevice implementation, buffer holds the frames read from the webcam as png files(QImage::save()). Then I give this iodevice object to phonon, it only shows the first image but not plays all of them consecutively. I don't know how to solve this problem.

Edit: Looking for a way to insert, append frames to a video file or something like that :) what is the simplest video format? Maybe GIF but qt can not write to it. QMovie could be a solution, currently working on it.

muellerp
30th November 2008, 19:16
I don't think GIF is really suitible.

How about following one of the tutorials (http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00073000000000000000)

It still doesn't give you a stream - just a file, but you can then start playing around with it.

I just looked into the docu and there is support for streams (http://opencv.willowgarage.com/wiki/HighGui#highgui_video).

aaslannn
1st December 2008, 11:29
I noticed xine can play webcam data directly using v4l:///dev/video0 as the input to xine command, maybe can figure out a way to pass it as a source to phonon where xine can get it and play. I tried Qfile and directly givi

I read the tutorial, it saves it to an avi file, at least that is a way to implement it. However, can we do it in the ram? Without disk access, it would be faster.