sergey-dryabzhinsky / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
1.02k stars 215 forks source link

For video streams, wait for a video keyframe before rotating the file. #336

Closed micolous closed 2 years ago

micolous commented 3 years ago

Fixes https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/issues/335

Video streams need a keyframe to start each file, so wait until the next video keyframe after record_interval before rotating the file.

Audio-only streams will always have brkframe = true, so will always be eligible to rotate.

Test: with record_interval 1m, sending a video stream (h264+aac) with a keyframe interval of 10 seconds causes the segments to not always be cut on the same second:

room1_2021-07-17_17_11_33.flv
room1_2021-07-17_17_12_33.flv
room1_2021-07-17_17_13_43.flv

Playing back all segments in sequence (or concatenating it into a single file) results in a continuous stream, with no missing frames or stuttering.