Search code examples
iphoneaudioios4avfoundation

How to add audio file contents in movie using AVFoundation on iOS4?


I am using AVFoundation to create a movie file (mp4) using images and sound files.

I have successfully created movie file using AVAssetWriterInputPixelBufferAdaptor which appends CVPixelBufferRef (exracted from UIImage objects) in movie file.

Now, I want to add audio contents from a file in that movie. Fetching data from device microphone is not what I am thinking here. And, I could not find anything similar to AVAssetWriterInputPixelBufferAdaptor which can help writing audio data into that movie file.

Am I missing something here?


Solution

  • At least for me the solution was to use AVMutableComposition class.

    1) create AVMutableComposition class object
    2) create 2 AVURLAsset class objects, the first based on your video file, and the second based on a file that you want to extract audio track from
    3) create 2 AVMutableCompositionTrack class objects, like before one with audio track, the second one with video track(based on appropriate assets objects from 2))
    4) create AVAssetExportSession class based on composition object from 1)
    5) export your session

    Best regards