zoukankan      html  css  js  c++  java
  • iOS沙盒视频缩略图及保存本地

    获取缩略图

    func thumbnailOfVideo(path : String)-> UIImage {
        do {
            let asset = AVURLAsset(url: URL(fileURLWithPath: path), options: nil)
            let imgGenerator = AVAssetImageGenerator(asset: asset)
            imgGenerator.appliesPreferredTrackTransform = true
            let cgImage =  try imgGenerator.copyCGImage(at: CMTimeMakeWithSeconds(1, 24), actualTime: nil)
            let uiImage = UIImage(cgImage: cgImage)
            return uiImage
        } catch {
            return UIImage(named: "default_figure")!
        }
    }
    

    保存到系统相册

    #import <AssetsLibrary/AssetsLibrary.h>
    - (void)saveVideoIntoAlbum {
        NSString *fileDirectory = 
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *fileArray = [fileManager contentsOfDirectoryAtPath:fileDirectory error:nil];
        NSString *filePath = [fileDirectory stringByAppendingPathComponent:[fileArray lastObject]];
        NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
        
        NSLog(@"fileUrl = %@", fileUrl);
        ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
        
        if ([assetslibrary videoAtPathIsCompatibleWithSavedPhotosAlbum:fileUrl]) {
            [assetslibrary writeVideoAtPathToSavedPhotosAlbum:fileUrl completionBlock:^(NSURL *assetURL, NSError *error) {
                NSLog(@"%@-----%@", assetURL, error);
            }];
        } else {
            
        }
    }
    
  • 相关阅读:
    视频4K技术的解读
    C语言野指针
    获取一个整数所有的质因数(C语言实现)
    乘法口诀表(C语言实现)
    完全平方数(C语言实现)
    Socket网络编程系列教程序
    求1-2/3+3/5-4/7+......49/97和(C语言实现)
    反射
    Cloneable接口和Object的clone()方法
    Comparable和Comparator的区别
  • 原文地址:https://www.cnblogs.com/horo/p/6991229.html
Copyright © 2011-2022 走看看