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

后端 未结 5 1900
余生分开走
余生分开走 2021-02-02 17:07

Here\'s the code:

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
             


        
相关标签:
5条回答
  • 2021-02-02 17:13

    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

    0 讨论(0)
  • 2021-02-02 17:15

    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.

    0 讨论(0)
  • 2021-02-02 17:21

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

    0 讨论(0)
  • 2021-02-02 17:22

    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

    0 讨论(0)
  • 2021-02-02 17:32

    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++;
    }
    
    0 讨论(0)
提交回复
热议问题