3

This is python code for capturing streaming video from server. but I need to write a function to extract one frame from the flow. It will be a button. On click it will show current frame. I have no ideas. Can anyone help me with this???

    self.player = gst.Pipeline("player")
    self.source = gst.element_factory_make("uridecodebin", "video-source")
    #self.source = gst.element_factory_make("playbin2", "video-source")
    sink = gst.element_factory_make("xvimagesink", "video-output")
    colorspace = gst.element_factory_make("ffmpegcolorspace")
    scale = gst.element_factory_make("videoscale")

    self.source.set_property("uri",\
    "http://10.10.25.4:12345/webcam.flv")

    caps = gst.Caps("video/x-raw-yuv, width=640, height=480, framerate=20/1")
    myfilter = gst.element_factory_make("capsfilter", "myfilter")
    myfilter.set_property("caps", caps)  # ################

    clr_sink = colorspace.get_pad("sink")
    self.source.connect("pad-added", self.on_pad_added, clr_sink)

    self.player.add(self.source, colorspace, scale, myfilter, sink)
    gst.element_link_many(colorspace, scale, myfilter, sink)

    self.bus = self.player.get_bus()
    self.bus.add_signal_watch()
    self.bus.connect('message', self.__on_message)

    self.player.set_state(gst.STATE_PLAYING)
oleg.foreigner
  • 993
  • 2
  • 13
  • 28

2 Answers2

0

If you can use playbin2, you can use the "convert-frame" action signal. Otherwise look at the implementation and reuse.

ensonic
  • 3,304
  • 20
  • 31
-2

you want to use the imagefreeze element. something like:

#!/usr/bin/python

import pygst
pygst.require("0.10")
import gst

player = gst.Pipeline("player")
source = gst.element_factory_make("videotestsrc", "testsource")
effect = gst.element_factory_make("clockoverlay", "clock")
freeze = gst.element_factory_make("imagefreeze", "freeze")
colorspace = gst.element_factory_make("ffmpegcolorspace", "colorspace")
sink = gst.element_factory_make("ximagesink", "imagesink")

player.add(source, effect, freeze, colorspace, sink)
gst.element_link_many(source, effect, freeze, colorspace, sink)
player.set_state(gst.STATE_PLAYING)

while True:
  inp = raw_input("Press enter:")
  player.set_state(gst.STATE_READY)
  player.set_state(gst.STATE_PLAYING)

whenever you hit "enter" in the console a new screenshot will be taken (from the videotest with clockoverlay) and displayed.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • 2
    imagefreeze will create a videostream from a single image (repeat image as a stream). Imho Oleg want the opposite - single image from a stream. – ensonic Aug 28 '12 at 09:00
  • `imagefreeze` will freeze any image-source that comes in, and repeat the frozen image. it can be used to create a videostream from a still image, but it can also be used to create a frozen videostream from a "live" videostream....at least my example freezes the `videotestsrc` (+ `clockoverlay`) and will re-freeze on user interaction - which i think is what the OP requested – umläute Aug 28 '12 at 11:11
  • it is useful, and I really like it...but the problem is that I need to extract frame from the flow... initial module writes video from the web cam on disk, I have web interface with button... when clicked I need to show current screenshot to the user. so, I'm trying to find the solution how to write click handler – oleg.foreigner Sep 06 '12 at 09:57