我打算在播放hls流时获得视频分辨率.
我有典型的玩家init:
我有典型的玩家init:
let urlAsset = AVURLAsset(URL: currentVideoUrl) self.player=AVPlayer(playerItem: AVPlayerItem(asset:urlAsset)) .......
我使用KVO,我试图获得视频大小,当我得到.ReadyToPlay状态AVPlayerItem:
func resolutionSizeForVideo() { guard let videoTrack = self.player.currentItem?.asset.tracksWithMediaType(AVMediaTypeVideo).first else { return } let size = CGSizeApplyAffineTransform(videoTrack.naturalSize,videoTrack.preferredTransform) let frameSize = CGSize(width: fabs(size.width),height: fabs(size.height)) print ("video size: \(frameSize)") }
问题是trackWithMediaType()总是返回空数组(但适用于非流文件,例如.mov).
如何获取AVPlayer内播放的HLS视频的大小(CGRect)?
解决方法
您是否能够使用此方法至少记录视频信息?
func checkVideoRez(videoURL: NSURL) -> Bool { let videoAssetSource = AVAsset.init(URL: videoURL) let videoTrack = videoAssetSource.tracksWithMediaType(AVMediaTypeVideo)[0] let size = videoTrack.naturalSize let txf = videoTrack.preferredTransform let realVidSize = CGSizeApplyAffineTransform(size,txf) print(videoTrack) print(txf) print(size) print(realVidSize) ... }