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

Handle malformed SDP from Hikvision cameras #1588

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

thomaspurchas
Copy link
Contributor

Adds function to detect and remove malformed fmtp lines emitted by some camera when streaming H265. Malformed fmtp line can cause issues downstream, notably if FFmpeg is used to de-mux and remux the H265 stream without transcoding. Removal of malformed fmtp forces downstream process to extract the VPS, SPS and PPS value from bitstream NALs.

Example of an SDP with malformed fmtp:

v=0
o=- 1739057148693902 1739057148693902 IN IP4 192.168.254.19
s=Media Presentation
e=NONE
b=AS:5050
t=0 0
a=control:rtsp://192.168.254.19:554/streaming/channels/101/
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:5000
a=recvonly
a=x-dimensions:1920,1080
a=control:rtsp://192.168.254.19:554/streaming/channels/101/trackID=1
a=rtpmap:96 H265/90000
a=fmtp:96 sprop-sps=QgECAWAAAAMAgAAAAwAAAwB4AACgA8CAEOf42td2pu7muVVgLcBAQEEAAAMD6AAAH0ByHe5RAHpgAIm8APTAARN4QB6YACJvAD0wAETeIA==; sprop-pps=RAHBcrCcFApiQAAA
a=Media_header:MEDIAINFO=494D4B48010200000400050000000000000000000000000000000000000000000000000000000000;
a=appversion:1.0

Here there fmtp has a sprop-sps, sprop-pps but is missing sprop-vps. When attempting to decode with FFmpeg this non-fatal error will be emitted by the demuxer:

[hevc @ 0x154e06810] VPS 0 does not exist

And this fatal error will be emitted by the muxer when trying to restream using RTSP

[out#0/rtsp @ 0x600001e5c000] Could not write header (incorrect codec parameters ?): Invalid data found when processing input

Malformed fmtp lines is likely the cause of these issues: #1545, blakeblackshear/frigate#5585

@AlexxIT AlexxIT merged commit c9bdac2 into AlexxIT:master Feb 17, 2025
@AlexxIT
Copy link
Owner

AlexxIT commented Feb 17, 2025

Thanks!

AlexxIT added a commit that referenced this pull request Feb 17, 2025
@AlexxIT AlexxIT changed the title Handle malformed fmtp lines Handle malformed SDP from Hikvision cameras Feb 18, 2025
@AlexxIT AlexxIT added this to the v1.9.9 milestone Feb 18, 2025
@AlexxIT
Copy link
Owner

AlexxIT commented Mar 10, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants