ios – 如何获取AVPlayer内的HLS流的视频大小?

前端之家收集整理的这篇文章主要介绍了ios – 如何获取AVPlayer内的HLS流的视频大小?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我打算在播放hls流时获得视频分辨率.
我有典型的玩家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)

...

}
原文链接:https://www.f2er.com/iOS/337082.html

猜你在找的iOS相关文章