问题描述
我尝试使用带有相机模块的Raspberry Pi 3制作H264 RTP流到视频标签。
I try to make a H264 RTP stream from a Raspberry Pi 3 with a camera module to a video tag.
使用以下代码启动流
raspivid -t 0 -h 720 -w 1080 -fps 25 -hf -b 2000000 -o - | \
gst-launch-1.0 -v fdsrc \
! h264parse \
! rtph264pay \
! gdppay \
! udpsink host="192.168.0.11" port=5000
然后我提供一个带有视频标签的简单网页:
Then I provide a simple webpage with a video tag:
<video id="videoTag" src="h264.sdp" autoplay>
<p class="warning">Your browser does not support the video tag.</p>
</video>
src引用以下SDP文件:
The src references the following SDP file:
v=0
m=video 5000 RTP/AVP 96
c=IN IP4 192.168.0.51
a=rtpmap:96 H264/90000
当我加载网页时没有任何反应,并且js控制台完全是空的。
When I load the webpage nothing happens, and the js console is completely empty.
所以我尝试用VLC查看流,并收到以下错误:
So I tried to view the stream with VLC, and got the following error:
[00007efd80c03ea8] es demux error: cannot peek
[00007efd80c03ea8] es demux error: cannot peek
[00007efd80c03ea8] live555 demux error: no data received in 10s, aborting
我认为根本没有UDP通信,所以我从远程机器上测试了它:
I thought that there had been no UDP communication at all, So I tested it from a remote machine:
gst-launch-1.0 udpsrc port=5000 \
caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" \
! fakesink dump=true
ans收到UDP数据包。所以我研究了前方,发现了这个:
ans received UDP packets. So I researched forward and found this:
现在很明显,我需要2个端口来传输数据并建立RTP控制协议。但是我不知道如何用gstreamer做到这一点。
Now it is clear that I need 2 ports one to stream data and to establish RTP Control Protocol. However I have no idea how can I do it with gstreamer.
我跑的时候最糟糕的是:
Worst of all when I run:
gst-inspect-1.0 | grep -i rtcp
我一无所获。
如何使用RTP协议将gstreamer-1.0的视频流启动到网页内的视频标签?
How can start video stream with gstreamer-1.0 to a video tag inside a webpage using the RTP protocol?
更新
使用 videotestsrc 作为gstreamer videosoruce并删除 gdppay (它导致无效的RTP有效载荷错误)我能够查看来自的视频流具有VLC和此gstreamer代码的远程客户端:
Using videotestsrc as gstreamer videosoruce and removing gdppay (it caused invalid RTP payload error) I was able to view the video stream from a remote client with VLC and with this gstreamer code:
gst-launch-1.0 udpsrc port=5000 \
caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" \
! rtph264depay \
! avdec_h264 \
! autovideosink
推荐答案
首先你需要提供更多信息:哪个浏览器(试试chrome,也称safari有更好的流媒体支持)..
First you need to provide more info: which browser (try chrome, also safari is said to have better streaming support)..
对于SDP我觉得你错过了它的h264的信息?
和是gdppay仅适用于内部GStreamer only流媒体(gdp意为GStreamer数据协议,其他人无法理解:))。
To the SDP I think you are missing the info that its h264?And yes gdppay is just for internal "GStreamer only" streaming (gdp means "GStreamer Data Protocol" which noone else understands:) ).
如果你真的希望GStreamer流式RTSP您可以使用gstreamer - 这在单独的仓库中,例如在Ubuntu的一些软件包中包含。
If you really want GStreamer to stream RTSP you may use gstreamer rtsp server implementation - this is in separate repo and is incuded in some packages in Ubuntu for example.
如果你只想要rtp你正确地做到了 - 正如你看到这种方法适用于例如vlc ..但是是什么让你认为sdp将在HTML5中运行(我只是问我没有最新的信息)?
If you want just rtp you are doing it correctly - as you see this approach works with for example vlc.. but what makes you think the sdp will work in HTML5 (I am just asking I do not have up to date infos on this)?
您也可以使用netcat对此进行测试 - 这对于这类调试来说很好。
你可以这样假冒rtp客户:
You can test this also with netcat - its fine for these kind of debugging.you can fake a rtp client this way:
nc -u -l 5000
哪会将流量转出。
我读
Here you have some js for processing hls:https://github.com/dailymotion/hls.js
您还可以尝试ogg / vorbis / theora等等(声音)疯了,但是你可以试一试,我读到它适合流媒体的地方)..
You can also try ogg/vorbis/theora and such stuff (sounds crazy, but you can give it a shot, I read somewhere that its suitable for streaming)..
这篇关于具有gstreamer-1.0的H264 RTP流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!