ios - How to use multiple tracks in an AVMutableComposition -
please see code below. i'm trying add 2nd track have smaller video overlaid on top of background video. can background video display in final exported file. doing wrong? , how control order of tracks, i.e. layering of composition?
avmutablecomposition* composition = [[avmutablecomposition alloc] init]; nsurl* backgroundurl = [nsurl fileurlwithpath:backgroundoutputpath]; avurlasset* url0 = [avurlasset urlassetwithurl:backgroundurl options:nil]; avmutablecompositiontrack *backgroundvideotrack = [composition addmutabletrackwithmediatype:avmediatypevideo preferredtrackid:kcmpersistenttrackid_invalid]; avassettrack* bgassettrack = [[url0 trackswithmediatype:avmediatypevideo] objectatindex:0]; [backgroundvideotrack inserttimerange:cmtimerangemake(kcmtimezero, [url0 duration]) oftrack:bgassettrack attime:kcmtimezero error:&error]; nsurl* videourl = [[nsbundle mainbundle] urlforresource: @"star" withextension:@"mp4"]; avurlasset* url = [avurlasset urlassetwithurl:videourl options:nil]; avmutablecompositiontrack *compositionvideotrack = [composition addmutabletrackwithmediatype:avmediatypevideo preferredtrackid:kcmpersistenttrackid_invalid]; avassettrack *clipvideotrack = [[url trackswithmediatype:avmediatypevideo] objectatindex:0]; [compositionvideotrack inserttimerange:cmtimerangemake(kcmtimezero, [url duration]) oftrack:clipvideotrack attime:kcmtimezero error:&error]; avassetexportsession *exportsession = [[avassetexportsession alloc] initwithasset:composition presetname:avassetexportpresetmediumquality]; nsstring *exportpath = [documentsdirectorypath stringbyappendingpathcomponent:@"test_av.mp4"]; [[nsfilemanager defaultmanager] removeitematpath:exportpath error:nil]; nsurl *exporturl = [nsurl fileurlwithpath:exportpath]; exportsession.outputurl = exporturl; exportsession.outputfiletype = avfiletypequicktimemovie; [exportsession exportasynchronouslywithcompletionhandler:^{ nslog (@"exporting. status %d", exportsession.status); switch (exportsession.status) { case avassetexportsessionstatusfailed: case avassetexportsessionstatuscompleted: { nslog(@"export done"); break; } }; }];
check tutorials.this may helpful you:http://abdulazeem.wordpress.com/2012/04/02/video-manipulation-in-ios-resizingmerging-and-overlapping-videos-in-ios/
http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
Comments
Post a Comment