audio - iOS Remove Particular Sound from a video -
i have application plays audio , records video+audio while sound playing. figure out way process video audio picked microphone removed resulting video.
for example, if i'm playing audioa, , recording videob audiob (from microphone), want somehow cancel out audioa resulting audiob, audiob ambient noise , not noise device speakers.
any idea if there's way this?
bonus points if can done without offline processing.
you have deal playback part. here code mix selected audio recorded video.
- (void)mixaudio:(avasset*)audioasset starttime:(cmtime)starttime withvideo:(nsurl*)inputurl affinetransform:(cgaffinetransform)affinetransform tourl:(nsurl*)outputurl outputfiletype:(nsstring*)outputfiletype withmaxduration:(cmtime)maxduration withcompletionblock:(void(^)(nserror *))completionblock { nserror * error = nil; avmutablecomposition * composition = [[avmutablecomposition alloc] init]; avmutablecompositiontrack * videotrackcomposition = [composition addmutabletrackwithmediatype:avmediatypevideo preferredtrackid:kcmpersistenttrackid_invalid]; avmutablecompositiontrack * audiotrackcomposition = [composition addmutabletrackwithmediatype:avmediatypeaudio preferredtrackid:kcmpersistenttrackid_invalid]; avurlasset * fileasset = [avurlasset urlassetwithurl:inputurl options:[nsdictionary dictionarywithobject:[nsnumber numberwithbool:yes] forkey:avurlassetpreferprecisedurationandtimingkey]]; nsarray * videotracks = [fileasset trackswithmediatype:avmediatypevideo]; cmtime duration = ((avassettrack*)[videotracks objectatindex:0]).timerange.duration; if (cmtime_compare_inline(duration, >, maxduration)) { duration = maxduration; } (avassettrack * track in [audioasset trackswithmediatype:avmediatypeaudio]) { [audiotrackcomposition inserttimerange:cmtimerangemake(starttime, duration) oftrack:track attime:kcmtimezero error:&error]; if (error != nil) { completionblock(error); return; } } (avassettrack * track in videotracks) { [videotrackcomposition inserttimerange:cmtimerangemake(kcmtimezero, duration) oftrack:track attime:kcmtimezero error:&error]; if (error != nil) { completionblock(error); return; } } videotrackcomposition.preferredtransform = affinetransform; avassetexportsession * exportsession = [[avassetexportsession alloc] initwithasset:composition presetname:avassetexportpresetpassthrough]; exportsession.outputfiletype = outputfiletype; exportsession.shouldoptimizefornetworkuse = yes; exportsession.outputurl = outputurl; [exportsession exportasynchronouslywithcompletionhandler:^ { nserror * error = nil; if (exportsession.error != nil) { nsmutabledictionary * userinfo = [nsmutabledictionary dictionarywithdictionary:exportsession.error.userinfo]; nsstring * sublocalizeddescription = [userinfo objectforkey:nslocalizeddescriptionkey]; [userinfo removeobjectforkey:nslocalizeddescriptionkey]; [userinfo setobject:@"failed mix audio , video" forkey:nslocalizeddescriptionkey]; [userinfo setobject:exportsession.outputfiletype forkey:@"outputfiletype"]; [userinfo setobject:exportsession.outputurl forkey:@"outputurl"]; [userinfo setobject:sublocalizeddescription forkey:@"causelocalizeddescription"]; [userinfo setobject:[avassetexportsession allexportpresets] forkey:@"allexportsessions"]; error = [nserror errorwithdomain:@"error" code:500 userinfo:userinfo]; } completionblock(error); }]; }
Comments
Post a Comment