Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTSP stream failing to record due to missing IDR or non-IDR NALU #3614

Closed
1 of 13 tasks
gkubes opened this issue Aug 5, 2024 · 3 comments
Closed
1 of 13 tasks

RTSP stream failing to record due to missing IDR or non-IDR NALU #3614

gkubes opened this issue Aug 5, 2024 · 3 comments
Labels
bug Something isn't working rtsp

Comments

@gkubes
Copy link

gkubes commented Aug 5, 2024

Which version are you using?

v1.8.4

Which operating system are you using?

  • Linux amd64 standard
  • Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (please describe)

Describe the issue

Unable to record RTSP stream to disk in mp4 format. Continually see errors indicating the video stream does not have an IDR or non-IDR NALU and then proceeds to immediately create and close a segment. As a result, the segments on disk are < 1sec, only show a black images with the the correct audio.

I am able to view the same camera RTSP stream using a WebRTC client.

Describe how to replicate the issue

  1. start the server
  2. proxy path with rtsp stream using h264 yuv420p video and pcm_alaw audio. I'm using Tapo C120 camera.
  3. enable record in fmp4 format.

Did you attach the server logs?

yes

mediamtx.log

Did you attach a network dump?

yes

capture-pcap.zip

@gkubes
Copy link
Author

gkubes commented Aug 6, 2024

Diving head first into the H.264 spec and analyzing my pcap file.

It appears that my camera is sending Fragmentation Units A (NALU #28) as opposed to the expected IDR (NALU Type #5) or non-IDR (NALU Type #1) as implemented by dts_extractor.go. These FU-A allows fragmenting a NAL unit into several RTP packets. I see the completion end marker of the FU-A followed by Supplemental Enhancement Information (SEI) before finally getting the expected non-IDR NALU Types.

@gkubes
Copy link
Author

gkubes commented Aug 7, 2024

I built out mediamtx from source and confirmed that dts_extrator.go is returning the above error in the case when the Access Unit contains a single SEI NALU.

The question becomes: should the SEI be incorporated into dts_extractor algorithm or should it be skipped and simply return the previous DTS (the same value can be handled given bluenviron/mediacommon#119)?

I found the following documentation from the h.264 spec and it seems like skipping the NALUwould be sufficient and have also confirmed that my video is then recorded.

If the NAL unit has no timing properties of its own (e.g., parameter set and SEI NAL units), the RTP timestamp is set to the RTP timestamp of the primary coded picture of the access unit in which the NAL unit is included, according to Section 7.4.1.2 of [1].

https://datatracker.ietf.org/doc/html/rfc6184#ref-1

@aler9 aler9 added bug Something isn't working rtsp labels Aug 25, 2024
aler9 added a commit to bluenviron/mediacommon that referenced this issue Aug 25, 2024
* h264: Fix DTS Extractor when single SEI NALU is received (bluenviron/mediamtx#3614)

* fix lint errors

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
@aler9
Copy link
Member

aler9 commented Aug 25, 2024

Fixed by bluenviron/mediacommon#142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rtsp
Projects
None yet
Development

No branches or pull requests

2 participants