Why does my movie from UIImages gets distorted?
Asked Answered
J

3

13

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.

Jacobian answered 13/3, 2012 at 20:33 Comment(3)
I know that this is because of multiply by 16, Bu how to solve this issue ? I have images with 1080*1980 any suggestion ?Helyn
@DipenChudasama downscale to a size where the width is a multiple of 16Somber
Thanks @Somber I was doing same :)Helyn
J
46

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.

Jacobian answered 14/3, 2012 at 9:42 Comment(9)
Wasted many hours wondering what was going on ... this was the key!Neoarsphenamine
thank you so much! i was struggling with this for hours! this fixed it!Whitehorse
Do we know why this is the case?Jadotville
Great great great !!! guys the best size is 1024 x 1024 , just convert you image to 1024Attire
BTW - width:height vs height:width matters. I thought 1080:1920 would work but its the width that needs to be a multiple of 16 - had to downscale to 1024:1820Somber
@Somber how did you down scale? I have some images in an array. Shall I draw them in bitamp context forcing the width to be a multiple of 16 and at the same time maintaining the aspect ratio of height parameter?Leaseback
Okay, but what do I do if I really need that 1080x1920 image resolution? It's absolutely a requirement for my purposes, because I have a FullHD video, I take the last frame out of it, generate a 3 second video from this frame, and then combine those two videos, and since I want to preserve the best quality, I need that 1080x1920 image.Concentrate
@Concentrate Is it a portrait? Maybe try to rotate it, export, and then rotate again? Or using a 1072x1,905.7778 size?Jacobian
@Jacobian I went with 1008x1792 image size, which is a viable solution for me, but my inner perfectionist is still mad with the fact that I cannot generate a 1080x1920 image properly from the beginning.Concentrate
E
3

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

Excelsior answered 20/11, 2020 at 3:22 Comment(0)
M
2

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.

Mcneely answered 21/3, 2012 at 8:18 Comment(1)
Please clarify what you mean. Do you mean the image size does not actually have to be 16 - and that you merely have to specify the width? If so, where do you specify the width?Stuffy

© 2022 - 2024 — McMap. All rights reserved.