AVAssetExportSession gives me a green frame on the right and bottom of the output video

Here is the code:

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

I tried different quality settings. I always get a 1-2-pixel border that goes down the right side of the video and the bottom, no matter what video I'm trying to make. What could be the reason for this and how to fix it?

EDIT: I do not use any green color anywhere, so this should come from the structure somehow.

+7
ios avfoundation avmutablecomposition avasset avassetexportsession
source share
5 answers

Usually green lines appear after cropping the video, the problem is the rendering width of the video image, it should be multiplied by 16.

Here are some links about it: apple 1 apple 2

+10
source share

a much better solution to get a multiple of 16 would be this approach:

 floor(width / 16) * 16 

or

 ceil(width / 16) * 16 

depending on your preference to have a smaller or a larger width

+4
source share

It turns out that if AVMutableVideoComposition displays a non-even number size width, you get mysterious green borders. Good times.

+2
source share

To get the correct resolution, try something like this ... increase it to the nearest number, which can be divided by 16:

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

This did the magic for me (iOS9, Swift 3, iPhone 6):

Based on: https://www.raywenderlich.com/94404/play-record-merge-videos-ios-swift

Change mainComposition.renderSize to:

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

where mainCompositionWidth , mainCompositionHeight are CGFloat and are calculated as follows:

  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 } 

Also change the scaleFitRatio in videoCompositionInstructionForTrack to:

 scaleToFitRatio = self.mainCompositionWidth / assetTrack.naturalSize.height 

This caused the bottom green line to disappear and the video filled the screen.

+2
source share

All Articles