2017-05-04 6 views
2

私は、Pythonでネットワークビデオストリームをキャプチャして表示しようとしています。ストリームは、次のコマンドを使用して(私のラップトップ上で)作成されています:Pythonでgstreamerネットワークビデオをキャプチャする

gst-launch-1.0 v4l2src ! videorate ! video/x-raw,framerate=2/1,width=640,height=480 ! x264enc pass=qual quantizer=20 tune=zerolatency ! rtph264pay config-interval=10 pt=96 ! udpsink host=127.0.0.1 port=5000 

これは、ウェブカメラの入力を受け取り、UDPポート経由でストリーム。私はストリームをキャプチャし、以下のコマンドでそれを表示することができます。今、私はPythonスクリプトと同じ(キャプチャ)をやろうとしています

gst-launch-1.0 udpsrc port=5000 ! "application/x-rtp, payload=127" ! rtph264depay ! avdec_h264 ! xvimagesink sync=false 

が、不足なし。ここに私のコードは次のとおりです。

import gi 
gi.require_version('Gst', '1.0') 
from gi.repository import Gst 

udpPipe = Gst.pipeline("player") 
source = Gst.ElementFactory.make('udpsrc', None) 
source.set_property("port", 5000) 
source.set_property("host", "127.0.0.1") 

rdepay = Gst.ElementFactory.make('rtph264depay', 'rdepay') 
vdecode = Gst.ElementFactory.make('avdec_h264', 'vdecode') 
sink = Gst.ElementFactory.make('xvimagesink', None) 

udpPipe.add(source, rdepay, vdecode, sink) 
gst.element_link_many(source, rdepay, vdecode, sink) 
udpPipe.set_state(gst.STATE_PLAYING) 

私は取得していますエラーは次のとおりです。

/usr/lib/python2.7/dist-packages/gi/overrides/Gst.py:56: Warning: /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:1674: parameter 1 of type '<invalid>' for signal "GstBus::sync_message" is not a value type 
    Gst.Bin.__init__(self, name=name) 
/usr/lib/python2.7/dist-packages/gi/overrides/Gst.py:56: Warning: /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:1674: parameter 1 of type '<invalid>' for signal "GstBus::message" is not a value type 
    Gst.Bin.__init__(self, name=name) 
Traceback (most recent call last): 
    File "getUdp.py", line 13, in <module> 
    source = Gst.ElementFactory.make('udpsrc', None) 
    File "/usr/lib/python2.7/dist-packages/gi/overrides/Gst.py", line 217, in make 
    return Gst.ElementFactory.make(factory_name, instance_name) 
TypeError: unbound method fake_method() must be called with ElementFactory instance as first argument (got str instance instead) 

任意のアイデア? :-(

+0

私はちょうど同じ問題に遭遇してきました。私はあなたのことを見Python 2.7をそのまま使う私はPython 3環境でGstをテストしました。今私はPython 2のアプリケーションで実装したいとこのエラーが発生しました。私はまだこれがどのように修正できるのか分かりません。しかし、私はとにかくアプリケーションをPython 3に移植する予定でした。しかし、それは時間がかかります。それが動作し、私はこのリンクを忘れていない場合、私はあなたにアップデートを提供します。 – exhuma

答えて

2

私も、今日のDebian 9.3(ストレッチ)で同じエラーを得た。 は、明示的にGst.initで問題が解決呼び出す。

コード次のPython 2.7と3.5の両方で私のシステムでxvimagesinkウィンドウをポップアップしました。

#!/usr/bin/python 
import sys 
import gi 
gi.require_version('GLib', '2.0') 
gi.require_version('Gst', '1.0') 
from gi.repository import GLib, Gst 

Gst.init(sys.argv) 

udpPipe = Gst.Pipeline("player") 
source = Gst.ElementFactory.make('udpsrc', None) 
source.set_property("port", 5000) 
#source.set_property("host", "127.0.0.1") 
caps = Gst.caps_from_string("application/x-rtp, payload=127") 
source.set_property("caps", caps) 

rdepay = Gst.ElementFactory.make('rtph264depay', 'rdepay') 
vdecode = Gst.ElementFactory.make('avdec_h264', 'vdecode') 
sink = Gst.ElementFactory.make('xvimagesink', None) 
sink.set_property("sync", False) 

udpPipe.add(source, rdepay, vdecode, sink) 

#Gst.element_link_many(source, rdepay, vdecode, sink) 
source.link(rdepay) 
rdepay.link(vdecode) 
vdecode.link(sink) 

udpPipe.set_state(Gst.State.PLAYING) 

GLib.MainLoop().run() 

私はPyGObjectとPythonスクリプトにGST-起動コマンドラインを変換するGst.initを呼び出し、メインループを実行する必要があると思います。

関連する問題