我用 ffmpeg
将 mp4 更改为 .ts
ffmpeg -y -i [fileName].mp4 -vcodec copy -vbsf h264_mp4toannexb [outPutFileName].ts
并获得以下 index.m3u8
文件#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:22
#EXTINF:21.804344,
out-0000.ts
#EXTINF:10.847822,
out-0001.ts
#EXTINF:12.239122,
out-0002.ts
#EXT-X-ENDLIST
然后我使用 hls.js
播放这个文件它工作正常
但现在我想改变这个
index.m3u8
文件到这个(复制这个 out02.ts 两次,重复 out02.ts)#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:22
#EXTINF:21.804344,
out-0000.ts
#EXTINF:10.847822,
out-0001.ts
#EXTINF:12.239122,
out-0002.ts
#EXTINF:12.239122,
out-0002.ts
#EXTINF:12.239122,
out-0002.ts
#EXT-X-ENDLIST
结果是这个视频play time
按预期改变但是out02不重复,当播放到第一个out02.ts的结尾时,屏幕卡在out00的开头
为什么我自己编辑这个文件时它不能正常工作?
或者我应该使用
ffmpeg
更新这个 index.m3u8
文件 ?
最佳答案
在这里提出并回答了一个类似的问题:hls manually add second .ts file to playlist在这里:How to include same segment into m3u8 playlist multiple times?
从那里,您只需要标记 m3u8 文件中的每个不连续性所需的信息。您可以通过添加#EXT-X-DISCONTINUITY 标志来实现。
例如,您的 m3u8 文件应如下所示:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:22
#EXTINF:21.804344,
out-0000.ts
#EXTINF:10.847822,
out-0001.ts
#EXTINF:12.239122,
out-0002.ts
#EXT-X-DISCONTINUITY
#EXTINF:12.239122,
out-0002.ts
#EXT-X-DISCONTINUITY
#EXTINF:12.239122,
out-0002.ts
#EXT-X-ENDLIST
这是因为一遍又一遍地播放 out-0002.ts 会一遍又一遍地重置视频演示时间戳,从而导致不连续性,因为 out-0002.ts 文件的结尾的时间戳值比视频开头的时间戳晚 12.239122 秒同一个文件。更多信息:https://datatracker.ietf.org/doc/html/rfc8216
The EXT-X-DISCONTINUITY tag indicates a discontinuity between the Media Segment that follows it and the one that preceded it. [...] The EXT-X-DISCONTINUITY tag MUST be present if there is a change in any of the following characteristics: file format; number, type, and identifiers of tracks; timestamp sequence. The EXT-X-DISCONTINUITY tag SHOULD be present if there is a change in any of the following characteristics: encoding parameters; encoding sequence.
关于ffmpeg - 为什么当我手动更改 m3u8 文件时 m3u8 文件播放不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71994406/