下载m3u8到本地存储为mp4,mp4切片为m3u8

标签:         

本文介绍m3u8资源保存到本地的方法

使用的工具为ffmpeg,有各平台版本,本文在CentOS上安装

1. centos安装ffmpeg

1.安装Nux Dextop Yum 源

由于CentOS没有官方FFmpeg rpm软件包。但是,我们可以使用第三方YUM源(Nux Dextop)完成此工作。

yum install epel-release -y \ && rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro \ && rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

2.安装FFmpeg 和 FFmpeg开发包

yum install ffmpeg ffmpeg-devel -y

测试是否安装成功

ffmpeg

如上若失败,用如下第二个方法:

yum install epel-release -y
yum update -y
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
yum install ffmpeg ffmpeg-devel -y

1.1 ubuntu安装

sudo add-apt-repository ppa:djcj/hybrid
sudo apt update
sudo apt install ffmpeg

2.下载m3u8为mp4文件

nohup ffmpeg -i https://up.imgupio.com/demo/birds.m3u8 birds.mp4 > birds.log &

将资源'https://up.imgupio.com/demo/birds.m3u8'下载到本目录保存为birds.mp4,并输出日志到birds.log

ffmpeg下载m3u8为mp4

mp4转m3u8

ffmpeg -i input.mp4 -c:v libx264 -c:a copy -f hls -threads 8 -hls_time 5 -hls_list_size 0 index.m3u8

参数:

hls_time seconds Set the segment length in seconds. Default value is 2.(设置每片的长度,默认值为2。单位为秒)

hls_list_size size Set the maximum number of playlist entries. If set to 0 the list file will contain all the segments. Default value is 5.(设置播放列表保存的最多条目,设置为0会保存有所片信息,默认值为5)

hls_wrap wrap Set the number after which the segment filename number (the number specified in each segment file) wraps. If set to 0 the number will be never wrapped. Default value is 0. This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk towrap.(设置多少片之后开始覆盖,如果设置为0则不会覆盖,默认值为0.这个选项能够避免在磁盘上存储过多的片,而且能够限制写入磁盘的最多的片的数量)

start_number number Start the playlist sequence number from number. Default value is 0.(设置播放列表中sequence number的值为number,默认值为0)

Note that the playlist sequence number must be unique for each segment and it is not to be confused with the segment filename sequence number which can be cyclic, for example if the ‘wrap’ option is specified.(提示:播放列表的sequence number 对每个segment来说都必须是唯一的,而且它不能和片的文件名混淆,因为在,如果指定了“wrap”选项文件名会出现重复使用。)

其他:vatfs (影视全搜索)代码分享


发表评论 登录

目前评论:1

  • avatar erbiLity 回复 2020-03-14 22:16:59

    两步都是错的 [root@VM_69_215_centos ~]# yum install epel-release -y \ && rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro \ && rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Loading mirror speeds from cached hostfile epel | 5.3 kB 00:00 extras | 2.9 kB 00:00 os | 3.6 kB 00:00 updates | 2.9 kB 00:00 Package epel-release-7-12.noarch already installed and latest version No package available. Nothing to do error: : import read failed(2). [root@VM_69_215_centos ~]# yum install ffmpeg ffmpeg-devel -y Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Loading mirror speeds from cached hostfile No package ffmpeg available. No package ffmpeg-devel available. Error: Nothing to do [root@VM_69_215_centos ~]#