如何在iOS中使用AVFoundation压缩视频

Shi*_*sad 0 cocoa-touch avfoundation ios

iPhone中是否有任何压缩技术可以使用AVfoundation压缩视频.或任何开源.

此致,Jeeva

KPM*_*KPM 7

试试这个 :)

+ (void)convertVideoToLowQualityWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL successHandler:(void (^)())successHandler failureHandler:(void (^)(NSError *))failureHandler
{
    if([[NSFileManager defaultManager] fileExistsAtURL:outputURL]) [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
    exportSession.outputURL = outputURL;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    [exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
        if (exportSession.status == AVAssetExportSessionStatusCompleted)
        {
            successHandler();
        }
        else
        {
            NSError *error = [NSError errorWithDomain:domain code:code userInfo:userInfo]; 
            failureHandler(error); 
        }
     }];
}
Run Code Online (Sandbox Code Playgroud)