在ios中获取视频的FPS

问题描述 投票:0回答:3

如何在 iOS 应用程序中使用 AVFoundation 获取视频的 FPS?我已经尝试了下面的代码,但它似乎不正确。

AVAssetTrack *videoAssetTrack = [myAsset tracksWithMediaType:AVMediaTypeVideo].firstObject;
NSLog(@"FPS is  : %f ",videoAssetTrack.nominalFrameRate);
ios objective-c avasset
3个回答
5
投票

我通过以下代码行获得了正确的 FPS:

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

2
投票

适用于 Swift 5 的 AVAsset 扩展

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

1
投票

iOS 16

您可以受益于 Swift 并发开发,通过使用

Load
属性异步检索
FPS
size or dimension
duration

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)
}
© www.soinside.com 2019 - 2024. All rights reserved.