直播 RTMP 至 HTML5
Live streaming RTMP to HTML5
我有一个来自 Unreal Media Server
的 RTMP
直播,我需要在带有 <video>
标签的 HTML5 页面上显示。到目前为止,我正在考虑使用 ffmpeg 库使用 H.264 编解码器对流进行转码并将其输出到 .mp4 文件,然后通过 http 协议访问它,如下所示:http://ip_addr/output_from_ffmpeg.mp4
然而,我不确定这是否会从头开始播放整个输出文件或直播。我当前用于对流进行转码的 ffmpeg 命令是:
ffmpeg -i rtmp://IP_addr_of_rtmp_stream:5119/live/Roulette -c:v libx264 -maxrate 1000k -bufsize 2000k -g 50 output.mp4
谁能指出我正确的方向?我还在文档中读到 ffserver 能够实现这一点,但是 windows 构建不可用。
您不能使用 mp4
格式进行直播,也不能仅使用 HTML5 标签进行直播。您的命令将流记录在静态 mp4
文件中,以通过 HTTP 渐进式下载提供服务。
RTMP
需要 Flash 播放器。备选方案包括 HLS
和支持桌面 Flash 回退的网络播放器(例如 Clappr、JWPlayer、Flowplayer)或 DASH
通过支持它的浏览器上的媒体源扩展 (MSE)。
我最终使用 VLC Player(使用 FFmpeg)通过 H.264
编解码器对 RTMP 流进行转码,并使用 VLC 的内置 http 服务器以 [=13=] 格式显示。我还启动了另一个 VLC 实例,用于 HLS
流式传输基于 Apple 的设备。以下是 H.264
和 HLS
的两个命令(注意:我在 windows 上执行此操作,并使用 wamp
进行 HLS 流式传输,因为 VLC 不提供传输方式在这种情况下):
vlc.exe -I dummy rtmp://_ip_addr_of_the_rtmp_stream :network-caching=0 :sout=#transcode{vcodec=theo,vb=512,scale=1,acodec=none}:http{mux=ogg,dst=:8181/stream.ogg} :no-sout-rtp-sap :no-sout-standard-sap :sout-keep
vlc.exe -I dummy rtmp://_ip_addr_of_the_rtmp_stream :network-caching=0 :sout="#transcode{vcodec=h264,vb=500, venc=x264{aud,profile=baseline,level=30,keyint=30,ref=1}, aenc=none} :std{access=livehttp{seglen=10,delsegs=true,numsegs=5, index=C:\wamp\www\stream.m3u8, index-url=http://_ip_addr_of_your_web_server/stream-########.ts}, mux=ts{use-key-frames}, dst=C:\wamp\www\stream-########.ts}"
然后在html页面中简单地:
<video width="320" height="240" controls autoplay>
<source src="http://_ip_addr_of_your_web_server/stream.m3u8" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
<source src="http://_ip_addr_of_your_web_server:8181/stream.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
延伸阅读:
https://wiki.videolan.org/Documentation:Streaming_HowTo/Streaming_for_the_iPhone/
Unreal Media Server v12(2016 年 9 月 15 日发布)完全支持您的需求。
您不需要转码任何内容。之前通过 RTMP 播放的同一广播,现在可以在 HTML5 视频标签中播放。
我有一个来自 Unreal Media Server
的 RTMP
直播,我需要在带有 <video>
标签的 HTML5 页面上显示。到目前为止,我正在考虑使用 ffmpeg 库使用 H.264 编解码器对流进行转码并将其输出到 .mp4 文件,然后通过 http 协议访问它,如下所示:http://ip_addr/output_from_ffmpeg.mp4
然而,我不确定这是否会从头开始播放整个输出文件或直播。我当前用于对流进行转码的 ffmpeg 命令是:
ffmpeg -i rtmp://IP_addr_of_rtmp_stream:5119/live/Roulette -c:v libx264 -maxrate 1000k -bufsize 2000k -g 50 output.mp4
谁能指出我正确的方向?我还在文档中读到 ffserver 能够实现这一点,但是 windows 构建不可用。
您不能使用 mp4
格式进行直播,也不能仅使用 HTML5 标签进行直播。您的命令将流记录在静态 mp4
文件中,以通过 HTTP 渐进式下载提供服务。
RTMP
需要 Flash 播放器。备选方案包括 HLS
和支持桌面 Flash 回退的网络播放器(例如 Clappr、JWPlayer、Flowplayer)或 DASH
通过支持它的浏览器上的媒体源扩展 (MSE)。
我最终使用 VLC Player(使用 FFmpeg)通过 H.264
编解码器对 RTMP 流进行转码,并使用 VLC 的内置 http 服务器以 [=13=] 格式显示。我还启动了另一个 VLC 实例,用于 HLS
流式传输基于 Apple 的设备。以下是 H.264
和 HLS
的两个命令(注意:我在 windows 上执行此操作,并使用 wamp
进行 HLS 流式传输,因为 VLC 不提供传输方式在这种情况下):
vlc.exe -I dummy rtmp://_ip_addr_of_the_rtmp_stream :network-caching=0 :sout=#transcode{vcodec=theo,vb=512,scale=1,acodec=none}:http{mux=ogg,dst=:8181/stream.ogg} :no-sout-rtp-sap :no-sout-standard-sap :sout-keep
vlc.exe -I dummy rtmp://_ip_addr_of_the_rtmp_stream :network-caching=0 :sout="#transcode{vcodec=h264,vb=500, venc=x264{aud,profile=baseline,level=30,keyint=30,ref=1}, aenc=none} :std{access=livehttp{seglen=10,delsegs=true,numsegs=5, index=C:\wamp\www\stream.m3u8, index-url=http://_ip_addr_of_your_web_server/stream-########.ts}, mux=ts{use-key-frames}, dst=C:\wamp\www\stream-########.ts}"
然后在html页面中简单地:
<video width="320" height="240" controls autoplay>
<source src="http://_ip_addr_of_your_web_server/stream.m3u8" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
<source src="http://_ip_addr_of_your_web_server:8181/stream.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
延伸阅读:
https://wiki.videolan.org/Documentation:Streaming_HowTo/Streaming_for_the_iPhone/
Unreal Media Server v12(2016 年 9 月 15 日发布)完全支持您的需求。 您不需要转码任何内容。之前通过 RTMP 播放的同一广播,现在可以在 HTML5 视频标签中播放。