我有一个 m3u8 文件和几个 TS 文件。
以下是 m3u8 文件的实际输出。
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0000.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0003.ts
#EXT-X-ENDLIST
我把这个m3u8改写成如下格式,保存,播放。然后视频的播放顺序和我换m3u8的顺序一模一样。
但是,视频播放无法按预期工作并卡住。
#extm3u.
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0003.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0000.ts
#EXT-X-ENDLIST
如果我想像这样更改 TS 文件的顺序,如何编辑 m3u8 文件?或者我可以使用 ffmpeg 命令更改 ts 文件的顺序,然后重新创建 m3u8 文件吗?
最佳答案
恐怕您不允许手动编辑播放列表(或使用 ffmpeg
命令重新生成它)。由于the restriction of HLS protocol (RFC8216) ,当您设置任一值 .ts
时,不得删除中间的媒体片段(在您的情况下为 event
文件)或 vod
至-hls_playlist_type
您的 ffmpeg
中的选项命令,即使没有 -hls_playlist_type
,它仍然仅限于更改播放列表(不包括自由删除任何媒体片段)。
引自 General Server Responsibilities in RFC8216
The server MUST NOT change the Media Playlist file, except to:
- Append lines to it (Section 6.2.1).
- Remove Media Segment URIs from the Playlist in the order that they appear, along with any tags that apply only to those segments (Section 6.2.2).
- Increment the value of the EXT-X-MEDIA-SEQUENCE or EXT-X- DISCONTINUITY-SEQUENCE tags (Section 6.2.2).
- Add an EXT-X-ENDLIST tag to the Playlist (Section 6.2.1).
A Media Playlist has further constraints on its updates if it contains an EXT-X-PLAYLIST-TYPE tag. An EXT-X-PLAYLIST-TYPE tag with a value of VOD indicates that the Playlist file MUST NOT change. An EXT-X-PLAYLIST-TYPE tag with a value of EVENT indicates that the server MUST NOT change or delete any part of the Playlist file; it MAY append lines to it.
请注意
EXT-X-PLAYLIST-TYPE
在与 -hls_playlist_type
相关的播放列表中在 ffmpeg
关于linux - 重新排列m3u8中ts文件的顺序会导致播放时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70870529/