Skip to content

Commit

Permalink
Merge pull request #1588 from thomaspurchas/master
Browse files Browse the repository at this point in the history
Handle malformed fmtp lines
  • Loading branch information
AlexxIT authored Feb 17, 2025
2 parents ad61662 + c39c9aa commit c9bdac2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/rtsp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
if codec.FmtpLine == "" {
codec.FmtpLine = findFmtpLine(codec.PayloadType, sd.MediaDescriptions)
}
case core.CodecH265:
if codec.FmtpLine != "" {
// All three parameters are needed for a valid fmtp line. If we're missing one
// then discard the entire line. The bitstream should contain the data in NAL units
//
// Some camera brands (notable Hikvision) don't include the vps property, rendering the entire
// line invalid, because the sps property references the non-existent vps proper. This invalid
// data will cause FFmpeg to crash with a `Could not write header (incorrect codec parameters ?): Invalid data found when processing input`
// error when attempting to repackage the HEVC stream into outgoing RTSP stream. Removing the
// fmtp line forces FFmpeg to rely on the bitstream directly, fixing this issue.
valid := strings.Contains(codec.FmtpLine, "sprop-vps=")
valid = valid && strings.Contains(codec.FmtpLine, "sprop-sps=")
valid = valid && strings.Contains(codec.FmtpLine, "sprop-pps=")
if !valid {
codec.FmtpLine = ""
}
}
case core.CodecOpus:
// fix OPUS for some cameras https://datatracker.ietf.org/doc/html/rfc7587
codec.ClockRate = 48000
Expand Down

0 comments on commit c9bdac2

Please # to comment.