Merge pull request #689 from stonerl/more-mpv-settings

MPV: speed up playback start
This commit is contained in:
Arkadiusz Fal 2024-05-23 11:41:56 +02:00 committed by GitHub
commit 03e4c6d4e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 114 additions and 25 deletions

View File

@ -60,18 +60,44 @@ final class MPVClient: ObservableObject {
checkError(mpv_set_option_string(mpv, "input-media-keys", "yes"))
#endif
// CACHING //
checkError(mpv_set_option_string(mpv, "cache-pause-initial", Defaults[.mpvCachePauseInital] ? "yes" : "no"))
checkError(mpv_set_option_string(mpv, "cache-secs", Defaults[.mpvCacheSecs]))
checkError(mpv_set_option_string(mpv, "cache-pause-wait", Defaults[.mpvCachePauseWait]))
// PLAYBACK //
checkError(mpv_set_option_string(mpv, "keep-open", "yes"))
checkError(mpv_set_option_string(mpv, "hwdec", machine == "x86_64" ? "no" : "auto-safe"))
checkError(mpv_set_option_string(mpv, "vo", "libmpv"))
checkError(mpv_set_option_string(mpv, "demuxer-lavf-analyzeduration", "1"))
checkError(mpv_set_option_string(mpv, "deinterlace", Defaults[.mpvDeinterlace] ? "yes" : "no"))
checkError(mpv_set_option_string(mpv, "sub-scale", Defaults[.captionsFontScaleSize]))
checkError(mpv_set_option_string(mpv, "sub-color", Defaults[.captionsFontColor]))
checkError(mpv_set_option_string(mpv, "user-agent", UserAgentManager.shared.userAgent))
// GPU //
checkError(mpv_set_option_string(mpv, "hwdec", Defaults[.mpvHWdec]))
checkError(mpv_set_option_string(mpv, "vo", "libmpv"))
// We set set everything to OpenGL so MPV doesn't have to probe for other APIs.
checkError(mpv_set_option_string(mpv, "gpu-api", "opengl"))
checkError(mpv_set_option_string(mpv, "opengl-swapinterval", "0"))
#if !os(macOS)
checkError(mpv_set_option_string(mpv, "opengl-es", "yes"))
#endif
// We set this to ordered since we use OpenGL and Apple's implementation is ancient.
checkError(mpv_set_option_string(mpv, "dither", "ordered"))
// DEMUXER //
// We request to test for lavf first and skip probing other demuxer.
checkError(mpv_set_option_string(mpv, "demuxer", "lavf"))
checkError(mpv_set_option_string(mpv, "audio-demuxer", "lavf"))
checkError(mpv_set_option_string(mpv, "sub-demuxer", "lavf"))
checkError(mpv_set_option_string(mpv, "demuxer-lavf-analyzeduration", "1"))
checkError(mpv_set_option_string(mpv, "demuxer-lavf-probe-info", Defaults[.mpvDemuxerLavfProbeInfo]))
checkError(mpv_initialize(mpv))
let api = UnsafeMutableRawPointer(mutating: (MPV_RENDER_API_TYPE_OPENGL as NSString).utf8String)

View File

@ -266,8 +266,10 @@ extension Defaults.Keys {
static let mpvEnableLogging = Key<Bool>("mpvEnableLogging", default: false)
static let mpvCacheSecs = Key<String>("mpvCacheSecs", default: "120")
static let mpvCachePauseWait = Key<String>("mpvCachePauseWait", default: "3")
static let mpvCachePauseInital = Key<Bool>("cache-pause-initial", default: true)
static let mpvCachePauseInital = Key<Bool>("mpvCachePauseInitial", default: false)
static let mpvDeinterlace = Key<Bool>("mpvDeinterlace", default: false)
static let mpvHWdec = Key<String>("hwdec", default: "auto-safe")
static let mpvDemuxerLavfProbeInfo = Key<String>("mpvDemuxerLavfProbeInfo", default: "no")
static let showCacheStatus = Key<Bool>("showCacheStatus", default: false)
static let feedCacheSize = Key<String>("feedCacheSize", default: "50")

View File

@ -8,6 +8,8 @@ struct AdvancedSettings: View {
@Default(.mpvCachePauseInital) private var mpvCachePauseInital
@Default(.mpvDeinterlace) private var mpvDeinterlace
@Default(.mpvEnableLogging) private var mpvEnableLogging
@Default(.mpvHWdec) private var mpvHWdec
@Default(.mpvDemuxerLavfProbeInfo) private var mpvDemuxerLavfProbeInfo
@Default(.showCacheStatus) private var showCacheStatus
@Default(.feedCacheSize) private var feedCacheSize
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
@ -73,12 +75,14 @@ struct AdvancedSettings: View {
HStack {
Text("cache-pause-initial")
#if !os(tvOS)
Link(destination: URL(string: "https://mpv.io/manual/stable/#options-cache-pause-initial")!) {
Image(systemName: "link")
.font(.footnote)
}
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-initial")!)
}
#if os(macOS)
.onHover(perform: onHover(_:))
.onHover(perform: onHover(_:))
#endif
#endif
}
@ -87,13 +91,16 @@ struct AdvancedSettings: View {
HStack {
Text("cache-secs")
#if !os(tvOS)
Link(destination: URL(string: "https://mpv.io/manual/stable/#options-cache-secs")!) {
Image(systemName: "link")
.font(.footnote)
#if os(macOS)
.onHover(perform: onHover(_:))
#endif
}
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-secs")!)
}
#if os(macOS)
.onHover(perform: onHover(_:))
#endif
#endif
TextField("cache-secs", text: $mpvCacheSecs)
#if !os(macOS)
@ -106,10 +113,12 @@ struct AdvancedSettings: View {
Group {
Text("cache-pause-wait")
#if !os(tvOS)
Link(destination: URL(string: "https://mpv.io/manual/stable/#options-cache-pause-wait")!) {
Image(systemName: "link")
}
.font(.footnote)
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-wait")!)
}
#if os(macOS)
.onHover(perform: onHover(_:))
#endif
@ -127,17 +136,69 @@ struct AdvancedSettings: View {
HStack {
Text("deinterlace")
#if !os(tvOS)
Link(destination: URL(string: "https://mpv.io/manual/stable/#options-deinterlace")!) {
Image(systemName: "link")
.font(.footnote)
}
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-deinterlace")!)
}
#if os(macOS)
.onHover(perform: onHover(_:))
.onHover(perform: onHover(_:))
#endif
#endif
}
}
HStack {
Text("hwdec")
#if !os(tvOS)
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-hwdec")!)
}
#if os(macOS)
.onHover( /* perform: onHover(_:) */ )
#endif
#endif
Picker("", selection: $mpvHWdec) {
ForEach(["auto", "auto-safe", "auto-copy"], id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
}
if mpvEnableLogging {
logButton
}
HStack {
Text("demuxer-lavf-probe-info")
#if !os(tvOS)
Image(systemName: "link")
.accessibilityAddTraits([.isButton, .isLink])
.font(.footnote)
.onTapGesture {
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-demuxer-lavf-probe-info")!)
}
#if os(macOS)
.onHover( /* perform: onHover(_:) */ )
#endif
#endif
Picker("", selection: $mpvDemuxerLavfProbeInfo) {
ForEach(["yes", "no", "auto", "nostreams"], id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
}
if mpvEnableLogging {
logButton
}