• 压缩视频


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

      

  • 相关阅读:
    转 将python的datetime转换为unix时间戳
    VMware 虚拟机中添加新硬盘的方法
    UBUNTU 安装 nodejs
    ubuntu 20 查看site-package 目录
    基于C++代码的UE4学习(四)—— 定时器
    ObjectMapper 动态用法
    关于Mybatis中Mapper是使用XML还是注解的一些思考
    Spring Boot 中使用 Jedis 及 Lettuce的对比
    批量切换版本
    Build OpenJdk
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5448984.html
Copyright © 2020-2023  润新知