kingslay / KSPlayer

A video player for iOS、macOS、tvOS、visionOS , based on AVPlayer and FFmpeg, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, SwiftUI, support subtitles.
https://apps.apple.com/app/tracyplayer/id6450770064
GNU General Public License v3.0
939 stars 194 forks source link

match framerate and dynamic range #197

Closed UnknownCoder807 closed 2 years ago

UnknownCoder807 commented 2 years ago

The Apple TV (tvOS) supports Dynamic Range and Framerate matching. Does KSPlayer support this? I know AVPlayer does.

Alanko5 commented 2 years ago

WIP: https://github.com/kingslay/KSPlayer/pull/186

UnknownCoder807 commented 2 years ago

I found today that AVPlayerController has the property appliesPreferredDisplayCriteriaAutomatically

This can be true/false. False disables Match Framerate so you do this for a per app basis.

Is it possible AVPlayerController is in KSPlayer and this option can be used? thanks.

kingslay commented 2 years ago

I found today that AVPlayerController has the property appliesPreferredDisplayCriteriaAutomatically

This can be true/false. False disables Match Framerate so you do this for a per app basis.

Is it possible AVPlayerController is in KSPlayer and this option can be used? thanks.

AVPlayerViewController is UIViewController not View. So it's not good to use this

UnknownCoder807 commented 2 years ago

I had a feeling it wasn't possible. Thanks.

Alanko5 commented 2 years ago

@UnknownCoder807 you need define protocol to configure framerate an dymanic range: https://github.com/Alanko5/KSPlayer/blob/develop/Sources/KSPlayer/Video/tvOS/AVDisplayCriteriaKS.h

for setup frame rate and dynamic range: https://github.com/Alanko5/KSPlayer/blob/develop/Sources/KSPlayer/Video/tvOS/Info/Views/TVPlayerView.swift

Detection for configure it (example):

         var dynamicRange = .SDR
         for track in player.tracks(mediaType: .video) {
            fps = track.nominalFrameRate

            if track.codecType.string == "ehvd" /// DolbyVision
            {
                dynamicRange = .DV
            }
            else if let colorPrimaries = track.colorPrimaries, /// HDR
                colorPrimaries.contains("2020")  {
                dynamicRange = .HDR
            }
        }
        set(fps: fps, contentMode: dynamicRange)
kingslay commented 2 years ago

@UnknownCoder807 you need define protocol to configure framerate an dymanic range: https://github.com/Alanko5/KSPlayer/blob/develop/Sources/KSPlayer/Video/tvOS/AVDisplayCriteriaKS.h

for setup frame rate and dynamic range: https://github.com/Alanko5/KSPlayer/blob/develop/Sources/KSPlayer/Video/tvOS/Info/Views/TVPlayerView.swift

Detection for configure it (example):

         var dynamicRange = .SDR
         for track in player.tracks(mediaType: .video) {
            fps = track.nominalFrameRate

            if track.codecType.string == "ehvd" /// DolbyVision
            {
                dynamicRange = .DV
            }
            else if let colorPrimaries = track.colorPrimaries, /// HDR
                colorPrimaries.contains("2020")  {
                dynamicRange = .HDR
            }
        }
        set(fps: fps, contentMode: dynamicRange)

@Alanko5 thanks. i fixed it on 4f387add45a9ae5b81484108861ca4c7b8ec91d1.

    open func preferredDisplayCriteria(refreshRate: Float, videoDynamicRange: Int32) -> AVDisplayCriteria? {
//        AVDisplayCriteria(refreshRate: fps, videoDynamicRange: dynamicRange.rawValue)
        nil
    }
Alanko5 commented 2 years ago

After stop playing/deinit player video you need set displayManager.preferredDisplayCriteria = nil For reset to default

UnknownCoder807 commented 2 years ago

Thanks for this both of you. Can I use it in KSVideoPlayerView (swiftui demo) ?

kingslay commented 2 years ago

Thanks for this both of you. Can I use it in KSVideoPlayerView (swiftui demo) ?

yes. you can use it. you only need override KSOptions

UnknownCoder807 commented 2 years ago

Thanks for this both of you. Can I use it in KSVideoPlayerView (swiftui demo) ?

yes. you can use it. you only need override KSOptions

Thanks. I'm not that great with SwiftUI yet and still coming to terms with how your swiftui demo works. Could I ask how to enable preferredDisplayCriteria ? some sample code would be really helpful. thanks

edit : I meant to say I know how to override KSOptions but I don't know how to return the correct value.

class MyOptions: KSOptions {
   override func preferredDisplayCriteria(refreshRate: Float, videoDynamicRange: Int32) -> AVDisplayCriteria? {

 }
}
Alanko5 commented 2 years ago

You need import this header to bridging header in your project. https://github.com/Alanko5/KSPlayer/blob/develop/Sources/KSPlayer/Video/tvOS/AVDisplayCriteriaKS.h

Alanko5 commented 2 years ago

If you use KSAVplayer then you detect criteria from avassat:

https://developer.apple.com/documentation/avfoundation/avpartialasyncproperty/3816776-preferreddisplaycriteria