iOS video compression

Source: Internet
Author: User

////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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.