iOS AVPlayer slow down
Asked Answered
V

2

0

I am using AVPlayer to play online video in my project. The Video is playing well. Now I want to reduce /increase the fps of the video . Below is my code that I am using:

self.asset = [AVAsset assetWithURL:self.videoUrl];
// the video player
self.player = [AVPlayer playerWithURL:self.videoUrl];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[self.player currentItem]];


self.playerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.myPlayerView.frame.size.height);
[self.myPlayerView.layer addSublayer:self.playerLayer];

- (void)playerItemDidReachEnd:(NSNotification *)notification {
    AVPlayerItem *p = [notification object];
    [p seekToTime:kCMTimeZero];
}

Now how should I reduce/increase the fps for the online video?

Vitrification answered 16/5, 2016 at 7:54 Comment(4)
What do you mean by " I want to reduce /increase the fps of the video"? Is that meaning that you want to play fast-forward or slow motion, or you want to play video in different resolutions?Healey
ya. I want to "play fast-forward or slow motion".Vitrification
Please check my answer, hope that would help youHealey
Thank you for your help.Vitrification
H
1

You can do something like,

 -(float)getFrameRateFromAVPlayer
{
   float fps=0.00;
   if (self.queuePlayer.currentItem.asset) {
     AVAssetTrack * videoATrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] lastObject];
if(videoATrack)
{
    fps = videoATrack.nominalFrameRate;
  }
   }
    return fps;
}

OR

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

Hope this will help :)

Honorary answered 16/5, 2016 at 8:2 Comment(0)
H
1

AVPlayer allows you to set the current rate of the playback. Basically, it accepts a range of possibility values to control the current AVPlayerItem such as play slow forward, fast forward or reverse with negative rates. As saying in the document, you should check whether or not the current item can support those states of playing

enter image description here

Please try to check it out. The link for your reference https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html#//apple_ref/occ/instp/AVPlayer/rate

Healey answered 20/5, 2016 at 3:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.