How to compress video using AVFoundation in iOS [closed]

纵然是瞬间 提交于 2019-12-04 14:53:19

问题


Is there are any compression technique in iPhone to compress video using AVfoundation. or any open source.

Regards, Jeeva


回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/8851335/how-to-compress-video-using-avfoundation-in-ios

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