Output from AVAssetWriter (UIImages written to video) distorted
Asked Answered
S

3

4

I am using an AVAssetWriter to encode a series of images to a movie file, following Zoul's answer here: How do I export UIImage array as a movie?.

In short my process is:

  • create UIImage from .png file
  • Get CGImage from UIImage
  • convert the CGImage to CVPixelBuffer (using zoul's function pixelBufferFromCGImage exactly)
  • write the frames to .mov using a AVAssetWriterInputPixelBufferAdaptor and AVAssetWriter

This is working fine in most cases, however sometimes the .mov file that is encoded is distorted (see picture below). I was wondering if this type of distorted image output is familiar to to anyone, and if there is any step I might have taken in encoding the frames that would cause this. The problem occurs specifically when the source images I use are generated by calls in Titanium to ImageView.toBlob(). Besides the Titanium side, any hints on how this type of result might appear would be great!

Thanks, Alexander

Screen from movie: http://tinypic.com/view.php?pic=8wkqys&s=7

Original image: http://commons.wikimedia.org/wiki/File:Phalaenopsis_(aka).jpg

Phalaenopsis_(aka)

Studner answered 7/9, 2011 at 1:3 Comment(0)
S
4

Ok, this turned out to be an issue with the aspect ratio of the images I was reading in being different from the aspect ratio of the PixelBuffer I was creating. Made them equal and it works fine.

Studner answered 7/9, 2011 at 18:0 Comment(0)
B
6

Please take a look at this link. It says the width should be a multiple of 16.

Just get the size.width, calculate the nearest number which is multiple of 16. And hard code it in place of size.width.

It works :)

Bush answered 10/1, 2013 at 11:29 Comment(0)
S
4

Ok, this turned out to be an issue with the aspect ratio of the images I was reading in being different from the aspect ratio of the PixelBuffer I was creating. Made them equal and it works fine.

Studner answered 7/9, 2011 at 18:0 Comment(0)
D
1

Old thread but different answer, instead of multiplying by a number I use CVPixelBufferGetBytesPerRow to get the actual bytes per row for CGBitmapContextCreate and it fixed the distortion, leaving height/width the same

Dancette answered 12/3, 2020 at 23:52 Comment(1)
You , sir, are a godsend. Thank you! For those confused, change (4 * width in zoul's answer to CVPixelBufferGetBytesPerRow(pxbuffer))Factorial

© 2022 - 2024 — McMap. All rights reserved.