AVAssetExportSession giving me a green border on right and bottom of output video
Asked Answered
I

5

15

Here's 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've tried different quality settings. I always get a 1-2 pixel border running down the right side of the video and along the bottom, no matter what video I'm trying to render. What could be causing this and how do I fix it?

EDIT: I am not using any kind of green color anywhere, so this must be coming from the framework somehow.

Inhumanity answered 5/4, 2014 at 16:24 Comment(0)
R
22

Usually green lines appear after video cropping, problem is in video renderSize width, it should be multiply of 16.

Here some links about this: apple 1 apple 2

Rockefeller answered 17/4, 2014 at 9:20 Comment(1)
For me just making sure the video had an even width did the trick (the number I tested wasn't a multiple of 4, 8 or 16)Correct
L
19

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

floor(width / 16) * 16

or

ceil(width / 16) * 16

depending on your preference of having a smaller or bigger width

Langlauf answered 10/7, 2017 at 13:57 Comment(0)
S
6

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

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

Changing mainComposition.renderSize to:

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

where mainCompositionWidth, mainCompositionHeight are CGFloats and are calculated like this:

 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 modifying scaleFitRatio in the videoCompositionInstructionForTrack function to:

scaleToFitRatio = self.mainCompositionWidth / assetTrack.naturalSize.height

This made the bottom green line disappear and the video fills the screen.

Sugar answered 4/7, 2016 at 6:37 Comment(0)
I
4

Turns out that if AVMutableVideoComposition's render size width isn't an even number, you get the mysterious green borders. Good times.

Inhumanity answered 5/4, 2014 at 18:43 Comment(0)
R
2

In order to get the proper resolution try something like this... increment it until the nearest number that 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++;
}
Rapture answered 9/6, 2015 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.