mediamtx icon indicating copy to clipboard operation
mediamtx copied to clipboard

Cache H264 GOPs in order to allow readers to decode frames immediately

Open aler9 opened this issue 3 years ago • 7 comments

Describe the feature

Discussed here #1132

NOTE: this feature is already present in HLS. It is missing in WebRTC, SRT, RTSP, RTMP.

aler9 avatar Oct 28 '22 17:10 aler9

This would be a very desired feature for the video platform we are currently building. Any outlook on when this could be build in? Thanks !

sourcez avatar Jun 14 '23 09:06 sourcez

Can you maybe give some pointers as to what you think is necessary to implement this (e.g. which files to edit)? Maybe I can give it a go

jordybsecurite avatar Jul 11 '23 14:07 jordybsecurite

Hello, in my opinion to implement this you can hack formatprocessor.H264, which is an object that is initialized once for every H264 track of every stream:

https://github.com/bluenviron/mediamtx/blob/main/internal/formatprocessor/h264.go

In this structure you have to save all NALUs in a buffer until a key frame is received; when a key frame is received, this buffer must be emptied, and filled with new NALUs starting from the key frame.

When a new RTSP, RTMP of WebRTC client connects (not HLS, since key frame caching is already present in HLS), you have to send to this client all NALUs that are present in the buffer.

aler9 avatar Jul 11 '23 14:07 aler9

want this feature to! I'm using video doorbell with this project, when doorbell event triggered, video showed up in about 3-4s. a gop cache will make the stream open in realtime.

thanks everyone in advance!!

0x5e avatar Jul 18 '23 18:07 0x5e

I have a live stream, where I have multiple webcams in one single location (a zoo). I switch between them every 20 seconds. This feature would help make the switch quick and smooth.

ethaniel avatar Dec 17 '23 06:12 ethaniel