Convert2mp4 Code Snippet

Source: Internet
Author: User

#pragma mark-helper

-(nsurl *) Convert2mp4: (nsurl *) movurl {

nsurl *mp4url = nil;

avurlasset *avasset = [avurlasset urlassetwithurl: Movurl options:Nil ];

nsarray *compatiblepresets = [avassetexportsession exportpresetscompatiblewithasset: Avasset];

if ([Compatiblepresets containsobject:avassetexportpresethighestquality]) {

avassetexportsession *exportsession = [[avassetexportsession alloc]initwithasset: Avasset

presetname:avassetexportpresethighestquality];

Mp4url = [movurl copy];

Mp4url = [Mp4url urlbydeletingpathextension];

Mp4url = [Mp4url urlbyappendingpathextension:@ "mp4"];

Exportsession. Outputurl = mp4url;

Exportsession. shouldoptimizefornetworkuse = YES;

Exportsession. outputfiletype = AVFileTypeMPEG4;

dispatch_semaphore_t wait = dispatch_semaphore_create(0L);

[Exportsession exportasynchronouslywithcompletionhandler: ^{

Switch ([exportsession status]) {

case avassetexportsessionstatusfailed: {

NSLog(@ "failed, error:%@.") , Exportsession. error);

} break;

case avassetexportsessionstatuscancelled: {

NSLog(@ "cancelled.") );

} break;

case avassetexportsessionstatuscompleted: {

NSLog(@ "completed.") );

} break;

default: {

NSLog(@ "others.") );

} break;

}

dispatch_semaphore_signal(wait);

}];

long timeout = dispatch_semaphore_wait(Wait, dispatch_time_forever);

if (timeout) {

NSLog(@ "timeout.") );

}

if (wait) {

//dispatch_release (wait);

wait = nil;

}

}

return mp4url;

}

Convert2mp4 Code Snippet

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.