ffmpeg - 为什么当我手动更改 m3u8 文件时 m3u8 文件播放不好

标签 ffmpeg m3u8 hls.js

我用 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/

相关文章:

nginx - Videojs - 流未运行时隐藏错误

node.js - Hls.js 'Access-Control-Allow-Origin' 错误

javascript - 用vuejs项目实现hls.js库

c++ - FFMPEG:为什么当我调用 av_codec_next() 时我的所有编解码器都没有显示

ios - 使用 AVPlayer 播放直播

android - HLS 协议(protocol),ParserException : Failed to parse the playlist, 无法识别任何标签

javascript - video.js 的 m3u8 源错误 : "No compatible source and playback technology were found."

ffmpeg - 为什么我的 ffmpeg 库这么大?

ffmpeg - 使用 FFMPEG,创建与视频比例成比例的缩略图

android - WhatsApp 视频作为 Gif 以编程方式在 Android 上共享