ios - AVAssetExportSession with modified resolution settings -


avassetexportsession takes preset 1 of initialization parameters:

avassetexportsession(asset: avasset, presetname: string) 

where presets settings avassetexportpreset640x480 or avassetexportpreset1920x1080. if want encode using custom resolution (say 250x400), there way , if how?

these export options defined , not able allow encode using custom resolution. alternatively, can try approach

func exportvideo(asset:avasset, renderedwidth: cgfloat, renderedheight: cgfloat, exportcompletionhandler: (() -> void)?) {         let videotrack: avassettrack = asset.trackswithmediatype(avmediatypevideo)[0]          let videocomposition = avmutablevideocomposition()         videocomposition.frameduration = cmtimemake(1, 30)         videocomposition.rendersize = cgsizemake(renderedwidth, renderedheight)          let instruction: avmutablevideocompositioninstruction = avmutablevideocompositioninstruction.init()         instruction.timerange = cmtimerangemake(kcmtimezero, cmtimemakewithseconds(60, 30))          let transformer: avmutablevideocompositionlayerinstruction = avmutablevideocompositionlayerinstruction(assettrack: videotrack);         //apply transformer if needed         //          instruction.layerinstructions = [transformer]         videocomposition.instructions = [instruction]          //create export path         let exportpath: nsurl = nsurl(fileurlwithpath: "export_path_here")         //          let exporter = avassetexportsession(asset: asset, presetname: avassetexportpresethighestquality)         exporter?.videocomposition = videocomposition         exporter?.outputurl = exportpath         exporter?.outputfiletype = avfiletypequicktimemovie          exporter?.exportasynchronouslywithcompletionhandler({ () -> void in             //do sth when finished             if let handler = exportcompletionhandler {                 handler()             }         })     } 

i hope helpful.

reference: https://www.one-dreamer.com/cropping-video-square-like-vine-instagram-xcode/


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -