Skip to content

Commit

Permalink
优化 rtsp
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 25, 2023
1 parent 247d8c9 commit 4716618
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 // 默认支持来自系统控制中心的控制
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/KSPlayer/MEPlayer/AVFFmpegExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4716618

Please sign in to comment.