Search code examples
iphoneobjective-ciosvideoframe-rate

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


Solution

  • 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;
        }
    }