ios - Shorten/edit video recorded as AVCaptureMovieFileOutput with fixed time -
in app recording video using device's camera , avcapturesession
save. long story short, need able cut out first x seconds of recorded clip. not want user presented 'edit video'-view, , not "fixed" amount of time per say, @ end of day, left here cmtime
value of how have cut out beginning of clip. have been looking @ avassetwriter
etc, no luck. playback, guess [player seektotime:time];
do, need actual video time
duration shorter, cut out beginning. method, or can documentation this?
have tried avmutablecomposition? have processing time though. like:
// asset avasset *asset = [avasset assetwithurl:yoururl]; // asset tracks avassettrack *assettrackvideo = [[asset trackswithmediatype:avmediatypevideo] objectatindex:0]; avassettrack *assettrackaudio = [[asset trackswithmediatype:avmediatypeaudio] objectatindex:0]; // create composition avmutablecomposition *composition = [avmutablecomposition composition]; avmutablecompositiontrack *trackvideo = [composition addmutabletrackwithmediatype:avmediatypevideo preferredtrackid:kcmpersistenttrackid_invalid]; avmutablecompositiontrack *trackaudio = [composition addmutabletrackwithmediatype:avmediatypeaudio preferredtrackid:kcmpersistenttrackid_invalid]; // your_duration cmtimesubstruct(asset.duration, yourtime_start); [trackvideo inserttimerange:cmtimerangemake(yourtime_start, your_duration) oftrack:assettrackvideo attime:kcmtimezero error:nil]; [trackaudio inserttimerange:cmtimerangemake(yourtime_start, your_duration) oftrack:assettrackaudio attime:kcmtimezero error:nil]; // orientation change if needed nsstring* filename = [nsstring stringwithformat:@"videofilename-%d.mov",arc4random() % 1000]; nsstring* path = [nstemporarydirectory() stringbyappendingpathcomponent:filename]; nsurl *exporterurl = [nsurl fileurlwithpath:path]; // create exporter avassetexportsession *exporter = [[avassetexportsession alloc] initwithasset:composition presetname:avassetexportpresethighestquality]; exporter.outputurl = exporterurl; exporter.outputfiletype = avfiletypequicktimemovie; exporter.shouldoptimizefornetworkuse = yes; [exporter exportasynchronouslywithcompletionhandler:^{ // nslog(@"finished output composition error '%@' reason '%@'", exporter.error.localizeddescription,exporter.error.localizedfailurereason); }];
Comments
Post a Comment