////VIEWCONTROLLER.M//iOS video Test////Created by Apple on 15/8/19.//Copyright (c) 2015 TQH. All rights reserved.//#import "ViewController.h"#import<AVFoundation/AVFoundation.h>@interfaceViewcontroller ()@end@implementationViewcontroller//Download Video- (void) viewdidload {[Super viewdidload]; NSString*path = Nshomedirectory ();//Home DirectoryNSLog (@"nshomedirectory:%@", path); //get the path in the sandboxNsarray*storefilepath =nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES); NSString*doucumentsdirectiory = [Storefilepath objectatindex:0]; NSString*plistpath =[doucumentsdirectiory stringbyappendingpathcomponent:@"Mp4test.mp4"]; Nsfilemanager*file =[Nsfilemanager Defaultmanager]; if([file Fileexistsatpath:plistpath]) {NSLog (@"a video in the sandbox"); } Else //If the sandbox does not have{nserror*error; Nsfilemanager*filemanager =[Nsfilemanager Defaultmanager]; NSString*bundle = [[NSBundle mainbundle] Pathforresource:@"mp4test"OfType:@"mp4"]; [FileManager copyitematpath:bundle topath:plistpath Error:&ERROR]; NSLog (@"Write no%d", [FileManager copyitematpath:bundle Topath:plistpath error:&ERROR]); } nsstring*newplistpath =[doucumentsdirectiory stringbyappendingpathcomponent:@"Mp4test5.mp4"]; [Self lowquailtywithinputurl:[nsurl Fileurlwithpath:plistpath] Outputurl:[nsurl Fileurlwithpath:newplistpath] Blockhandler:^ (Avassetexportsession *session) { if(Session.status = =avassetexportsessionstatuscompleted) {NSLog (@"Compression Complete"); }Else if(Session.status = =avassetexportsessionstatusfailed) {NSLog (@"Compression failed"); } }];}#pragmaMark-Video Compression-(void) Lowquailtywithinputurl: (nsurl*) Inputurl Outputurl: (Nsurl*) Outputurl Blockhandler: (void(^) (avassetexportsession*)) handler{Avurlasset*asset =[Avurlasset Urlassetwithurl:inputurl Options:nil]; Avassetexportsession*session =[[Avassetexportsession alloc] Initwithasset:asset presetname:avassetexportpresetlowquality]; Session.outputurl=Outputurl; Session.outputfiletype=Avfiletypequicktimemovie; [Session Exportasynchronouslywithcompletionhandler:^(void) {handler (session); }];}@end
Avassetexportpresetlowquality: Low quality compression
Avf_export nsstring *const avassetexportpresetlowquality Ns_available_ios (4_0);
Avf_export nsstring *const avassetexportpresetmediumquality Ns_available_ios (4_0);
Avf_export nsstring *const avassetexportpresethighestquality Ns_available_ios (4_0);
iOS video compression