• 压缩视频


    #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");
            
            
        }];
        
    }
    

      

  • 相关阅读:
    5.抽象工厂模式-abstractfactory
    java-code优化(持续更新)
    4.工厂方法模式-factoryMethod
    3.单例模式-singleton
    2.适配器模式-adapter
    1.外观模式-facade
    Hibernate(七)多对一单向关联映射
    Hibernate(六)一对一双向关联映射
    Hibernate(五)一对一单向关联映射
    Hibernate(四)基本映射
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5448984.html
Copyright © 2020-2023  润新知