从媒体文件生成HLS流的简单实现方法
前些天折腾HLS文件模拟直播的笔记部分,先就HLS生成方法发一文,等解决多文件轮播问题后再补充剩余部分。从本地文件切片生成HLS流媒体网上有多种工具可用,有功能强大但配置复杂的FFmpeg,也有简单适合新手使用的Nimble。下面分别介绍两者基本用法,更多功能则需大家去翻看文档。

下面操作环境为CentOS 7 64Bit。
FFmpeg生成HLS
1. 先安装Nginx提供Web环境。若要支持RTMP,需要添加nginx-rtmp-module模块。
2. FFmpeg安装相对麻烦一些,默认软件仓库里没有。除编译安装外一般通过Nux Dextop源安装,Nux Dextop依赖EPEL源,所以需逐个安装。
# 安装EPEL yum install -y epel-release # 导入Nux Dextop GPG密钥 rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro # 安装Nux Dextop rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm # 开始安装。若要安装开发包,带上ffmpeg-devel yum install -y ffmpeg
3. 安装后建议关闭Nux Dextop源,因为平时很少用到,也避免可能与其它源冲突。
# 将文件里[nux-dextop]下的enabled参数改至0 vi /etc/yum.repos.d/nux-dextop.repo
4. 上传媒体文件到服务器,运行下面命令即可生成HLS流,之后访问m3u8文件就可以播放。
ffmpeg -re -i /usr/share/nginx/html/test.mp4 -codec:v libx264 -codec:a libfaac -map 0 -f hls -hls_list_size 6 -hls_wrap 10 -hls_time 10 /usr/share/nginx/html/test.m3u8
上面命令为简单示例,FFmpeg有许多参数。例如HLS流模式设置,更改视频分辨率,ts文件时长等。
Nimble生成HLS
Nimble是一个相对小众的软件,用起来非常简单,本身提供Web环境。使用需先到官网注册账号。
1. vi /etc/yum.repos.d/nimble.repo
创建文件以添加软件源。
[nimble] name= Nimble Streamer repository baseurl=http://nimblestreamer.com/centos/7/$basearch enabled=1 gpgcheck=1 gpgkey=http://nimblestreamer.com/gpg.key
2. 运行yum makecache
命令刷新缓存,之后yum -y install nimble
安装软件。
3. 输入注册的账号和密码,修改下面命令运行。
/usr/bin/nimble_regutil -u mail@example.com -p mypassword
4. service nimble start
启动服务,登录控制面板进入服务器设置页面,点击Edit Nimble Routes。
继续点击Add Vod Streaming Route。
填写请求目录和媒体文件路径。之后服务器会自动生成配置文件,后续即使在控制面板删除服务器也不影响使用。
5. 防火墙放行Nimble默认8081端口。
firewall-cmd --zone=public --add-port=8081/tcp --permanent firewall-cmd --reload
6. 之后通过下面格式链接访问播放列表,Nimble会自动切割ts文件,不用手动操作。
http://example.com:8081/vod/test.mp4/playlist.m3u8
Nimble也有很多功能,部分要订阅才能使用,服务器软件是免费的。
ivermectin dosing calculator https://ivermectin.mlsmalta.com/
tamoxifen and blurred vision https://tamoxifen.mrdgeography.com/
costco pharmacy dapoxetine https://dapoxetine.bee-rich.com/
does vidalista help enlarged prostate https://vidalista40mg.mlsmalta.com/
purchasing ivermectin over the internet https://ivermectin1st.com/
aurogra to take drug sildenafil https://aurogra.buszcentrum.com/
tadalafil price https://wisig.org/
what does albuterol do https://amstyles.com/
latest news on hydroxychloroquine trials https://hydroxychloroquinee.com/
should i buy priligy online https://ddapoxetine.com/
acyclovir package insert iv https://www.herpessymptomsinmen.org/productacyclovir/
is happy family store legit https://medpills.bee-rich.com/
is happy family store legit https://edmeds.buszcentrum.com/
viagra did not work https://viaplz.com/
Its such as you learn my mind! You appear
to grasp so much approximately this, such as you wrote
the e book in it or something. I believe that you simply could
do with a few percent to pressure the message house a bit, however
instead of that, that is excellent blog. A fantastic read.
I’ll definitely be back. http://antiibioticsland.com/Doxycycline.htm
tadalafil once daily realptadalafil https://tadfil.online/
cialis online sales https://cialis.stdstory.com/
cialis online sales https://cialis.cleckleyfloors.com/
cialis http://cialis.anafassia.com/
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.
I think that you could do with some pics to drive the message home a bit,
but other than that, this is fantastic blog. A fantastic read.
I will definitely be back. http://herreramedical.org/sildenafil
vidalista 20 centurion laboratories
viagra prescription
Hello to all, it’s truly a nice for me to pay a quick visit this website, it consists of
valuable Information. http://antiibioticsland.com/Amoxil.htm
farmacia aeropuerto palma http://essinreceta.com/ genuine viagra suppliers
buy hydroxychloroquine online https://hydroxychloroquinex.com/
viagra online usa viagra over the counter walmart
viagra online usa
what is vardenafil used for https://vegavardenafil.com/ purchase vardenafil online
ed pills without a doctor prescription cheap ed pills
ed pills online
ed aids cheap ed pills in mexico
buy ed pills
July 4, 2012: genuine kamagra oral jelly cheap viagra no prescription kamagra
tadalafil pills https://elitadalafill.com/ tadalafil tablets
buy ed pills drugs prices
buy ed pills
where to buy alprostadil gel https://alprostadildrugs.com/ alprostadil side
how to order sildenafil from canada https://eunicesildenafilcitrate.com/ usa over the counter sildenafil