Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVMutableComposition-缩放范围导致高速视频在快速运动时结巴_Ios_Video_Avfoundation_Avplayer_Avmutablecomposition - Fatal编程技术网

Ios AVMutableComposition-缩放范围导致高速视频在快速运动时结巴

Ios AVMutableComposition-缩放范围导致高速视频在快速运动时结巴,ios,video,avfoundation,avplayer,avmutablecomposition,Ios,Video,Avfoundation,Avplayer,Avmutablecomposition,我正在使用scaleTimeRange:toDuration:生成高达原始视频速度10倍的快速运动效果。然而,我注意到,当以高于正常速度4倍的速度通过AVPlayer播放时,具有更高比特率(例如20比特/秒及以上)的视频开始结巴,如果AVPlayerLayer运行一段时间,足以使其崩溃(消失) 密码 //initialize the player self.player = [[AVPlayer alloc] init]; //load up the asset AVURLAsset *ass

我正在使用scaleTimeRange:toDuration:生成高达原始视频速度10倍的快速运动效果。然而,我注意到,当以高于正常速度4倍的速度通过AVPlayer播放时,具有更高比特率(例如20比特/秒及以上)的视频开始结巴,如果AVPlayerLayer运行一段时间,足以使其崩溃(消失)

密码

//initialize the player
self.player = [[AVPlayer alloc] init];

//load up the asset
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[[NSBundle mainBundle] URLForResource:@"sample-video" withExtension:@"mov"] options:nil];

[asset loadValuesAsynchronouslyForKeys:@[@"playable", @"hasProtectedContent", @"tracks"] completionHandler:
 ^{
     AVMutableComposition *composition = [AVMutableComposition composition];
     AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];

     // composition set to play at 60fps
     videoComposition.frameDuration = CMTimeMake(1,60);

     //add video track to composition
     AVMutableCompositionTrack *videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

     //1080p composition
     CGSize renderSize = CGSizeMake(1920.0, 1080.0);
     CMTime currentTime = kCMTimeZero;
     CGFloat scale = 1.0;
     AVAssetTrack *assetTrack = nil;

     assetTrack = [asset tracksWithMediaType:AVMediaTypeVideo].firstObject;

     [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:assetTrack  atTime:currentTime error:nil];


     CMTimeRange scaleTimeRange = CMTimeRangeMake(currentTime, asset.duration);

     //Speed it up to 8x.
     CMTime scaledDuration = CMTimeMultiplyByFloat64(asset.duration,1.0/8.0);

     [videoTrack scaleTimeRange:scaleTimeRange toDuration:scaledDuration];

     AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];

     //ensure video is scaled up/down to match the composition
     scale = renderSize.width/assetTrack.naturalSize.width;
     [layerInstruction setTransform:CGAffineTransformMakeScale(scale, scale) atTime:currentTime];


     AVMutableVideoCompositionInstruction *videoInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
     videoInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, composition.duration);
     videoInstruction.layerInstructions = @[ layerInstruction];

     videoComposition.instructions = @[videoInstruction];
     videoComposition.renderSize = renderSize;

     //pass the stuff to AVPlayer for playback
     self.playerItem = [AVPlayerItem playerItemWithAsset:composition];
     self.playerItem.videoComposition = videoComposition;
     [self.player replaceCurrentItemWithPlayerItem:self.playerItem];

     //playerView is a custom view with AVPlayerLayer, picked up from https://developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html#//apple_ref/doc/uid/TP40010188-CH3-SW11

     [self.playerView setPlayer:self.player];

     //call [self.player play] when ready.


 }];
一些注意事项:

  • 所有测试都在iphone6上完成
  • 我故意不添加任何音频曲目,以排除音频在此处发挥作用的可能性
  • 正常比特率视频(平均16Mbits/s)在10x上播放效果良好
  • 相同的合成代码在OSX应用程序上产生平滑播放
  • 比特率越高,口吃越明显
  • 所有正在测试的视频均为1080p 60fps
  • 如果在中打开并导出到1080,则高比特率视频表现良好,以便降低比特率并保持FPS
  • 不涉及视频的渲染/导出

有没有其他人遇到过这种情况并知道解决方法?

你做过吗?还没有运气,伙计。我猜这只是硬件的限制,即使是iPhone6。现在我不得不将速度限制在4倍。这个问题一直存在,并且必须依赖于录制后的预计算。发生了什么?我播放了一段从1/8到1/128的视频,每次翻倍都会更快。