Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS get video frame rate

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

like image 323
vodkhang Avatar asked May 11 '12 13:05

vodkhang


2 Answers

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

like image 193
Oleg Avatar answered Sep 30 '22 17:09

Oleg


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;
    }
}
like image 31
AddisDev Avatar answered Sep 30 '22 15:09

AddisDev