为什么M3U8文件在我手动更改M3U8文件时播放不好

发布于 2025-01-23 15:18:53 字数 1035 浏览 3 评论 0 原文

我使用 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 文件更改为此(复制This of this of of not02.ts,重复opt of 02.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

结果是此视频播放时间更改正如预期的那样

,但是out02不会重复,当它播放到第一个out2.t的末尾时,屏幕粘在of00的开始时,

为什么当我自己编辑此文件时它不正常? 或者我使用 ffmpeg 更新此 index.m3U8 文件?

I use ffmpeg to change mp4 to .ts

ffmpeg -y -i [fileName].mp4 -vcodec copy  -vbsf h264_mp4toannexb [outPutFileName].ts

And get the following index.m3u8 file

#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

And then i use hls.js play this file

It works fine

But now i want to change this index.m3u8 file to this (copy this out02.ts twice, to repeat 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

The result is this video play time change as expected

but out02 does not repeat, when it play to end of first out02.ts, screen stuck at the begin of out00

Why it does not work fine when i edit this file by myself ?
or i shoule use ffmpeg update this index.m3u8 file ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2025-01-30 15:18:53

在这里提出了一个类似的问题并回答:在这里: 从那里多次进入M3U8播放列表?

从那里,您只需要在M3U8文件中标记每个不连续性所需的信息即可。您可以通过添加#Ext-X-Discontinuition标志来做到这一点。

例如,您的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.org/doc/doc/doc/html/html/rfc8216

ext-x透度标签表示在
遵循它的媒体段,以及它之前的媒体部分。
[...]
如果发生更改
以下任何特征:
文件格式;
轨道的数字,类型和标识符;
时间戳序列。
如果发生更改
以下任何特征:
编码参数;
编码序列。

A similar question was asked and answered here: hls manually add second .ts file to playlist and here: How to include same segment into m3u8 playlist multiple times?

From there, you just need the piece of information that you need to mark each and every discontinuity in the m3u8 file. You do it by adding the #EXT-X-DISCONTINUITY flag.

For example, your m3u8 file should look like the following:

#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

This is because playing over and again the out-0002.ts resets the video presentation timestamps over and again, causing a discontinuity, as the ending of the out-0002.ts file has timestamp values 12.239122 seconds after the timestamps of the beginning of the same file.

Further information here: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文