Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Using Wx::MediaCtrl to display a live videofeed (eg a webcam)

by Steve_BZ (Chaplain)
on Jul 20, 2010 at 12:19 UTC ( #850404=perlquestion: print w/replies, xml ) Need Help??

Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi People,

I have been developing a wxPerl application for about a year now, one of my outstanding issues is how to get a live video feed to display. So far I have been using Wx::MediaCtrl and all my testing has been done on stored videos. However, I feel the time has come to bite the bullet and get the live feed to work. I am developing on Linux (Kubuntu) and Wx::MediaCtrl uses GStreamer as the back end. I had hoped that I could simply use:

$success_status = $i_frame->{Ctl_Videos_Media}->LoadURI ('/dev/video0');

but it doesn't work, it doesn't give me an error message, and it doen't even return a success status (but if I do a GetStatus on it I get '0').

My second thought was:

  • run ffmpeg from the command line: ffmpeg -f oss -ac 2 -ar 48000 -i /dev/dsp -acodec pcm_s16le -f video4linux2 -s 720x480 -r 30000/1001 -i /dev/video0 -sameq -aspect 4:3 -f avi -vcodec mjpeg -r 30000/1001 -y test.avi, which works fine.
  • Then use $i_frame->{Ctl_Videos_Media}->Load ('test.avi');, which also works but only for the video recorded *before* MediaCtrl started. When it gets to the point in time where the webcam was when the program started it crashes. That is to say, you can't Seek to the end of the .avi file and play what is currently being added to it.

*However*, there is hope, if I run the following command at a command prompt: gst-launch-0.10 v4l2src ! tee name=videoout ! queue ! videorate ! video/x-raw-yuv,fps=15 ! queue ! theoraenc quality=60 ! queue ! muxout. oggmux name=muxout ! filesink location=lulz.ogg videoout. ! queue ! ffmpegcolorspace ! ximagesink, I get a stored file which I can seek through and a live feed being displayed through a window with about a half-second latency. If only that window was a MediaCtrl window it would be perfect. As gst-launch is a GStreamer application and Wx::MediaCtrl uses Wx::GStreamerMediaBackend, I assume that I can somehow splice these programs together, but here I get lost.

As usual, your wisdom and thoughts would be very welcome.

Regards

Steve

Replies are listed 'Best First'.
Re: Using Wx::MediaCtrl to display a live videofeed (eg a webcam)
by Corion (Pope) on Jul 20, 2010 at 12:38 UTC

    If you can push raw frames (in YUV or RGB format) to the Wx::MediaControl, then you can use ffmpeg to read from the webcam and convert and output the raw frames to STDOUT. You set up a filehandle to read from there and push the frames into the Wx frame. I have something not unlike this (except that my build of ffmpeg.exe does not want to read from the video camera and that I use OpenGL to render the output) in App::VideoMixer.

      Hi Corion,

      I thought I had posted a reply to this yesterday, but maybe it got lost in the confusion. My power-supply blew up spectacularly (loud bang and smoke) taking motherboard and CPU with it, luckily not HD. I need to rebuild my PC, but as I'm off for a week tomorrow, it'll be the end of next week before I can do it.

      Thanks for your input

      Regards

      Steve

Re: Using Wx::MediaCtrl to display a live videofeed (eg a webcam)
by Anonymous Monk on Jul 20, 2010 at 12:44 UTC
    Do you have a wxLogWindow? Some kind of error message should be reported... Can you run it with strace?

      Hi Anon,

      Thanks for this. I didn't have LogWindow installed, so I just did that and I get:

      21:56:14: Error: gst_error_callback Error Message:Invalid URI "/dev/video0". Debug:gstplaybasebin.c(1666): gen_source_element (): /GstPlayBin:play (error 0: Success) 21:56:14: Error: wxGStreamerMediaBackend::Load - Could not set initial + state to ready (error 0: Success)

      I guess it doesn't like the /dev/video0. Maybe it really expects a URL, but assuming it means a URI, then should I just put my computer name in front of it like this? steve-desktop/dev/video0 because that doesn't work either.

      Do you know what format is correct?

      Thanks and regards

      Steve.

      PS I tried the strace, but it gave me pages and pages of info. I'll have a go at filtering it down, and post it here.

        $ perl -MURI::file -le"die URI::file->new( shift )->canonical " /dev/v +ideo0 file:///dev/video0
Re: Using Wx::MediaCtrl to display a live videofeed (eg a webcam)
by Kirsle (Pilgrim) on Jul 21, 2010 at 17:08 UTC
    I've done something similar with Perl/Tk, using ffmpeg to get an mjpeg stream and split the jpeg images up and display them in a regular imagelabel widget.

    See node: 792758

Re: Using Wx::MediaCtrl to display a live videofeed (eg a webcam) - Solved
by Steve_BZ (Chaplain) on Aug 11, 2011 at 11:27 UTC

    Update

    Thanks everyone for your input. In fact just last night, I got a fix from the wxWidgets mailing list.

    The answer for anyone else who comes looking is:

    The Linux webcam should be addressed as v4l2:///dev/video0. Make sure that's a letter l (lower case L, not upper case i and not a numeral l) in the v4l2.

    Now I have beautiful streaming webcam!

    Regards

    Steve

      Wow, to wait a whole year ... I wonder if v4lc: was available then
        Sorry, v4l2 - I've updated my post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://850404]
Approved by moritz
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-10-25 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?