Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

GStreamer capturing video frame

by pablacho (Initiate)
on Oct 12, 2012 at 14:52 UTC ( #998711=perlquestion: print w/replies, xml ) Need Help??
pablacho has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!,
I'm trying to capture a picture from a webcam while previewing the video. This is as simple as it sounds: I launch the program, I see myself on the screen, and whenever I see myself the best I capture that frame. Piece of cake.
Now, I could't be more wrong... I seems that there is not that much documentation about GStreamer in Perl, and this issue is giving me a LOT of trouble.
This is what i've tried so far: (I apologise for not pasting the actual code, as not only is a little messy but also I do not have it at hand)

The good part is that I can capture a frame and view video doing a pipeline like this:
v4l2src ! tee ! queue ! xvimagesink tee. ! queue ! videorate ! jpegenc ! filesink location=test.jpg
With this translated to my perl program, i obtain a nice window for about 5 seconds (I added a timeout) and a beautifull copy of the first frame. (using multifilesink gives me about 25 pictures per second)
Any attempt of triggering that frame capture on any other instant fails:
I've tried making different bins and pausing one untill I need to capture, using different pipelines, using a 'valve' element to drop frames and enabling/disabling it as fast as possible, blocking some pads and unblocking them assynchronously, and had absolutely no luck. I ended up with freezed xvimagesinks, null images and/or hundreds of pictures taken...
Do you have any advice? I'm sure that it is me that is blind and there is an obvious way of doing this, but, as we say here in Argentina, "the turtle is getting away from me"...
Thanks for your help!

Replies are listed 'Best First'.
Re: GStreamer capturing video frame
by zentara (Archbishop) on Oct 12, 2012 at 15:39 UTC
    There is a simpler way of doing this. :-)
    mplayer -vf screenshot tv:// driver=v4l2:width=800:height=600:device=/ +dev/video0 -fps 15 # and that gave me 800x600 video, and after I pressed 's' i obtained 8 +00x600 in the snapshot. # q to quit # I did the same for 1024x768, 1280x1024, and 1600x1200 and obtained a + 1024x768, # 1280x1024, and 1600x1200 video and snapshot respectively. # or get shots from a video # mplayer -vf screenshot some.avi # use keys # 1 and 2 - Adjust contrast. # 3 and 4 - Adjust brightness. # 5 and 6 - Adjust hue. # 7 and 8 - Adjust saturation.
    I know it isn't Perl, but you can run it via Perl's system command. :-)

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Hi zentara
      thanks for your reply!
      I think that might do the trick, but I don't think that that is a solution for me... this is a PC that will run as an embedded system with no keyboard or mouse (that's why I need that paralell port button I've mentioned).
      I've tried before with ffmpeg (that I think is the base that mplayer uses) and the results were not that good...
      Thanks again for answering! I'll just keep looking!!

      Has anyone been able to set a callback from a pad in GStreamer? I think that through that I might be able to take my picture, but I found absolutely no documentation for Perl :-(
      in c this is made through
       gst_pad_add_probe(GstPad *pad,GstPadProbeType mask,GstPadProbeCallback callback,gpointer user_data,GDestroyNotify destroy_data);
      But i did't found the Perl equivalent...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998711]
Approved by kcott
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-09-21 23:59 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (254 votes). Check out past polls.