iOS AVPlayer变慢了

时间:2016-05-16 07:54:15

标签: ios avplayer avplayerlayer

我正在使用AVPlayer在我的项目中播放在线视频。视频播放得很好。现在我想减少/增加视频的fps。以下是我正在使用的代码:

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

现在我应该如何减少/增加在线视频的fps?

2 个答案:

答案 0 :(得分:1)

你可以做点什么,

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

希望这会有所帮助:)

答案 1 :(得分:1)

AVPlayer允许您设置播放的当前速率。基本上,它接受一系列可能值来控制当前的AVPlayerItem,例如播放慢速前进,快速前进或反向负速率。如文档中所述,您应该检查当前项目是否可以支持这些播放状态

enter image description here

请尝试检查一下。参考链接https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html#//apple_ref/occ/instp/AVPlayer/rate