build video from UIImage using Swift
<p>I am building a IP camera app which can get the view in real time now, and now I want to record the video which is in MJPEG format using Swift.</p>

<pre><code>let imageData = receivedData , imageData.length &gt; 0,
        let receivedImage = UIImage(data: imageData as Data)
</code></pre>

<p>here I have every image that received and save them as UIImage, the problem is how can I record the image stream? I have found a useful resource in Github but I failed, the link is blow:<a href="https://gist.github.com/acj/6ae90aa1ebb8cad6b47b" rel="nofollow noreferrer">https://gist.github.com/acj/6ae90aa1ebb8cad6b47b</a></p>

<p>Can any one give me some hint or do you guys have sample project? Would really appreciate that, thanks!</p>

<p>update: I use the code from Amrit Tiwari's answer, but get this error:
Created asset writer for 640.0x640.0 video
Error converting images to video: pixelBufferPool nil after starting session</p>

<pre><code>if let imageData = receivedData , imageData.length &gt; 0,
        let receivedImage = UIImage(data: imageData as Data){
        let size = CGSize(width: 640, height: 640)
        writeImagesAsMovie([receivedImage], videoPath: "test.mp4", videoSize: size, videoFPS: 2)
    }
</code></pre>

<p>I am not sure whether it is correct for path argument(I want to save it in Documents directory). Please help me, thanks!</p>