IOS AVPlayer get fps

前端 未结 6 665
渐次进展
渐次进展 2021-01-18 10:59

Im trying to figure out how to retrieve a videos frame rate via AVPlayer. AVPlayerItem has a rate variable but it only returns a value between 0 and 2 (usually 1 when playin

6条回答
  •  星月不相逢
    2021-01-18 11:15

    This is not gonna work anymore, API has changed, and this post is old. :( The swift 4 answer is also cool, this is answer is similar.

    You get the video track from the AVPlayerItem, and you check the FPS there. :)

    private var numberOfRenderingFailures = 0
    func isVideoRendering() -> Bool {
        guard let currentItem = player.currentItem else { return false }
    
        // Check if we are playing video tracks
        let isRendering = currentItem.tracks.contains { ($0.assetTrack?.mediaType == .video) && ($0.currentVideoFrameRate > 5) }
        if isRendering {
            numberOfRenderingFailures = 0
            return true
        }
        numberOfRenderingFailures += 1
        if numberOfRenderingFailures < 5 {
            return true
        }
        return false
    }
    

提交回复
热议问题