IT618

 找回密码
 立即注册
查看: 1757|回复: 0

用ffmpeg 把mp4文件转为ts文件并生成m3u8列表

[复制链接]
<

267

主题

49

回帖

3087万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
30870331
发表于 2017-10-24 19:17:25 | 显示全部楼层 |阅读模式

在使用hls技术播放视频流时,首先要把视频转换为ts片和一个m3u8播放列表,使用ffmpeg进行该转换时(低版本ffmpeg不支持直接转,只能现在转换成ts,再用m3u8-segmenter切片,笔者使用的是ffmpeg version-2.1.2),通常使用如下命令:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict -2 -f hls output.m3u8

但是在此状态下,默认的每片长度为2秒,m3u8文件中默认只保存最新的5条片的信息,导致最后播放的时候只能播最后的一小部分。

实际上还有一些其他参数可以控制这些内容:

以下为ffmpeg官网原文:
This muxer supports the following options:

‘hls_time seconds’
Set the segment length in seconds. Default value is 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.
‘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.
‘start_number number’
Start the playlist sequence number from number. Default value is 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.

翻译如下:
-hls_time n: 设置每片的长度,默认值为2。单位为秒
-hls_list_size n:设置播放列表保存的最多条目,设置为0会保存有所片信息,默认值为5
-hls_wrap n:设置多少片之后开始覆盖,如果设置为0则不会覆盖,默认值为0.这个选项能够避免在磁盘上存储过多的片,而且能够限制写入磁盘的最多的片的数量
-hls_start_number n:设置播放列表中sequence number的值为number,默认值为0
注意:播放列表的sequence number 对每个segment来说都必须是唯一的,而且它不能和片的文件名(当使用wrap选项时,文件名有可能会重复使用)混淆


加上了这些参数,小伙伴们就可以愉快地控制生成的m3u8文件啦

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|插件教程|常见问题|扫码访问手机版|IT618

GMT+8, 2024-4-29 22:27

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表