从媒体文件生成HLS流的简单实现方法

Kevin 杂记 1,185 次浏览 34条评论

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

HLS播放测试
HLS文件播放测试,移动浏览器大多可以直接播放,Chrome桌面版要安装Native HLS Playback插件。

下面操作环境为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。

Edit Nimble Routes

继续点击Add Vod Streaming Route。

Add Vod Streaming Route

填写请求目录和媒体文件路径。之后服务器会自动生成配置文件,后续即使在控制面板删除服务器也不影响使用。

Vod Streaming Via HLS

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也有很多功能,部分要订阅才能使用,服务器软件是免费的。

评论列表

  1. #1

    ivermectin dosing calculator https://ivermectin.mlsmalta.com/

  2. #2

    tamoxifen and blurred vision https://tamoxifen.mrdgeography.com/

  3. #3

    costco pharmacy dapoxetine https://dapoxetine.bee-rich.com/

  4. #4

    does vidalista help enlarged prostate https://vidalista40mg.mlsmalta.com/

  5. #5

    purchasing ivermectin over the internet https://ivermectin1st.com/

  6. #6

    aurogra to take drug sildenafil https://aurogra.buszcentrum.com/

  7. #7

    tadalafil price https://wisig.org/

  8. #8

    what does albuterol do https://amstyles.com/

  9. #9

    latest news on hydroxychloroquine trials https://hydroxychloroquinee.com/

  10. #10

    should i buy priligy online https://ddapoxetine.com/

  11. #11

    acyclovir package insert iv https://www.herpessymptomsinmen.org/productacyclovir/

  12. #12

    is happy family store legit https://medpills.bee-rich.com/

  13. #13

    is happy family store legit https://edmeds.buszcentrum.com/

  14. #14

    viagra did not work https://viaplz.com/

  15. #15

    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

  16. #16

    tadalafil once daily realptadalafil https://tadfil.online/

  17. #17

    cialis online sales https://cialis.stdstory.com/

  18. #18

    cialis online sales https://cialis.cleckleyfloors.com/

  19. #19

    cialis http://cialis.anafassia.com/

  20. #20

    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

  21. #21

    vidalista 20 centurion laboratories

  22. #22

    viagra prescription

  23. #23

    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

  24. #24

    farmacia aeropuerto palma http://essinreceta.com/ genuine viagra suppliers

  25. #25

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  26. #26

    viagra online usa viagra over the counter walmart
    viagra online usa

  27. #27

    what is vardenafil used for https://vegavardenafil.com/ purchase vardenafil online

  28. #28

    ed pills without a doctor prescription cheap ed pills
    ed pills online

  29. #29

    ed aids cheap ed pills in mexico
    buy ed pills

  30. #30

    July 4, 2012: genuine kamagra oral jelly cheap viagra no prescription kamagra

  31. #31

    tadalafil pills https://elitadalafill.com/ tadalafil tablets

  32. #32

    buy ed pills drugs prices
    buy ed pills

  33. #33

    where to buy alprostadil gel https://alprostadildrugs.com/ alprostadil side

  34. #34

    how to order sildenafil from canada https://eunicesildenafilcitrate.com/ usa over the counter sildenafil

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。