1

I am new to gstreamer and want to live streaming from a webcam using gstreamer with python.

How can I do it?

If anyone has a related article or source code please share.

I have tried this code:

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

can anyone please guide me what will be the python code for the gstreamer server command

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

and the gstreamer client command

gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink

for mjpeg encoding.

  • sorry for the code format.....but anyone plz help. – Rup Samanta Jun 21 '17 at 09:56
  • Can you format the code, explain what it is trying to do, and explain what issues you are having with it ? – PaulNUK Jun 21 '17 at 09:58
  • if a video is playing in my laptop i have to transmit the screen of my laptop (which is possible by screengrabbing) to my desktop using gstreamer with python and in pc i have to save it as pickle file. as i am new to python and gstreamer i am facing difficulty and don't have any clue how to do it(i have gone through many resources but none are useful) so if anyone can please help me doing my project. (p.s - the code is of getting video from webcam nd transmitting it to pc.....instead of screengrabbing i use a webcam to get the images of my laptop screen) – Rup Samanta Jun 22 '17 at 07:26
  • attempted to reformat the code to make it more clear – garyh Jun 22 '17 at 08:07
  • thanks garyh. if you guys help me to do another code for my project as i have described in earlier comments it will be of immense help. – Rup Samanta Jun 22 '17 at 09:04
  • what will be the python code for this gstreamer command.................... gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! autovideosink............................ and this.............................. 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............................ – Rup Samanta Jun 22 '17 at 09:58

0 Answers0