简体   繁体   English

iOS AVPlayer变慢

[英]iOS AVPlayer slow down

I am using AVPlayer to play online video in my project. 我正在使用AVPlayer在我的项目中播放在线视频。 The Video is playing well. 视频播放良好。 Now I want to reduce /increase the fps of the video . 现在,我要降低/增加视频的fps。 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? 现在,我应该如何降低/提高在线视频的fps?

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 :) 希望这会有所帮助:)

AVPlayer allows you to set the current rate of the playback. AVPlayer允许您设置当前播放速率。 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. 基本上,它接受一定范围的可能性值来控制当前的AVPlayerItem,例如以负速率播放慢速前进,快进或快退。 As saying in the document, you should check whether or not the current item can support those states of playing 如文档中所述,您应该检查当前项目是否可以支持这些播放状态

在此处输入图片说明

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 供您参考的链接https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html#//apple_ref/occ/instp/AVPlayer/rate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM