diff --git a/Demo/SwiftUI/Shared/MovieModel.swift b/Demo/SwiftUI/Shared/MovieModel.swift index 061cb89e6..ca866dd5e 100644 --- a/Demo/SwiftUI/Shared/MovieModel.swift +++ b/Demo/SwiftUI/Shared/MovieModel.swift @@ -355,7 +355,13 @@ extension KSVideoPlayerView { if url.scheme == "rtmp" || url.scheme == "rtsp" { options.formatContextOptions["listen_timeout"] = -1 options.formatContextOptions["fflags"] = ["nobuffer"] - options.preferredForwardBufferDuration = 2 + // tcp or udp + options.formatContextOptions["rtsp_transport"] = "tcp" + options.probesize = 4096 + options.maxAnalyzeDuration = 2_000_000 + options.codecLowDelay = true + options.preferredForwardBufferDuration = 1 + options.maxBufferDuration = 3600 options.hardwareDecode = false } else { options.formatContextOptions["listen_timeout"] = 3 diff --git a/Sources/KSPlayer/AVPlayer/KSOptions.swift b/Sources/KSPlayer/AVPlayer/KSOptions.swift index 85ccdd38b..c5a3d8e4b 100644 --- a/Sources/KSPlayer/AVPlayer/KSOptions.swift +++ b/Sources/KSPlayer/AVPlayer/KSOptions.swift @@ -43,6 +43,7 @@ open class KSOptions { public var probesize: Int64? public var maxAnalyzeDuration: Int64? public var lowres = UInt8(0) + public var codecLowDelay = false public var startPlayTime: TimeInterval = 0 public var startPlayRate: Float = 1.0 public var registerRemoteControll: Bool = true // 默认支持来自系统控制中心的控制 @@ -111,7 +112,6 @@ open class KSOptions { // 参数的配置可以参考protocols.texi 和 http.c formatContextOptions["auto_convert"] = 0 formatContextOptions["fps_probe_size"] = 3 -// formatContextOptions["probesize"] = 40 * 1024 // formatContextOptions["max_analyze_duration"] = 300 * 1000 formatContextOptions["reconnect"] = 1 diff --git a/Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift b/Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift index 1b0c8222f..f2856e1f1 100644 --- a/Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift +++ b/Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift @@ -93,6 +93,9 @@ extension AVCodecParameters { } codecContext.pointee.codec_id = codec.pointee.id codecContext.pointee.flags2 |= AV_CODEC_FLAG2_FAST + if options.codecLowDelay { + codecContext.pointee.flags |= AV_CODEC_FLAG_LOW_DELAY + } var lowres = options.lowres if lowres > codec.pointee.max_lowres { lowres = codec.pointee.max_lowres