当用户搜寻其他时间时,计算HTML5视频流中的.m4s段文件后缀 [英] Calculate .m4s segment file suffix in HTML5 video streaming when user seeks to another time

查看:304
本文介绍了当用户搜寻其他时间时,计算HTML5视频流中的.m4s段文件后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Mp4Box为长MP4视频创建了固定长度的片段. Mp4Box创建一个元信息文件mv_init.mp4和诸如mv_1.m4smv_2.m4s之类的片段,…我使用HTML5 Media Source Extensions传输视频,并且传输正常.

I have created fixed length segments for a long MP4 video using Mp4Box. Mp4Box creates a meta info file mv_init.mp4 and segments like mv_1.m4s, mv_2.m4s, … I stream the video using HTML5 Media Source Extensions and the streaming is working properly.

问题是我无法利用我的HTML5播放器的时间搜索功能.当用户使用搜索栏搜索到另一个时间点时,我需要为该currentTime获取正确的段文件(mv_{number}.m4s).

The problem is that I am unable to utilize time seeking feature of my HTML5 player. When a user uses the seekbar to seek to another time point, I need to fetch the correct segment file (mv_{number}.m4s) for that currentTime.

例如:

  • 视频时长:2小时
  • 段大小:10秒
  • 用户寻求时间:25分钟

25分钟= 25×60秒= 1500秒.由于每个段为10秒,因此我需要段号1500/10 =150.所需的段文件为mv_150.m4s.

25 minutes = 25 × 60 seconds = 1500 seconds. As each segment is of 10 seconds, I need segment number 1500 / 10 = 150. The needed segment file is mv_150.m4s.

计算看似正确,但是HTML5播放器mv_150.m4s之后下载了更多文件,然后继续进行流式传输.

The calculation apparently seems correct, but the HTML5 player then downloads many more files after mv_150.m4s before it continues with the streaming.

如何正确计算段文件号,以便在查找后,流传输平稳运行,而无需下载任何额外的文件?

How to correctly calculate segment file number, so that after seeking, the streaming runs smoothly, without downloading any extra files?

要创建MP4视频的片段,我使用了以下命令:

To create the segments of the MP4 video, I used the following command:

MP4Box -dash 10000 -out video.mpd -dash-profile live -segment-name mv_ -rap video.mp4

推荐答案

我对此事进行了研究,找到了真正的原因.加载段的计算是正确的.问题在于视频文件中的关键帧间隔.关键帧是视频中的帧,随后可以从该帧开始加载视频并从该点开始运行.因此,就我而言,我需要在每个片段的开头插入关键帧.因此,当我们在不同时间位置浏览视频时,下一个加载的片段在其开始处包含关键帧.

I have researched on the matter and found the real cause. The caluclation for loading the segments was correct. The issue was with the key frame interval in video file. A keyframe is a frame in video from which the video can subsequently load and run from that point. So in my case I need to insert keyframe at the start of each segment. Therefore when we seek through the video in different time positions the next segment that is loaded contains a keyframe at the start of it.

可以使用FFMPEG设置视频文件中的关键帧.因此,例如,如果我们的视频具有5秒的片段,则必须使用ffmpeg以5秒的间隔创建关键帧.设置关键帧时的另一个重要点是查看视频的帧速率.视频必须具有固定的帧频,以便我们可以精确地计算关键帧的位置.

The keyframes in video file can be setup using FFMPEG. So for example if we have a video having segments of 5 seconds then we must create keyframe at 5 seconds interval using ffmpeg. Another important point while setting up keyframes is to look into FRAME RATE of video. The video must have a fixed frame rate so we can precisely calculate the position of keyframe.

示例:

Video File: gladiator.mp4

Segment Size: 5 seconds

不,我们使用FFMPEG设置帧速率和关键帧间隔

No we set FRAME RATE and KEY FRAME INTERVAL USING FFMPEG

ffmpeg -i gladiator.mp4 -x264-params keyint = 120:min-keyint = 120:no-scenecut = 1 -r 24 gladiator-output.mp4

ffmpeg -i gladiator.mp4 -x264-params keyint=120:min-keyint=120:no-scenecut=1 -r 24 gladiator-output.mp4

keyint=120 i.e; 24 fps * 5 seconds = 120

现在我们使用Mp4Box创建细分文件

And now we create the segment files using Mp4Box

MP4Box -dash 5000 -frag 5000 -out gladiator.mpd -dash-profile 按需-段名称mv_ gladiator-output.mp4

MP4Box -dash 5000 -frag 5000 -out gladiator.mpd -dash-profile on-demand -segment-name mv_ gladiator-output.mp4

因此它将创建诸如mv_1,mv_2,..之类的片段,并在每个片段文件的开始处具有关键帧.

So it will create segments like mv_1,mv_2, .. and so on having keyframes at the start of each segment file.

可搜索的冲刺流示例

这篇关于当用户搜寻其他时间时,计算HTML5视频流中的.m4s段文件后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆