iphone - How to crop the video? -
i want crop video @ particular portion.given height,width,x , y ,i want crop particular region on video.does have idea.
i have done lot of research didn't find fruitful.i tried cropping using gpuimage cropfilter taking time.
i want perform operation quick possible,please suggest me technique or example how it. in advance
you can use avmutablecomposition
, avassetexportsession
available in avfoundation framework
for more detail visit apple's reference library avmutablecomposition class reference , avassetexportsession class reference
avasset* asset = // create asset source video url avmutablecomposition *videocomposition = [avmutablecomposition composition]; avmutablecompositiontrack *compositionvideotrack = [videocomposition addmutabletrackwithmediatype:avmediatypevideo preferredtrackid:kcmpersistenttrackid_invalid]; avassettrack *clipvideotrack = [[asset trackswithmediatype:avmediatypevideo] objectatindex:0]; avmutablevideocomposition* videocomposition = [[avmutablevideocomposition videocomposition]retain]; videocomposition.rendersize = cgsizemake(320, 240); videocomposition.frameduration = cmtimemake(1, 30); avmutablevideocompositioninstruction *instruction = [avmutablevideocompositioninstruction videocompositioninstruction]; instruction.timerange = cmtimerangemake(kcmtimezero, cmtimemakewithseconds(60, 30) ); avmutablevideocompositionlayerinstruction* transformer = [avmutablevideocompositionlayerinstruction videocompositionlayerinstructionwithassettrack:clipvideotrack]; cgaffinetransform finaltransform = // setup transform grows video, causing crop [transformer settransform:finaltransform attime:kcmtimezero]; instruction.layerinstructions = [nsarray arraywithobject:transformer]; videocomposition.instructions = [nsarray arraywithobject: instruction]; cgsize videosize = myvideocomposition.rendersize; calayer *parentlayer = [calayer layer]; calayer *videolayer = [calayer layer]; nslog(@"%f %f",_playerlayer.frame.origin.x,_playerlayer.frame.size.width); parentlayer.frame = cgrectmake( 0, 0 , cropsize.x , cropsize.y ); [videolayer setposition:cgpointmake(videolayer.position.x, videosize.height)]; [parentlayer addsublayer:videolayer]; videocomposition.animationtool = [avvideocompositioncoreanimationtool videocompositioncoreanimationtoolwithpostprocessingasvideolayer:videolayer inlayer:parentlayer]; exporter = [[avassetexportsession alloc] initwithasset:savecomposition presetname:avassetexportpresethighestquality] ; exporter.videocomposition = videocomposition; exporter.outputurl=url3; exporter.outputfiletype=avfiletypequicktimemovie; [exporter exportasynchronouslywithcompletionhandler:^(void){}];
Comments
Post a Comment