Results 1 to 9 of 9

Thread: Phonon and webcam

  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Phonon and webcam

    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.
    Last edited by Radagast; 6th November 2008 at 19:28.

  2. #2
    Join Date
    Jul 2008
    Posts
    47
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Phonon and webcam

    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.

  3. #3
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Phonon and webcam

    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?

  4. #4
    Join Date
    Jul 2008
    Posts
    47
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Phonon and webcam

    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.

  5. #5
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Phonon and webcam

    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?

  6. #6
    Join Date
    Jul 2008
    Posts
    47
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Phonon and webcam

    Quote Originally Posted by aaslannn View Post
    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.

  7. #7
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Phonon and webcam

    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 , 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.
    Last edited by aaslannn; 30th November 2008 at 17:18.

  8. #8
    Join Date
    Jul 2008
    Posts
    47
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Phonon and webcam

    I don't think GIF is really suitible.

    How about following one of the tutorials

    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.

  9. #9
    Join Date
    Nov 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Phonon and webcam

    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.

Similar Threads

  1. using a DirectShow enabled webcam to take still images in QT
    By Jason Hamilton in forum Qt Programming
    Replies: 4
    Last Post: 8th October 2008, 23:25
  2. Phonon examples
    By SPir4L in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2008, 11:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.