bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
12.25k stars 1.53k forks source link

can't read with RTMP / LHLS a stream encoded with nvenc: DTS is greater than PTS #989

Closed JIEgOKOJI closed 2 years ago

JIEgOKOJI commented 2 years ago

Which version are you using?

latest

Which operating system are you using?

Describe the issue

When using lhls and starting stream from OBS with nvenc encoder. The Muxer crashes with logs " destroyed (muxer error: DTS is greater than PTS)"

Describe how to replicate the issue

  1. start the server
  2. publish with Obs and nvenc with b-frames
  3. read with logs

Did you attach the server logs?

2022/06/13 17:21:30 INF [HLS] [muxer lhls/6] is converting into HLS 2022/06/13 17:21:32 INF [HLS] [muxer lhls/6] destroyed (muxer error: DTS is greater than PTS)

no

Did you attach a network dump?

no

aler9 commented 2 years ago

Hello, this is caused by the fact that nvenc doesn't include the max_num_reorder_frames field into the H264 SPS, and therefore the server can't compute the initial offset between PTS and DTS (which is max_num_reorder_frames * 1 / fps). Without this initial offset, it happens that DTS > PTS.

FFmpeg uses an undocumented algorithm that allows to derive max_num_reorder_frames when it is not present, that may be implemented in the server too:

https://github.com/FFmpeg/FFmpeg/blob/c6364b711bad1fe2fbd90e5b2798f87080ddf5ea/libavcodec/h264_ps.c#L587

i need to investigate.

aler9 commented 2 years ago

fixed in v0.19.2.

github-actions[bot] commented 1 year ago

This issue is being locked automatically because it has been closed for more than 6 months. Please open a new issue in case you encounter a similar problem.