AVAssetExportSession给我一个输出video的右侧和底部的绿色边框

代码如下:

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; exporter.outputURL = outputUrl; exporter.outputFileType = AVFileTypeQuickTimeMovie; exporter.videoComposition = mainComposition; exporter.shouldOptimizeForNetworkUse = YES; [exporter exportAsynchronouslyWithCompletionHandler:^{ //completion }]; 

我尝试了不同的质量设置。 无论我尝试渲染什么video,我都会在video的右侧沿着底部获取一个1-2像素的边框。 什么可能导致这个,我该如何解决?

编辑:我没有在任何地方使用任何种类的绿色,所以这必须以某种方式来自框架。

通常绿色的线出现在video裁剪后,问题是在videorenderSize的宽度,它应该是16乘以。

这里有一些链接: 苹果1 苹果2

得到16的倍数的更好的解决scheme将是这种方法:

 floor(width / 16) * 16 

要么

 ceil(width / 16) * 16 

取决于你的喜好有一个更小或更大的宽度

原来,如果AVMutableVideoComposition的渲染大小的宽度不是一个偶数,你会得到神秘的绿色边框。 美好时光。

为了得到正确的解决scheme尝试这样的事情…增加它,直到最接近的数字,可以除以16:

 computedVideoSize=self.view.frame.size.width; while (computedVideoSize%16>0) { // find the right resolution that can be divided by 16 computedVideoSize++; } 

这对我来说是魔术(iOS9,Swift 3,iPhone 6):

基于: https : //www.raywenderlich.com/94404/play-record-merge-videos-ios-swift

mainComposition.renderSize更改为:

 mainComposition.renderSize = CGSize(width: self.mainCompositionWidth, height: self.mainCompositionHeight) 

其中mainCompositionWidthmainCompositionHeightCGFloat并按如下计算:

  self.mainCompositionWidth = UIScreen.mainScreen().bounds.width self.mainCompositionHeight = UIScreen.mainScreen().bounds.height while (self.mainCompositionWidth%16>0) { // find the right resolution that can be divided by 16 self.mainCompositionWidth = self.mainCompositionWidth + 1.0 } while (self.mainCompositionHeight%16>0) { // find the right resolution that can be divided by 16 self.mainCompositionHeight = self.mainCompositionHeight + 1.0 } 

还可以修改videoCompositionInstructionForTrack函数中的scaleFitRatio以:

 scaleToFitRatio = self.mainCompositionWidth / assetTrack.naturalSize.height 

这使底部的绿线消失,video充满了屏幕。