Reputation: 18741
I want to get the frame rate for a specific video. I tried to look at APIs in the AVFoundation
and AssetsLibrary
like AVURLAsset or AVAssetReader. None of them are really helpful. Does anybody know a method in the Apple's frameworks/library to get the frame rate
Upvotes: 8
Views: 9629
Reputation: 2630
For the property currentVideoFrameRate
, from Apple's document:
If the item is not playing, or if the media type of the track is not video, the value of this property is 0.0.
It requires the item is in "playing", so I used nominalFrameRate
instead.
It still works in iOS 12, swift 4:
let tracks = asset.tracks(withMediaType: .video)
let fps = tracks?.first?.nominalFrameRate
Remember to handle nil checking.
Upvotes: 2
Reputation: 1801
For iOS 7+ you can use the currentVideoFrameRate property of AVPlayerItemTrack. Its the only consistent property that I've seen measure FPS. The nominalFrameRate property seems to be broken in HLS streams.
AVPlayerItem *item = AVPlayer.currentItem; // Your current item
float fps = 0.00;
for (AVPlayerItemTrack *track in item.tracks) {
if ([track.assetTrack.mediaType isEqualToString:AVMediaTypeVideo]) {
fps = track.currentVideoFrameRate;
}
}
Upvotes: 5
Reputation: 101
The easier option is to obtain an AVAssetTrack and read its nominalFrameRate property. Looks like this can help you.
Nominal frame rate is the frame rate of the track, in frames per second. (read-only) AVAssetTrack Class @property(nonatomic, readonly) float nominalFrameRate
Upvotes: 9