Search code examples
videoffmpegffprobemedia-source

Adaptive bit rate streaming of mp4 of different gop size using media source api


I want the adaptive bitrate streaming of the mp4 video of different gop keyframe size.

I know there are couple of options for multi bitrate streaming i.e hls, dash etc

But I already uploaded the videos on the server each video have the 360p, 480p and 720p mp4 file and each video are having different keyframe intervals.

So the real challenge is to make the own multi bitrate mp4 media player using the media source api

I have brain storming all aspect.

We can only cut the h264 at keyframe

So my real challenge is to know the video each keyframe, the keyframe chunk duration, the offset duration and the offset byte position in the mp4 file.

So my question is how I can get these following using ffmpeg, ffprobe or any other software.

1- Keyframe chunk duration

2- Offset video duration

3- Offset byte position in video.

The following ffprobe command give the detailed info of the each keyframe, maybe this will help

ffprobe -i "1080p.mp4" -select_streams v -skip_frame nokey -show_frames

Thanks!


Solution

  • Run this command,

    ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_dts_time,pkt_pos -of csv "video.mp4"
    

    Then

    pkt_dts_time provides "Offset video duration" for the GOP.

    pkt_pos provides "Offset byte position" for the start of the GOP.

    The difference between the pkt_dts_time of a keyframe and the pkt_dts_time of the next keyframe is the "Keyframe chunk duration".

    Note that you can only change keyframe position by re-encoding the video. And if you're re-encoding, the keyframe positions of the input video don't matter. See -force_key_frames under https://ffmpeg.org/ffmpeg.html#Advanced-Video-options on how to force KFs at fixed psotions.