How to compress video using AVFoundation in iOS [closed]

末鹿安然 提交于 2019-12-03 10:13:32
KPM

Try this :)

+ (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); 
        }
     }];
}

Here is best example provided by Apple for recording using AVFoundation

You can make settings (Dimension/ FPS/ BitRate) custom.

https://developer.apple.com/library/ios/#samplecode/RosyWriter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011110

Hope this will help you

Yes, it is called AVAssetWriter. Search around for examples, it is too complicated to give a coherent piece of working code as an answer here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!