小编tir*_*oto的帖子

使用Twisted创建客户端/服务器

我正在尝试使用Twisted创建客户端/服务器.我想创建一个守护进程,它将作为客户端连接到另一台服务器,并充当其他客户端的服务器.我写了类似的东西我认为描述我的问题:

server = sys.argv[1]
control_port = 8001

class ControlClient(protocol.Protocol):
    def makeConnection(self, transport):
        [some code here -snip-]
        self.firstOrder(order, transport)

    def firstOrder(self, action, transport):
        self.t = transport
        self.t.write(action + "\0")

    def sendOrder(self, action):
        self.t.write(action + "\0")

    def dataReceived(self, data):
        [some code here -snip-]
        [HERE I WANT TO SEND DATA TO CLIENTS CONNECTED TO MY TWISTED SERVER, USING CONTROL SERVER]

class ControlServer(ControlClient):
    def dataReceived(self, data):
        print "client said " + data

    def makeConnection(self, transport):
        self.t = transport
        self.t.write("make connection")
        print "make connection"

    def …
Run Code Online (Sandbox Code Playgroud)

python client twisted

6
推荐指数
1
解决办法
5705
查看次数

使用python-gstreamer播放RTSP

我使用gstreamer从IP摄像机(如Axis)播放RTSP流.我使用如下命令行:

gst-launch-0.10 rtspsrc location=rtsp://192.168.0.127/axis-media/media.amp latency=0 ! decodebin ! autovideosink
Run Code Online (Sandbox Code Playgroud)

它工作正常.

我想用pygtk中的gui控制它,所以我使用gstreamer python绑定.我写了这段代码:

[...]
self.player = gst.Pipeline("player")
source = gst.element_factory_make("rtspsrc", "source")
source.set_property("location", "rtsp://192.168.0.127/axis-media/media.amp")
decoder = gst.element_factory_make("decodebin", "decoder")
sink = gst.element_factory_make("autovideosink", "sink")

self.player.add(source, decoder, sink)
gst.element_link_many(source, decoder, sink)

bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
[...]
Run Code Online (Sandbox Code Playgroud)

但它不起作用并退出此消息:

gst.element_link_many(source, decoder,sink)
gst.LinkError: failed to link source with decoder
Run Code Online (Sandbox Code Playgroud)

我也尝试用这个来改进我的CLI,因为我只使用h264:

gst-launch-0.10 -v rtspsrc location=rtsp://192.168.0.127/axis-media/media.amp ! rtph264depay !  ffdec_h264 ! xvimagesink
Run Code Online (Sandbox Code Playgroud)

并在我的python代码中实现它:

[...]
self.player = gst.Pipeline("player")
source = gst.element_factory_make("rtspsrc", "source")
depay = gst.element_factory_make("rtph264depay", "depay") …
Run Code Online (Sandbox Code Playgroud)

python rtsp gstreamer h.264 ip-camera

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×2

client ×1

gstreamer ×1

h.264 ×1

ip-camera ×1

rtsp ×1

twisted ×1