Geva
Geva

Reputation: 820

Why does my movie from UIImages gets distorted?

I'm using zoul's solution to export UIImage array as a movie. But my frames all turns out distorted. Here's the original image:

original image

Here's a similar distortion example:
similar distortion example

I've read here that it has something to do with aspect ratio, but there's no explanation on how to fix it.

Upvotes: 13

Views: 5732

Answers (3)

Daryl Teo
Daryl Teo

Reputation: 5495

For those still doing the journey in 2020, and getting distortion in their movies because its not width 16px

change

CGContextRef context = CGBitmapContextCreate(pxdata,
                                             width, height,
                                             8, 4 * width,
                                             rgbColorSpace,
                                             kCGImageAlphaNoneSkipFirst);

to

CGContextRef context = CGBitmapContextCreate(pxdata,
                                             width, height,
                                             8, CVPixelBufferGetBytesPerRow(pxbuffer),
                                             rgbColorSpace,
                                             kCGImageAlphaNoneSkipFirst);

Credit to @Bluedays Output from AVAssetWriter (UIImages written to video) distorted

Upvotes: 3

Eric.Cheng
Eric.Cheng

Reputation: 172

I'v encountered this problem too, and I found the reason is the image's size is not the multiple of 16, you can change the size and have a try.

Upvotes: 2

Geva
Geva

Reputation: 820

After a lot of experiments with different image sizes, and with the help of this article, I've got to the conclusion that the width of the images must be a multiple of 16.

Upvotes: 46

Related Questions