使用gstreamer和python的视频流

时间:2017-06-21 09:52:07

标签: python-2.7 video-streaming pygtk python-gstreamer pygst

我是gstreamer的新手,想要使用带有python的gstreamer从网络摄像头直播。

我该怎么做?

如果有人有相关文章或源代码,请分享。

我试过这段代码:

Vidserver.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()

Vidclient.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编码。

0 个答案:

没有答案