I need to remux a live stream from an RTSP container to framgented MP4.

Video stream is a h264 baseline one.

I can have a very good results with ffmpeg, however, I'm struggling with one key thing:

I would like to have a very quick first frame (ie. very short time-to-first-frame).

Now my video source encoder puts an IDR-frame into the stream at every 10 seconds. This one we can consider as a keyframe. I also modded the encoder to immediately put an IDR frame into the stream, once a client joins to it over rtsp.

I applied these flags to ffmpeg: +frag_keyframe+empty_moov+default_base_moof, and created a pipeline:

CAM -> RTSP(H264) -> FFMPEG -> fMP4(H264) -> VLC player

Due to above config, I will get frames written at every keyframe, and for somewhat reason the first keyframe is not taken into account, so whenever I start the process, VLC will be silent for 10seconds (then comes the next keyframe, and buffers are flushed), VLC will show a still picture, another 10s needs to be passed (then comes again the next keyframe), and after that VLC just plays fine with a 20s lag.

I can use frag_every_frame, which works just perfect, but it has a massive performance drawback.

I tried to use frag_custom, and flush the buffers (creating fragments) at 1Hz in the beginning for fast startup, then slow down the frequency to fragment at every 10s: but in this case, fMP4 player first starts correctly, but after the change of fragment timings, it stalls.

How can I change fragmentation on the fly in case a fragmented MP4 stream?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.