GStreamer How to extract video frame from the flow?

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

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) 

回答1:

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.



回答2:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!