我是 gstreamer 的新手,想使用带有 python 的 gstreamer 从网络摄像头直播。
我该怎么做?
如果有人有相关文章或源代码,请分享。
我试过这段代码:
视频服务器.py
import gobject, pygst
pygst.require("0.10")
import gst
source pad
def new_decode_pad(dbin, pad, islast):
pad.link(decode.get_pad("xvimagesink"))
pipeline = gst.Pipeline("server")
tcpsrc = gst.element_factory_make("tcpserversrc", "source")
pipeline.add(tcpsrc)
tcpsrc.set_property("host", "localhost")
tcpsrc.set_property("port", 5000)
decode = gst.element_factory_make("decodebin", "decode")
decode.connect("new-decoded-pad", new_decode_pad)
pipeline.add(decode)
tcpsrc.link(decode)
def new_xvimage_pad(ximg, pad, islast):
xvimage = gst.element_factory_make("xvimagesink", "imagesink")
xvimage.connect("new-xvimaged-pad", new_xvimage_pad)
pipeline.add(xvimage)
decode.link(xvimage)
pipeline.set_state(gst.STATE_PLAYING)
loop = gobject.MainLoop()
loop.run()
视频客户端.py
import gobject, pygst
pygst.require("0.10")
import gst
# create a pipeline and add [ filesrc ! tcpclientsink ]
pipeline = gst.Pipeline("client")
src = gst.element_factory_make("filesrc", "source")
src.set_property("location", "/home/sam/Desktop/ramstien.mpg")
pipeline.add(src)
def new_mux_pad(mux, pad, islast):
pad.link(mux.get_pad("mpeg"))
mux = gst.element_factory_make("dvddemux", "mux")
mux.connect("new-muxed-pad", new_mux_pad)
pipeline.add(mux)
src.link(mux)
def new_mpeg_pad(mpg, pad, islast):
pad.link(mpeg.get_pad("theora"))
mpeg = gst.element_factory_make("mpeg2dec", "mpeg")
mpeg.connect("new-mpeged-pad", new_mpeg_pad)
pipeline.add(mpeg)
mux.link(mpeg)
def new_theoraenc_pad(thr, pad, islast):
pad.link(theora.get_pad("ogg"))
theora = gst.element_factory_make("theoraenc", "theora")
theora.connect("new-theoraenced-pad", new_theoraenc_pad)
pipeline.add(theora)
mpeg.link(theora)
def new_ogg_pad(og, pad, islast):
ogg = gst.element_factory_make("oggmux", "ogg")
ogg.connect("new-ogged-pad", new_ogg_pad)
pipeline.add(ogg)
theora.link(ogg)
client = gst.element_factory_make("tcpclientsink", "client")
pipeline.add(client)
client.set_property("host", "localhost")
client.set_property("port", 5000)
ogg.link(client)
pipeline.set_state(gst.STATE_PLAYING)
# enter into a mainloop
loop = gobject.MainLoop()
loop.run()
谁能指导我gstreamer服务器命令的python代码是什么
gst-launch-1.0 -v ximagesrc use-damage=false xname=/usr/lib/torcs/torcs-bin ! videoconvert ! videoscale ! video/x-raw,format=I420,width=800,height=600,framerate=25/1 ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000
和 gstreamer 客户端命令
gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink
用于 mjpeg 编码。