user2929734
user2929734

Reputation: 31

How do I fetch the current frame of a video playing in iOS using AVFoundation?

I can see the nominalFrameRate for some video tracks, but not current frame in AVFoundation docs. How can I get the current frame number of the track as it is played in an AVPlayer? I know frame rates will vary, and nominalFrameRate will always be 0.0 in .m3u8 streams, but surely there must be a way to get the frame number of the currently playing track without having to multiply nominalFrameRate by currentTime?

Thanks.

Upvotes: 3

Views: 1023

Answers (1)

AddisDev
AddisDev

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 and always returns 0.0 as you mentioned.

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: 2

Related Questions