Merge multiple videos in objective-c

today we are learning how to merge multiple videos in a single file, so lets start

1) Converting Video file to AVAsset

AVAsset is an abstract class to represent timed audiovisual media such as videos and sounds. Each asset contains a collection of tracks that are intended to be presented or processed together, each of a uniform media type, including but not limited to audio, video, text, closed captions, and subtitles.

2) add AVAssets to AVmutableCompositionTrack

AVMutableCompositionTrack is a mutable subclass of AVCompositionTrack that lets you for insert, remove, and scale track segments without affecting their low-level representation (that is, the operations you perform are non-destructive on the original).

3) set Asset layer in to the transform

AVMutableVideoCompositionLayerInstruction is a mutable subclass of AVVideoCompositionLayerInstruction that is used to modify the transform, cropping, and opacity ramps to apply to a given track in a composition.

4) add all layer in to one layer and video composition

The AVMutableVideoComposition class is a mutable subclass of AVVideoComposition. A video composition describes, for any time in the aggregate time range of its instructions, the number and IDs of video tracks that are to be used in order to produce a composed video frame corresponding to that time. When AV Foundation’s built-in video compositor is used, the instructions an AVVideoComposition comprises can specify a spatial transformation, an opacity value, and a cropping rectangle for each video source, and these can vary over time via simple linear ramping functions.

5) export all composition to video using AVAssetExportSession

An AVAssetExportSession object transcodes the contents of an AVAsset source object to create an output of the form described by a specified export preset. Prior to initializing an instance of AVAssetExportSession, you can use allExportPresets to get the complete list of presets available. Use exportPresetsCompatibleWithAsset: to get a list of presets that are compatible with a specific asset.

You can Download Demo Programs from here

Leave a comment