Stream webcam video with gstreamer 1.0 over UDP to PC

柔情痞子 提交于 2020-01-12 06:20:12

问题


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?


回答1:


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"




回答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.



来源:https://stackoverflow.com/questions/27969541/stream-webcam-video-with-gstreamer-1-0-over-udp-to-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!