hls: refresh H264/H265 codec parameters in OnData callback by WinterPhoenix · Pull Request #5745 · bluenviron/mediamtx (original) (raw)
With hlsAlwaysRemux=yes the muxer is created at PathReady time,
before any unit has flowed through the reader. setupVideoTrack
captures format.SafeParams() once, so codec.SPS stays nil for
sources that deliver SPS only in the elementary stream (MPEG-TS
over SRT/UDP, HLS pull, WebRTC, RTSP without sprop-parameter-sets).
gohlslib's populateMultivariantPlaylist then fails with
"not enough bits" on h264.SPS.Unmarshal and returns 500 with no
body on every /
RTMP publishers don't hit this: format.H264 is built with SPS already set from AVCDecoderConfigurationRecord in internal/protocols/rtmp/to_stream.go.
Refresh from format.SafeParams() inside the OnData callback while SPS is nil. subStreamFormat.writeUnitInner runs the format updater on the payload before invoking OnData, so SafeParams() returns current values. The nil check short-circuits after the first frame.