How do I export UIImage array as a movie?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
To turn an array of UIImage frames into a movie on iOS, the usual solution is AVAssetWriter plus one pixel buffer per frame. The workflow is straightforward once the pieces are clear: choose one output size, convert each image into a CVPixelBuffer, assign presentation times, and finish the writer cleanly.
Build the Writer First
AVAssetWriter creates the output file, and AVAssetWriterInput describes the encoded video stream.
Every frame in the movie must match the same output dimensions. If your images come from different sources, normalize them before or during conversion.
Convert UIImage to CVPixelBuffer
The writer cannot append UIImage objects directly. It needs a pixel buffer in a consistent format.
This redraws each image into a stable canvas, which is exactly what the encoder expects.
Append Frames With Predictable Timing
Once you have a writer and a pixel-buffer adaptor, append frames in order using one presentation time per frame.
This takes you from an image array to an .mp4 file with deterministic frame timing.
Decide the Frame Rate Up Front
The chosen fps controls how long each still image stays on screen. At 30 fps, each image lasts one thirtieth of a second. If you want a slower slideshow effect, either lower the frame rate or append the same frame multiple times.
That is a design choice, not an export bug. People often think the movie is wrong when the real issue is that the frame timing does not match the intended playback speed.
Common Pitfalls
The most common mistake is allowing frames to have inconsistent sizes. Video encoders expect one stable width and height for the whole stream.
Another mistake is forgetting to remove an existing file at the output path. AVAssetWriter will not silently overwrite it.
Developers also sometimes skip input.isReadyForMoreMediaData and then wonder why frames are dropped or append calls fail.
Finally, finishWriting completes asynchronously. If you try to use the file before the completion handler runs, you may read an incomplete movie.
Summary
- Exporting
UIImageframes to video usually meansAVAssetWriterplus pixel buffers. - Convert every image to a
CVPixelBufferusing one fixed output size. - Append frames with explicit presentation times based on your target frame rate.
- Remove any existing output file before writing.
- Treat
finishWritingas asynchronous and wait for completion before using the movie.
Related reading
- How do I find all paths through a set of given nodes in a DAG?
- How do I find the duplicates in a list and create another list with them?
- How do I find the median of numbers in linear time using heaps?
- How do I find the size of a 2D array?
- How do I find out if the GPS of an Android device is enabled
- How do I find out which keystore was used to sign an app?
- How do I find the stack trace in Visual Studio?
- How do I find which attributes my tree splits on, when using scikit-learn?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.