#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的更多相关文章

  1. 使用 Code Snippet 简化 Coding

    在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提 ...

  2. Visual Studio 如何使用代码片段Code Snippet提高编程速度!!!

      使用Code Snippet简化Coding 在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符 ...

  3. 如何创建 Code Snippet

    比如有一行自定义代码段: @property (nonatomic,copy) NSString *<#string#>; 需要添加到 Code Snippet 上,以帮助开发人员开发更便 ...

  4. 善用VS中的Code Snippet来提高开发效率

    http://www.cnblogs.com/anderslly/archive/2009/02/16/vs2008-code-snippets.html http://www.cnblogs.com ...

  5. 介绍 .Net工具Code Snippet 与 Sql Server2008工具SSMS Tools Pack

    不久前,某某在微软写了一个很酷的工具:Visual Stuido2008可视化代码片断工具,这个工具可以在http://www.codeplex.com/SnippetDesigner上免费下载,用它 ...

  6. Code Snippet

    Code Snippet: http://msdn.microsoft.com/en-us/library/z41h7fat.aspx CodePlex.Snippets 4.0 - Visual S ...

  7. iOS 学习笔记 七 (2015.03.29)code snippet操作

    1.code snippet 备份路径:~/Library/Developer/Xcode/UserData/CodeSnippets/

  8. 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏

    前言  在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建项目时省却不少重复性的工作,从而提高开发效率.在创建好了项目和文件后,就得开始具体的编码了,这时又有了新的重复性工作,就是 ...

  9. Code Snippet Library

    你可以将自己常用的代码放到里面,给它命名,设置快捷键,以后想用这段代码的时候只要按快捷键,就会出现提示,直接将这段代码显示出来,十分高效. 比如我经常会用到一个动画:[UIView beginAnim ...

随机推荐

  1. Android Netty框架的使用

    Netty框架的使用 1 TCP开发范例 发送地址---192.168.31.241 发送端口号---9223 发送数据 { "userid":"mm910@mbk.co ...

  2. JavaScript变量——栈内存or堆内存

    原文  http://blog.csdn.net/xdd19910505/article/details/41900693 堆和栈这两个字我们已经接触多很多次,那么具体是什么存在栈中什么存在堆中呢?就 ...

  3. 使用DBMS_STATS来收集统计信息【转】

    overview Oracle's cost-based optimizer (COB) uses statistics to calculate the selectivity (the fract ...

  4. 解决SQL命令行回退的问题

    场景 在linux或者aix上安装后Oracle后,在SQL命令行下无法通过键盘的退格键回退,如下 解决方法 安装软件 # rpm -ivh rlwrap-0.41-1.el6.x86_64.rpm ...

  5. SqlServer扩展存储过程

    1. 扩展存储过程xp_cmdshell用法: --1.启用 SP_CONFIGURE RECONFIGURE GO SP_CONFIGURE RECONFIGURE GO --2.用法 master ...

  6. easyui-datebox 和easyui-datetimebox 设置默认时间当前时间

    //显示当前日期 formatterDate = function (date) { var day = date.getDate() > 9 ? date.getDate() : " ...

  7. 项目二:使用机器学习(SVM)进行基因预测

    SVM软件包 LIBSVM -- A Library for Support Vector Machines(本项目所用到的SVM包)(目前最新版:libsvm-3.21,2016年7月8日) C-S ...

  8. 美国半个互联网瘫痪对开发者使用DNS的启发

    版权声明:本文由腾讯云DNSPod团队原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/174 来源:腾云阁 https:// ...

  9. 使用TCP/IP的套接字(Socket)进行通信

    http://www.cnblogs.com/mengdd/archive/2013/03/10/2952616.html 使用TCP/IP的套接字(Socket)进行通信 套接字Socket的引入 ...

  10. 弹出框--self

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...