3

这是用于从服务器捕获流式视频的 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)
4

2 回答 2

0

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

于 2012-08-17T21:20:01.503 回答
-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.

于 2012-08-22T17:35:56.197 回答