I was able to create a * .mov file using AVAssetWriter. I used the CMSampleBuffer screen shots and audio that I received from using AVCaptureSession and passed it to the inputs for AVAssetWriter, and it worked.
Now I would like to combine the * .mov file with music from the ipod / iphone music library (most likely * .mp3). Therefore, my initial idea is to use AVAssetReader to retrieve samples from a * .mp3 and * .mov file and transfer the samples to AVAssetWriter. Will this work? Just by reading the documentation, I think it is possible.
I played with the idea a bit, but I can't get it to work.
My first attempt is to use 2 AVAssetReaders, one for each file. I used AVAssetReaderAudioMixOutput as the output for the first reader, and then AVAssetReaderVideoCompositionOutput for the second. The problem with using AVAssetReaderVideoCompositionOutput requires you to pass AVVideoComposition to it. I was having trouble creating AVVideoComposition / AVMutableVideoComposition, so I gave up on this solution. I don’t understand why I need to transfer AVVideoComposition, I just want to get movie samples.
So, my second attempt is similar, but instead of using AVAssetReaderVideoCompositionOutput as the output for the second reader, I used 2 AVAssetReaderTrackOutput instead. So, now I have 2 readers with a total of 3 outputs, and I tried to use a sample from the outputs and pass it to AVAssetWriter to create a * .mov file. I was able to run it without errors / crashes. But I can not play the resulting * .mov file. Its game duration is 0. So you are out of luck with the idea of AVAssetReader + AVAssetWriter.
So my question / s: Can you use AVAssetReader and AVAssetWriter to merge two files? Has anyone tried to do this and make it work? Should I just use AVMutableVideoComposition?
I’ll send a code if necessary.