I am experimenting streaming with HLS to an AVPlayer instance - like the Apple StitchedStreamPlayer sample project.
I am getting the current player time nicely, but in order 开发者_StackOverflow社区to calculate a particular frame or generate a SMPTE timecode I need to know the FPS (Frames Per Second)
Can anyone help me figure out how to retrieve this from AVPlayer or AVPlayerItem or similar?
Many thanks!
[[video_player.currentItem.tracks[0] assetTrack] nominalFrameRate];
func getFPS(_ videoUrl : URL) -> Float {
let asset:AVAsset = AVAsset(url: videoUrl)
let tracks = asset.tracks(withMediaType: .video)
let fps = tracks.first?.nominalFrameRate
return fps ?? 0.0
}
`
精彩评论