码迷,mamicode.com
首页 > 其他好文 > 详细

压缩视频

时间:2016-04-30 18:21:21      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate> 

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    
    //创建图片选择控制器
    
    UIImagePickerController * pick = [[UIImagePickerController alloc]init];
    
    
    //设置数据类型
    
    pick .sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    
    //设置媒体类型
    
    pick.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    
    //设置代理
    pick.delegate = self;
    
    
    //moda 控制器
    
    [self presentViewController:pick animated:YES completion:nil];
    
    
    
    
}





- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info;{
    
//    NSLog(@"%@" , info);
    NSURL * url = info[UIImagePickerControllerMediaURL];
    
    //包装
    AVAsset * set = [AVAsset assetWithURL:url];
    
    //创建资源导出会话
    
    /*
     NSString *const AVAssetExportPresetLowQuality;
     NSString *const AVAssetExportPresetMediumQuality;
     NSString *const AVAssetExportPresetHighestQuality;
     
     */
    
    AVAssetExportSession * exportSession = [AVAssetExportSession exportSessionWithAsset:set presetName:AVAssetExportPresetHighestQuality];
    
    //设置视屏存储路径
    NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"压缩视屏.MP4"];
    
    //导出路径
    exportSession.outputURL = [NSURL fileURLWithPath:path];
    
    NSLog(@"%@" , exportSession.outputFileType);
    
    //一定要设置导出视频类型
    exportSession.outputFileType = @"public.mpeg-4";
    
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
       
        NSLog(@"finshed");
        
        
    }];
    
}

  

压缩视频

标签:

原文地址:http://www.cnblogs.com/yuwei0911/p/5448984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!