zoukankan      html  css  js  c++  java
  • 压缩视频

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

      

  • 相关阅读:
    git warning: LF will be replaced by CRLF in 解决办法
    今天买了个pro,开始ios开发
    基于pyspark的mapreduce实现
    正则表达式中全部符号作用及解释
    CNN
    tensorboard使用及tensorflow各层权重系数输出
    DeepFM tensorflow实现
    FM详解
    sklearn计算auc需要注意的点
    矩阵压缩存储(可用于FM算法中的稀疏矩阵存储)
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5448984.html
Copyright © 2011-2022 走看看