博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搭建简单hls直播测试服务
阅读量:4290 次
发布时间:2019-05-27

本文共 2949 字,大约阅读时间需要 9 分钟。

经过实践,通过h5 video 直接m3u8直播, ios 是都没有问题的。android 4.2以上才基本上没问题。4.2以下的各品牌有些问题需要做不同的兼容。

HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议。是苹果公司QuickTime X和iPhone软件系统的一部分。它的工作原理是把整个流分成一个个小的基于HTTP的文件来下载,每次只下载一些。当媒体流正在播放时,客户端可以选择从许多不同的备用源中以不同的速率下载同样的资源,允许流媒体会话适应不同的数据速率。在开始一个流媒体会话时,客户端会下载一个包含元数据的extended M3U (m3u8) playlist文件,用于寻找可用的媒体流。

在测试直播各种兼容性时, 为了测试方便,可以自己搭建一个直播服务器来输入视频流供测试。

rtmp直播流会被动态切分为ts片段和一个不断刷新的u3m8文件, 这个正是h5直播时的方式,因此我们通过配置nginx 的rtmp 模块来支持 rtmp 流媒体直播服务。

主要以下几步, 一些具体的安装步骤就不细说了:

1. 安装强大的音视频转换工具ffmpeg , 相信你对这个不陌生.

2.安装nginx 以及 nginx-rtmp-module 模块(自行搜索下载)

进入你的nginx源码目录, 执行以下命令, 注意, 之前安装的模块如果有其他配置需要带上

./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/nginx-rtmp-module --with-debugmakemake install

 3.配置 nginx 以支持rtmp

在nginx.conf配置文件末尾加上以下配置:

rtmp{        server{                 listen 1935;                chunk_size      4000;                   # For HLS to work please create a directory in tmpfs (/tmp/app here)           # for the fragments. The directory contents is served via HTTP (see          # http{} section in config)          #               # Incoming stream must be in H264/AAC. For iPhones use baseline H264          # profile (see ffmpeg example).          # This example creates RTMP stream from movie ready for HLS:          #               # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264           #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1           #    -f flv rtmp://localhost:1935/hls/movie          #               # If you need to transcode live stream use 'exec' feature.          #                       application hls{                        live on;                        hls on;                         hls_path        /data/maxwellxwma/html5hls/html/hls;                        hls_fragment 5s;                }                       }       }

 这样配置好后, 我们就可以对当前服务器生成rtmp 直播流了,执行以下命令会不断向/data/maxwellxwma/html5hls/html/hls下面写入ts片段和m3u8文件:

./ffmpeg -re -i /data/maxwellxwma/src/t.flv -vcodec copy -acodec copy -f flv rtmp://10.6.224.185/hls/mystream

 如下图所示:

边生成边播放边删除:

4. 配置vhosts支持外部调用m3u8文件播放:

server{        listen 8080;        server_name html5hls.qq.com;        error_log /data/maxwellxwma/logs/nginx/hls.qq.com_error.log;        index index.html index.php;        root /data/maxwellxwma/html5hls/html;        location        /hls{                   #server HLS fragments                types{                          text/html html htm;                        #application/vnd.apple.mpegurl m3u8;                        application/x-mpegurl m3u8;                        video/mp2t ts;                }                       root /data/maxwellxwma/html5hls/html;                index index.html;                expires -1;        }       }

 这些配置可以直接加入到nginx.conf里, 但建立虚拟主机配置,增加可维护性

然后重启nginx  ,  直播服务就搭建好了。

用VLC播放器测试一下正常:

 

5. html5  video 标签嵌入播放测试:

	
HLS Player

 

m3u8文件记录了待播放的ts列表:

好了, 到此终于可以随心随地随时,随心所欲的测试直播了, 还有那些非常蛋疼的安卓兼容 性问题

转载地址:http://xirgi.baihongyu.com/

你可能感兴趣的文章
httpclient 请求http数据,json转map
查看>>
git 常用命令
查看>>
用递归方法建立二叉树
查看>>
用递归方法对二叉树进行先序、中序和后序遍历
查看>>
翻转二叉树
查看>>
逆序链表
查看>>
epoll 使用详解
查看>>
stl 中 set容器用法
查看>>
有序数组求交集
查看>>
文字常量区与栈
查看>>
非阻塞connect 编写方法
查看>>
epoll 边沿触发
查看>>
String类 默认生成的函数
查看>>
Linux 软连接与硬链接
查看>>
视音频数据处理入门:H.264视频码流解析
查看>>
视音频数据处理入门:AAC音频码流解析
查看>>
视音频数据处理入门:UDP-RTP协议解析
查看>>
视音频数据处理入门:FLV封装格式解析
查看>>
最简单的基于FFMPEG的封装格式转换器(无编解码)
查看>>
base64 编码原理
查看>>