title: How to stream pc webcam with rtsp and GStreamer on python
body: <p>I'm trying to stream my laptop webcam frames with rtsp with python.
  To do this I'm using GStreamer.
  Browsing some examples on the web, I get the following code and I tested it with a local video in .mp4 format</p>
  
  <pre><code>#!/usr/bin/env python
  import sysimport gi
  gi.require_version('Gst', '1.0')
  gi.require_version('GstRtspServer', '1.0')
  from gi.repository import Gst, GstRtspServer, GObject, GLib
  
  loop = GLib.MainLoop()
  Gst.init(None)
  
  class TestRtspMediaFactory(GstRtspServer.RTSPMediaFactory): 
      def __init__(self):             
          GstRtspServer.RTSPMediaFactory.__init__(self)
  
      def do_create_element(self, url): 
          #set mp4 file path to filesrc's location property 
          src_demux = "filesrc location=/home/user1/Videos/720.mp4 ! qtdemux name=demux" 
          h264_transcode = "demux.video_0" 
          #uncomment following line if video transcoding is necessary 
          #h264_transcode = "demux.video_0 ! decodebin ! queue ! x264enc" 
          pipeline = "{0} {1} ! queue ! rtph264pay name=pay0 config-interval=1 pt=96".format(src_demux, h264_transcode) 
          print ("Element created: " + pipeline) 
          return Gst.parse_launch(pipeline)
  
  class GstreamerRtspServer(): 
      def __init__(self): 
          self.rtspServer = GstRtspServer.RTSPServer() 
          self.rtspServer.set_service("7000") 
          factory = TestRtspMediaFactory() 
          factory.set_shared(True) 
          mountPoints = self.rtspServer.get_mount_points() 
          mountPoints.add_factory("/stream1", factory) 
          self.rtspServer.attach(None)
  
  if __name__ == '__main__': 
      s = GstreamerRtspServer() 
      loop.run()
  </code></pre>
  
  <p>It expose the stream on the address 127.0.0.1:7000/stream1.
  So, if I try with the following command from the terminal, I can see the video in a window</p>
  
  <pre><code>gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:7000/stream1 ! queue ! rtph264depay ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! autovideosink
  </code></pre>
  
  <p>Now, I want to change the pipeline to change the source from the mp4 local video to my laptop webcam. I tried with the following:</p>
  
  <pre><code>vl42src device=/dev/video0 ! decodebin ! x264enc ! rtph264pay name=pay0 config-interval=1 pt=96
  </code></pre>
  
  <p>And, by terminal side, I try to connect with the same pipeline.
  It don't works. This is the error I get:</p>
  
  <pre><code>gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:7000/stream1 ! queue ! rtph264depay ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! autovideosink --gst-debug=3 -v
  Setting pipeline to PAUSED ...
  Pipeline is live and does not need PREROLL ...
  Got context from element 'autovideosink0-actual-sink-vaapi': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)"\(GstVaapiDisplayGLX\)\ vaapidisplayglx1";
  Progress: (open) Opening Stream
  Progress: (connect) Connecting to rtsp://127.0.0.1:7000/stream1
  Progress: (open) Retrieving server options
  Progress: (open) Retrieving media info
  0:00:00.113988576 11172 0x5589f65698f0 WARN                 rtspsrc gstrtspsrc.c:6563:gst_rtspsrc_send:&lt;rtspsrc0&gt; error: Unhandled error
  0:00:00.114040409 11172 0x5589f65698f0 WARN                 rtspsrc gstrtspsrc.c:6563:gst_rtspsrc_send:&lt;rtspsrc0&gt; error: Service Unavailable (503)
  ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Unhandled error
  0:00:00.114134907 11172 0x5589f65698f0 WARN                 rtspsrc gstrtspsrc.c:7951:gst_rtspsrc_open:&lt;rtspsrc0&gt; can't get sdp
  0:00:00.114188780 11172 0x5589f65698f0 WARN                 rtspsrc gstrtspsrc.c:6031:gst_rtspsrc_loop:&lt;rtspsrc0&gt; we are not connected
  Additional debug info:
  gstrtspsrc.c(6563): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
  Service Unavailable (503)
  ERROR: pipeline doesn't want to preroll.
  Setting pipeline to PAUSED ...
  Setting pipeline to READY ...
  Setting pipeline to NULL ...
  Freeing pipeline ...
  </code></pre>
  
  <p>What I'm wrong with this?
  Did anyone know a pipeline that can be used to make things working from my webcam?</p>
  
  <p>Thanks in advance</p>