title: Stream webcam video with gstreamer 1.0 over UDP to PC
body: <p>Im trying to stream video from a Raspberry Pi (on Raspbian) to a Windows 7 PC like in this video: <a href="https://www.youtube.com/watch?v=lNvYanDLHZA" rel="nofollow noreferrer">https://www.youtube.com/watch?v=lNvYanDLHZA</a></p>
  
  <p>I have a Logitech C270 connected to the Raspberry Pi, and have managed to stream webcam video over TCP using:</p>
  
  <pre class="lang-bash prettyprint-override"><code>gst-launch v4l2src device=/dev/video0 ! \
  'video/x-raw-yuv,width=640,height=480' ! \
  x264enc pass=qual quantizer=20 tune=zerolatency ! \
  rtph264pay ! tcpsink host=$pi_ip port=5000
  </code></pre>
  
  <p>from my Pi. Receive this using VLC works, but with a 3 sec delay.
  I want to do this over UDP to get a shorter delay (correct me if I'm wrong). But cannot for the life of me figure it out. I have tried following: </p>
  
  <pre class="lang-bash prettyprint-override"><code>gst-launch-1.0 v4l2src device=/dev/video0 ! \
  'video/x-raw-yuv,width=640,height=480' ! \
  x264enc pass=qual quantizer=20 tune=zerolatency ! \ 
  rtph264pay ! udpsink host=$pc_ip port=1234
  </code></pre>
  
  <p>and</p>
  
  <pre class="lang-bash prettyprint-override"><code>gst-launch-1.0 udpsrc port=1234 ! \ 
  "application/x-rtp, payload=127" ! \
  rtph264depay ! ffdec_h264 ! fpsdisplaysink sync=false text-overlay=false
  </code></pre>
  
  <p>For the Pi and PC side, respectively (taken from 
  <a href="https://stackoverflow.com/questions/7669240/webcam-streaming-using-gstreamer-over-udp">Webcam streaming using gstreamer over UDP</a>)
  but with no luck. (tried to change the video/x-raw-yuv to fit 1.0 version but still without luck)</p>
  
  <p>Any hints would be highly appreciated!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>With the raspi camera (not the webcam) the following works:</p>
  
  <p>Windows batch script:</p>
  
  <pre class="lang-bat prettyprint-override"><code>@echo off
  cd C:\gstreamer\1.0\x86_64\bin
  gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, payload=96 !        
  rtpjitterbuffer ! rtph264depay ! avdec_h264 ! fpsdisplaysink sync=false    
  text-overlay=false
  </code></pre>
  
  <p>Raspberry Pi Bash Script:</p>
  
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  clear
  raspivid -n -t 0 -rot 270 -w 960 -h 720 -fps 30 -b 6000000 -o - | gst-       
  launch-1.0 -e -vvvv fdsrc ! h264parse ! rtph264pay pt=96 config-interval=5 !   
  udpsink host=***YOUR_PC_IP*** port=5000
  </code></pre>
  
  <p>But I cannot figure out how to use to webcam instead of the raspberry pi camera (i.e. v4l2src instead of raspivid) in the same manner</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>The following works, but is very slow and has a huge delay:</p>
  
  <p>RPi
  </p>
  
  <pre><code>gst-launch-1.0 -vv -e v4l2src device=/dev/video0  \
  ! videoscale \
  ! "video/x-raw,width=400,height=200,framerate=10/1" \
  ! x264enc pass=qual quantizer=20  tune=zerolatency  \
  ! h264parse \
  ! rtph264pay config-interval=5 pt=96  \
  ! udpsink host=$myip port=$myport
  </code></pre>
  
  <p>PC:
  </p>
  
  <pre><code>gst-launch-1.0 -e -v udpsrc port=5001 ! ^
  application/x-rtp, payload=96 ! ^
  rtpjitterbuffer ! ^
  rtph264depay ! ^
  avdec_h264 ! ^
  autovideosink sync=false text-overlay=false
  </code></pre>
  
  <p>I now suspect that (thanks to hint from @Mustafa Chelik) that the huge lag is due to the fact that the raspberry pi has to encode the webcam video, while the raspberry pi video is already encoded, not sure if this makes sense though?</p>