下载m3u8到本地存储为mp4,mp4切片为m3u8 -j9九游会真人游戏第一品牌

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

使用的工具为,有各平台版本,本文在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 \ && rpm -uvh 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 ~]#