使用UDP将gstreamer 1.0的网络摄像头视频流式传输到PC [英] Stream webcam video with gstreamer 1.0 over UDP to PC

查看:916
本文介绍了使用UDP将gstreamer 1.0的网络摄像头视频流式传输到PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Raspberry Pi(在Raspbian上)的视频流传输到Windows 7 PC,如以下视频所示:

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

我有一个连接到Raspberry Pi的Logitech C270,并设法使用以下方法通过TCP流网络摄像头视频:

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

来自我的Pi.使用VLC进行接收,但延迟3秒. 我想通过UDP执行此操作,以缩短延迟(如果我输入错了,请纠正我).但是我一生无法解决.我尝试过以下操作:

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

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

分别针对Pi端和PC端(取自 使用基于UDP的gstreamer进行网络摄像头传输) 但没有运气. (试图将video/x-raw-yuv更改为适合1.0版本,但仍然没有运气)

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)

任何提示将不胜感激!

修改

使用raspi摄像头(而不是网络摄像头)可以进行以下工作:

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

Windows批处理脚本:

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脚本:

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

但是我无法弄清楚如何使用网络摄像机以相同的方式代替树莓派摄像机(即v4l2src而不是raspivid)

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

编辑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

我现在怀疑(感谢@Mustafa Chelik的暗示),巨大的滞后是由于树莓派必须对网络摄像头视频进行编码,而树莓派已经对视频进行编码,因此不确定知道吗?

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?

推荐答案

http://www.z25.org/static/ rd /videostreaming_intro_plab/

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

以下内容对于将树莓派上的Logitech c270的视频从Windows 7 pc流式传输非常有效:

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

PC端:

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

RPi端:

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

我怀疑在树莓派上,网络摄像机视频到h264的编码太慢了,但是网络摄像机已经给出了jpeg帧,因此不需要使用"image/jpeg"进行编码

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"

这篇关于使用UDP将gstreamer 1.0的网络摄像头视频流式传输到PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆