Skip to content

Commit c9bdac2

Browse files
authored
Merge pull request #1588 from thomaspurchas/master
Handle malformed fmtp lines
2 parents ad61662 + c39c9aa commit c9bdac2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/rtsp/helpers.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ func UnmarshalSDP(rawSDP []byte) ([]*core.Media, error) {
7575
if codec.FmtpLine == "" {
7676
codec.FmtpLine = findFmtpLine(codec.PayloadType, sd.MediaDescriptions)
7777
}
78+
case core.CodecH265:
79+
if codec.FmtpLine != "" {
80+
// All three parameters are needed for a valid fmtp line. If we're missing one
81+
// then discard the entire line. The bitstream should contain the data in NAL units
82+
//
83+
// Some camera brands (notable Hikvision) don't include the vps property, rendering the entire
84+
// line invalid, because the sps property references the non-existent vps proper. This invalid
85+
// data will cause FFmpeg to crash with a `Could not write header (incorrect codec parameters ?): Invalid data found when processing input`
86+
// error when attempting to repackage the HEVC stream into outgoing RTSP stream. Removing the
87+
// fmtp line forces FFmpeg to rely on the bitstream directly, fixing this issue.
88+
valid := strings.Contains(codec.FmtpLine, "sprop-vps=")
89+
valid = valid && strings.Contains(codec.FmtpLine, "sprop-sps=")
90+
valid = valid && strings.Contains(codec.FmtpLine, "sprop-pps=")
91+
if !valid {
92+
codec.FmtpLine = ""
93+
}
94+
}
7895
case core.CodecOpus:
7996
// fix OPUS for some cameras https://datatracker.ietf.org/doc/html/rfc7587
8097
codec.ClockRate = 48000

0 commit comments

Comments
 (0)