在iOS中获取视频的FPS

vpfxa7rd  于 2023-02-01  发布在  iOS
关注(0)|答案(3)|浏览(201)

如何在iOS SDK中获得视频的FPS。我已经尝试了下面的代码行,但它似乎并不完美。

AVAssetTrack *videoAssetTrack = [myAsset tracksWithMediaType:AVMediaTypeVideo].firstObject;
NSLog(@"FPS is  : %f ",videoAssetTrack.nominalFrameRate);

任何帮助都将不胜感激。

xxslljrj

xxslljrj1#

我得到了正确的FPS与下面的代码行:

AVAsset * myAsset = [[AVURLAsset alloc] initWithURL: _videoUrl options: nil];
AVAssetTrack * videoAssetTrack = [myAsset tracksWithMediaType: AVMediaTypeVideo].firstObject;
NSLog(@"FPS is  : %f ", videoAssetTrack.nominalFrameRate);
rseugnpd

rseugnpd2#

Swift 5的AVAsset扩展

extension AVAsset {
   /**
    * Get FPS from AVAsset
    */
   var fps: Float? {
      self.tracks(withMediaType: .video).first?.nominalFrameRate
   }
}
6kkfgxo0

6kkfgxo03#

    • iOS 16操作系统**

通过异步使用Load属性,您可以从Swift并发开发中获益,以检索FPSsize or dimensionduration

var asset: AVAsset? = AVAsset(url: filePath)
if let asset = asset,
   let videoTrack = try? await asset.loadTracks(withMediaType: .video).first {

     let size = try? await videoTrack.load(.naturalSize)
     let fps = try? await videoTrack.load(.nominalFrameRate)
     let duration = try? await asset.load(.duration)
}

相关问题