Gstreamer消息以信号通知来自视频源(网络摄像头)的新帧 [英] Gstreamer message to signal new frame from video source (webcam)

查看:389
本文介绍了Gstreamer消息以信号通知来自视频源(网络摄像头)的新帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gstreamer将网络摄像头中的视频流另存为一系列图像.到目前为止,我已经编写了这段代码...

I am trying to save a stream from webcam as series of image using gstreamer. I have written this code so far...

#!/usr/bin/python
import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst

 def __init__(self):
      #.... 
      # Code to create a gtk Window
      #....
      self.player = gst.Pipeline("player")
      source = gst.element_factory_make("v4l2src", "video-source")
      sink = gst.element_factory_make("xvimagesink", "video-output")
      caps = gst.Caps("video/x-raw-yuv, width=640, height=480")
      filter = gst.element_factory_make("capsfilter", "filter")
      filter.set_property("caps", caps)
      self.player.add(source, filter, sink)
      gst.element_link_many(source, filter, sink)

此后,我试图在总线上创建一个信号,以侦听来自源或接收器的任何消息,以指示已发送或接收了新帧,以便可以保存它.

After this, I am trying to create a signal over the bus to listen for any message from the source or the sink to indicate a new frame has been sent or received, so that it can be saved.

      bus = self.player.get_bus()
      bus.add_signal_watch()
      bus.connect("message::any", self.save_file,"Save file")

其中save_file是我的回调,我要在其中保存文件.

where save_file is my callback, where I want to save the file.

def save_file(self, bus, msg):
      print  "SAVED A NEW FILE"

我有两个问题,

  1. 如何调用此回调.消息::任何都不起作用.
  2. 调用此消息后,如何访问图像缓冲区.

更新(4-12-2012):

UPDATE (4-12-2012):

链接对供参考

  1. v4l的python接口.但这对我没有用.当我尝试使用12.04 Ubuntu时,似乎崩溃了. http://code.google.com/p/python-video4linux2/

  1. A python interface for v4l. But it has not been working for me. It seems to crash when i try to grab on 12.04 Ubuntu. http://code.google.com/p/python-video4linux2/

针对感兴趣者的网络摄像头查看器代码.但这不是我想要的,因为它使用gst-launch并且没有提供我想要的管道控制级别. http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html

A webcam viewer code for those interested. But this is not what I want since it uses gst-launch and does not provide the level of pipeline control I want to have. http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html

推荐答案

Gstreamer总线不适用于此目的.放置在那里的消息会发出一些特殊事件的信号,例如流结束,元素状态更改等.流经元素的缓冲区(图像)通常不会在总线上生成任何消息.

Gstreamer Bus is not intended to be used for this purpose. Messages that are put there signal rather some special event like end-of-stream, element state change and so on. Buffers (images) flowing through elements usualy don't generate any messages on the bus.

您可以考虑以下几种可能性:

You may consider several possibilities:

  • 在videosink之前制作"tee"元素,并将"multifilesink"并行连接到videosink(您可能希望看到一些图像编码器,例如pngenc或jpegenc,并将其中之一放在multifilesink之前")
  • 像以前一样,但是使用"appsink",它允许您处理缓冲区并随心所欲
  • 如果要打开和关闭转储,请考虑使用阀门"元素

您可能希望在其他接收器上将"sync"属性设置为false(这将导致在不同步至时钟的情况下尽快转储缓冲区).考虑在tee之后也添加一些队列(在就绪->暂停过渡期间可能不会发生此死锁).

You may want to set "sync" property to false on your additional sink (Which cause buffers to be dumped as soon as possible without syncing to clock). Consider also adding some queues after tee (without this deadlock may occur during ready->paused transition).

这篇关于Gstreamer消息以信号通知来自视频源(网络摄像头)的新帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆