GStreamer如何从流中提取视频帧?

时间:2022-07-07 21:24:14

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???

这是用于从服务器捕获流视频的python代码。但是我需要写一个函数来从流中提取一个帧。它将是一个按钮。点击它将显示当前帧。我没有想法。有人能帮我吗???

    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)

2 个解决方案

#1


0  

you want to use the imagefreeze element. something like:

要使用imagefreeze元素。喜欢的东西:

#!/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.

无论何时,当您点击控制台的“enter”时,将会使用一个新的屏幕截图(从视频测试到时钟覆盖)并显示。

#2


0  

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

如果您可以使用playbin2,您可以使用“convert-frame”动作信号。否则,查看实现和重用。

#1


0  

you want to use the imagefreeze element. something like:

要使用imagefreeze元素。喜欢的东西:

#!/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.

无论何时,当您点击控制台的“enter”时,将会使用一个新的屏幕截图(从视频测试到时钟覆盖)并显示。

#2


0  

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

如果您可以使用playbin2,您可以使用“convert-frame”动作信号。否则,查看实现和重用。