ios - Monotouch, Trimming Video Fails -
i trying trim video 5 seconds programmatically. here implementation.
avassetexportsession exportsession= new avassetexportsession(videoasset,avassetexportsession.presetlowquality.tostring()); int systemversion = convert.toint16(uidevice.currentdevice.systemversion.split('.')[0]); string filename; if (systemversion >= 8) { var documents = nsfilemanager.defaultmanager.geturls(nssearchpathdirectory.documentdirectory, nssearchpathdomain.user)[0].path; filename = path.combine(documents, "trimmed.mov"); } else { var documents = environment.getfolderpath(environment.specialfolder.mydocuments); // ios 7 , earlier filename = path.combine(documents, "trimmed.mov"); } outputurl=new nsurl(filename); exportsession.outputurl = outputurl; cmtime start = new cmtime((long)1, 1); cmtime duration = new cmtime((long)5, 1); cmtimerange range = new cmtimerange(); range.start=start; range.duration=duration; exportsession.timerange = range; exportsession.outputfiletype = avfiletype.quicktimemovie; exporttrimmedvideo( exportsession); async void exporttrimmedvideo(avassetexportsession exportsession) { await exportsession.exporttaskasync (); if (exportsession.status == avassetexportsessionstatus.completed) { invokeonmainthread (() => { new uialertview ("export sucess", "video trimmed", null, "o k").show (); }); } else { invokeonmainthread (() => { new uialertview ("export falure", exportsession.error.description, null, "o k").show (); }); } }
but in completion getting filed status. full nserror
description follows
error domain=avfoundationerrordomain code=-11800 "the operation not completed" userinfo=0x7cebcf80 {nslocalizeddescription=the operation not completed, nsunderlyingerror=0x7cb08410 "the operation couldn’t completed. (osstatus error -12105.)", nslocalizedfailurereason=an unknown error occurred (-12105)}
what possibly doing wrong ?
edit: have referred apple's doumentation on trimming video , have modified above code no positive effect below.
var compatiblepresets= avassetexportsession.exportpresetscompatiblewithasset(videoasset).tolist(); var preset=""; if(compatiblepresets.contains("avassetexportpresetlowquality")) { preset="avassetexportpresetlowquality"; } else { preset=compatiblepresets.firstordefault(); } avassetexportsession exportsession= new avassetexportsession(videoasset,preset); int systemversion = convert.toint16(uidevice.currentdevice.systemversion.split('.')[0]); string filename; if (systemversion >= 8) { var documents = nsfilemanager.defaultmanager.geturls(nssearchpathdirectory.documentdirectory, nssearchpathdomain.user)[0].path; filename = path.combine(documents, "trimmed.mov"); } else { var documents = environment.getfolderpath(environment.specialfolder.mydocuments); // ios 7 , earlier filename = path.combine(documents, "trimmed.mov"); } outputurl=new nsurl(filename); exportsession.outputurl = outputurl; exportsession.outputfiletype = avfiletype.quicktimemovie; cmtime start = new cmtime((long)1, 600); cmtime duration = new cmtime((long)5, 600); cmtimerange range = new cmtimerange(); range.start=start; range.duration=duration; exportsession.timerange = range; exporttrimmedvideo( exportsession);
try code below. modified exportsession.outputurl , how initialize cmtimerange. trimming down 4 second clip?
var compatiblepresets= avassetexportsession.exportpresetscompatiblewithasset(videoasset).tolist(); var preset=""; if(compatiblepresets.contains("avassetexportpresetlowquality")) { preset="avassetexportpresetlowquality"; } else { preset=compatiblepresets.firstordefault(); } using (var exportsession = new avassetexportsession(videoasset, preset)) { int systemversion = convert.toint16(uidevice.currentdevice.systemversion.split('.')[0]); string filename; if (systemversion >= 8) { var documents = nsfilemanager.defaultmanager.geturls(nssearchpathdirectory.documentdirectory, nssearchpathdomain.user)[0].path; filename = path.combine(documents, "trimmed.mov"); } else { var documents = environment.getfolderpath(environment.specialfolder.mydocuments); // ios 7 , earlier filename = path.combine(documents, "trimmed.mov"); } exportsession.outputurl = nsurl.fromfilename(filename); exportsession.outputfiletype = avfiletype.quicktimemovie; var range = new cmtimerange(); range.start = cmtime.fromseconds (1, videoasset.duration.timescale); range.duration = cmtime.fromseconds (5, videoasset.duration.timescale); exportsession.timerange = range; } exporttrimmedvideo( exportsession);
Comments
Post a Comment