shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.
https://docs.haishinkit.com/swift/latest
BSD 3-Clause "New" or "Revised" License
2.78k stars 618 forks source link

SRT corrupt stream #1601

Open mkrn opened 1 month ago

mkrn commented 1 month ago

Describe the bug

I'm transporting SRT to a server nearby ?latency=1500&peerlatency=1500

reading on server with ffmpeg -i "srt://IP?streamid=STREAMID&latency=1500" -c copy -t 60 raw.ts

There are a lot of corrupt packets issues in ffmpeg:

[mpegts @ 0x5bdfc0591080] Packet corrupt (stream = 0, dts = 4235532).
[in#0/mpegts @ 0x5bdfc0590dc0] corrupt input packet in stream 0
[mpegts @ 0x5bdfc0591080] PES packet size mismatchits/s speed= 1.5x

Performance metrics:

Performance Data:
- Total Packets Sent: 13398 
- Total Send Packet Loss: 1 
- Total Retransmitted Packets: 1
- Total Received ACKs: 3953
- Total Received NAKs: 378
- Packets In Flight: 87
- Total Bytes Sent: 13457548 
- Sending Bitrate (Mbps): 1.6095544032307871
- Total Dropped Sent Packets: 2882  
- Round Trip Time (ms): 327.179
- Congestion Window: 8192
- Packets in Send Buffer: 81
- Bytes in Send Buffer: 81363
- Packet Congestion Window: 8192
- Bytes Available in Send Buffer: 12166500
- pktReorderTolerance: 0
- pktSndFilterExtra: 0

round trip varied from 180 - 1000 ms it's on 5G but inside walls

resulting video: https://videos.eventlive.site/streams/OVRSGPWH_raw.ts

To Reproduce

Start SRT stream on less than perfect internet Monitor with ffmpeg See corrupt packets, unable to recover

Encoder Settings:

720p 

       stream.videoSettings.profileLevel = kVTProfileLevel_HEVC_Main_AutoLevel as String
        stream.videoSettings.bitRate = 1300 * 1000
         stream.videoSettings.allowFrameReordering = nil
        stream.videoSettings.bitRateMode = .average
        stream.videoSettings.maxKeyFrameIntervalDuration = 2
        stream.videoSettings.isHardwareEncoderEnabled = true

Expected behavior

Smooth, quick to recover, no corrupt packets

Version

1.9.5

Smartphone info.

iPhone 13 Pro iOS 18

Additional context

No response

Screenshots

No response

Relevant log output

No response

shogo4405 commented 1 month ago

The network part is a wrapper for Haivision/srt, and it seems that there is nothing HaishinKit can control.

In environments where packet loss occurs, increasing the latency value seems to help compensate for it. There are documents that recommend setting it to 3–4 times the RTT.

Could increasing the latency like this, SRTConnection.open(URL(string: "srt://ip.address?latency=4000")!), help resolve the issue?

mkrn commented 1 month ago

Thank you! I'm not sure why this happened, but moved on to use HEVC in RTMP for my application it may be better fit.