Crop video in iOS see weird green line around video

后端 未结 2 477
[愿得一人]
[愿得一人] 2020-12-30 12:37

Hey everyone I am cropping a video taken from the camera on iPhone and then cropping it an playing it back like this. When i do it however I get a weird green line around th

相关标签:
2条回答
  • 2020-12-30 13:10

    There are width requirements for either the iOS encoders or the video format itself. Try making your width even or divisible by 4.

    I wasn't aware of there being a similar requirement for height, but that could be worth a try too.

    I've never found it documented, but requiring evenness makes a certain amount of sense as h.264 uses a 4:2:0 yuv colour space, where the UV component is half the size (in both dimensions) of the Y channel, which has the overall dimensions of the video. If those dimensions weren't even, the UV dimensions wouldn't be integral.

    p.s. the hint in these cases is the mysterious green colour. I think it corresponds to 0, 0, 0 in YUV.

    0 讨论(0)
  • 2020-12-30 13:19

    The answer by @Rhythmic saved my day.

    In my app, I need square video as per screen width size. So for iPhone 5 this comes 320 pixels and for iPhone 6 this becomes 375 pixels.

    So I came across same green line issue for iPhone 6 size resolution. Because its screen size width is 375 pixels. And not divisible by 2 or 4.

    To come out of this we made these changes

     AVMutableVideoComposition *MainCompositionInst = [AVMutableVideoComposition videoComposition];
        MainCompositionInst.instructions = [NSArray arrayWithObject:MainInstruction];
        MainInstruction.timeRange = range;
    
        MainCompositionInst.frameDuration = VideoFrameDuration; //Constants
        MainCompositionInst.renderScale = VideoRenderScale; //Constants
    
        if ((int)SCREEN_WIDTH % 2 == 0)
            MainCompositionInst.renderSize = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH);
        else // This does the trick
            MainCompositionInst.renderSize = CGSizeMake(SCREEN_WIDTH+1, SCREEN_WIDTH+1); 
    

    Hope This helps. Just add one more pixel to it so it becomes divisible by 2 or 4.

    Thanks

    0 讨论(0)
提交回复
热议问题