4

Im trying to stream video from a Raspberry Pi (on Raspbian) to a Windows 7 PC like in this video: https://www.youtube.com/watch?v=lNvYanDLHZA

I have a Logitech C270 connected to the Raspberry Pi, and have managed to stream webcam video over TCP using:

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

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:

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

and

gst-launch-1.0 udpsrc port=1234 ! \ 
"application/x-rtp, payload=127" ! \
rtph264depay ! ffdec_h264 ! fpsdisplaysink sync=false text-overlay=false

For the Pi and PC side, respectively (taken from Webcam streaming using gstreamer over UDP) but with no luck. (tried to change the video/x-raw-yuv to fit 1.0 version but still without luck)

Any hints would be highly appreciated!

Edit

With the raspi camera (not the webcam) the following works:

Windows batch script:

@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

Raspberry Pi Bash Script:

#!/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

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

Edit 2

The following works, but is very slow and has a huge delay:

RPi

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

PC:

gst-launch-1.0 -e -v udpsrc port=5001 ! ^
application/x-rtp, payload=96 ! ^
rtpjitterbuffer ! ^
rtph264depay ! ^
avdec_h264 ! ^
autovideosink sync=false text-overlay=false

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?

Community
  • 1
  • 1
simen-andresen
  • 2,217
  • 4
  • 25
  • 39
  • 1
    I don't think changing from TCP to UDP will reduce delay (although I'm not one hundred percent sure about this). Why do you think so? By the way, can RaspberryPi encode HD video and stream it?! Is RaspberryPi that fast to do so? What is the video's framerate? 25? – Mustafa Chelik Jan 15 '15 at 20:00
  • I would think UDP was faster for live streaming, as it is a connectionless protocoll, whereas TCP is connection oriented, and thus have some retransmission delays (the threeway handshake and all that). Not sure if it is able to stream HD video, but it should be able to stream good quality video. Not sure about the framerate, still working on figuring that out. – simen-andresen Jan 16 '15 at 07:10

2 Answers2

3

Found hints to the solution from http://www.z25.org/static/rd/videostreaming_intro_plab/

The following worked very well for streaming video from Logitech c270 on raspberry pi to a windows 7 pc:

PC side:

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

RPi side:

gst-launch-1.0 -v v4l2src device=/dev/video0  \
! "image/jpeg,width=1280, height=720,framerate=30/1" \
! rtpjpegpay \
! udpsink host=$myip port=$myport

I suspect that it was the encoding of the webcam video to h264 that was too slow on the raspberry pi, however the webcamera already gave jpeg frames and thus no encoding was nescessary using "image/jpeg"

simen-andresen
  • 2,217
  • 4
  • 25
  • 39
  • 1
    Doesn't work for me. First I made test: `gst-launch-1.0 -vvv v4l2src device=/dev/video1 ! "image/jpeg,width=800,height=600,framerate=8/1" ! jpegdec ! xvimagesink` Then started streaming: `gst-launch-1.0 -vvv v4l2src device=/dev/video1 ! "image/jpeg,width=800,height=600,framerate=8/1" ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000` And receiving: `gst-launch-1.0 -vvv v4l2src device=/dev/video1 ! "image/jpeg,width=800,height=600,framerate=8/1" ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000` Fails with: "GstJpegDec:jpegdec0: number of components not supported: 0 (max 3)" – beemaster Apr 29 '16 at 05:42
2

I have used for my webcamstream the MJPG-Streamer and get a 0,2 seconds delay. http://wiki.ubuntuusers.de/MJPG-Streamer

And the advantage is that you can watch it with the webbrowser.

Waishon
  • 23
  • 4