Calculate .m4s segment file suffix in HTML5 video streaming when user seeks to another time

心已入冬 提交于 2019-12-04 00:46:26

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.

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.

Example:

Video File: gladiator.mp4

Segment Size: 5 seconds

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

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

And now we create the segment files using Mp4Box

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

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

Seekable Dash Streaming Example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!