From 433ff6cc0e96d0f781db6c7450e12fd6d41d80dd Mon Sep 17 00:00:00 2001 From: kingslay Date: Thu, 28 Dec 2023 22:12:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/KSPlayer/AVPlayer/KSOptions.swift | 10 ++++++---- Sources/KSPlayer/MEPlayer/Resample.swift | 1 + Sources/KSPlayer/MEPlayer/ThumbnailController.swift | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/KSPlayer/AVPlayer/KSOptions.swift b/Sources/KSPlayer/AVPlayer/KSOptions.swift index a7a059127..d8d5035e2 100644 --- a/Sources/KSPlayer/AVPlayer/KSOptions.swift +++ b/Sources/KSPlayer/AVPlayer/KSOptions.swift @@ -113,16 +113,18 @@ open class KSOptions { // 参数的配置可以参考protocols.texi 和 http.c // 这个一定要,不然有的流就会判断不准FieldOrder formatContextOptions["scan_all_pmts"] = 1 - // 下面是用来处理秒开的参数,有需要的自己打开 + // ts直播流需要加这个才能一直直播下去,不然播放一小段就会结束了。 + formatContextOptions["reconnect"] = 1 + formatContextOptions["reconnect_streamed"] = 1 + // 这个是用来开启http的链接复用(keep-alive)。vlc默认是打开的,所以这边也默认打开。 + formatContextOptions["multiple_requests"] = 1 + // 下面是用来处理秒开的参数,有需要的自己打开。默认不开,不然在播放某些特殊的ts直播流会频繁卡顿。 // formatContextOptions["auto_convert"] = 0 // formatContextOptions["fps_probe_size"] = 3 // formatContextOptions["rw_timeout"] = 10_000_000 // formatContextOptions["max_analyze_duration"] = 300 * 1000 // 默认情况下允许所有协议,只有嵌套协议才需要指定这个协议子集,例如m3u8里面有http。 // formatContextOptions["protocol_whitelist"] = "file,http,https,tcp,tls,crypto,async,cache,data,httpproxy" - formatContextOptions["reconnect"] = 1 - formatContextOptions["reconnect_streamed"] = 1 - formatContextOptions["multiple_requests"] = 1 // 开启这个,纯ipv6地址会无法播放。并且有些视频结束了,但还会一直尝试重连。所以这个值默认不设置 // formatContextOptions["reconnect_at_eof"] = 1 // 开启这个,会导致tcp Failed to resolve hostname 还会一直重试 diff --git a/Sources/KSPlayer/MEPlayer/Resample.swift b/Sources/KSPlayer/MEPlayer/Resample.swift index f60c686c9..6f7862d7a 100644 --- a/Sources/KSPlayer/MEPlayer/Resample.swift +++ b/Sources/KSPlayer/MEPlayer/Resample.swift @@ -131,6 +131,7 @@ class VideoSwresample: FrameChange { let dstFormat = dstFormat ?? format.bestPixelFormat pixelFormatType = dstFormat.osType()! // imgConvertCtx = sws_getContext(width, height, self.format, width, height, dstFormat, SWS_FAST_BILINEAR, nil, nil, nil) + // AV_PIX_FMT_VIDEOTOOLBOX格式是无法进行swscale的 imgConvertCtx = sws_getCachedContext(imgConvertCtx, width, height, self.format, dstWidth, dstHeight, dstFormat, SWS_FAST_BILINEAR, nil, nil, nil) } pool = CVPixelBufferPool.ceate(width: dstWidth, height: dstHeight, bytesPerRowAlignment: linesize, pixelFormatType: pixelFormatType) diff --git a/Sources/KSPlayer/MEPlayer/ThumbnailController.swift b/Sources/KSPlayer/MEPlayer/ThumbnailController.swift index 8afb78066..f520ff959 100644 --- a/Sources/KSPlayer/MEPlayer/ThumbnailController.swift +++ b/Sources/KSPlayer/MEPlayer/ThumbnailController.swift @@ -29,10 +29,9 @@ public class ThumbnailController { } public func generateThumbnail(for url: URL, thumbWidth: Int32 = 240) async throws -> [FFThumbnail] { - let task = Task { + try await Task { try getPeeks(for: url, thumbWidth: thumbWidth) - } - return try await task.value + }.value } private func getPeeks(for url: URL, thumbWidth: Int32 = 240) throws -> [FFThumbnail] {