uiimagepickercontroller – 具有mp4格式的IOS UIImagePicker

uiimagepickercontroller – 具有mp4格式的IOS UIImagePicker,第1张

概述是否可以保存视频并将其添加到自定义ALAsset,从MP4格式的UI ImagePicker捕获?或者我必须将它保存在.mov中并通过AVAssetExportSession进行压缩? 是的,您可以使用AVAssetExportSession压缩视频.您可以在此处指定压缩视频的视频类型,质量和输出网址. 见下面的方法: - (void) saveVideoToLocal:(NSURL *)vide 是否可以保存视频并将其添加到自定义ALAsset,从MP4格式的UI ImagePicker捕获?或者我必须将它保存在.mov中并通过AVAssetExportSession进行压缩?解决方法 是的,您可以使用AVAssetExportSession压缩视频.您可以在此处指定压缩视频的视频类型,质量和输出网址.

见下面的方法:

- (voID) saveVIDeoTolocal:(NSURL *)vIDeoURL {    @try {        NSArray *documentsDirectory = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);        Nsstring *docPath = [documentsDirectory objectAtIndex:0];        Nsstring *vIDeoname = [Nsstring stringWithFormat:@"sampleVIDeo.mp4"];        Nsstring *vIDeoPath = [docPath stringByAppendingPathComponent:vIDeoname];        NSURL *outputURL = [NSURL fileURLWithPath:vIDeoPath];        NSLog(@"Loading vIDeo");        [self convertVIDeoTolowQuailtyWithinputURL:vIDeoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession) {             if (exportSession.status == AVAssetExportSessionStatusCompleted) {                 NSLog(@"Compression is done");             }             [self performSelectorOnMainThread:@selector(doneCompressing) withObject:nil waitUntilDone:YES];         }];    }    @catch (NSException *exception) {        NSLog(@"Exception :%@",exception.description);        [self performSelectorOnMainThread:@selector(doneCompressing) withObject:nil waitUntilDone:YES];    }}//---------------------------------------------------------------- (voID)convertVIDeoTolowQuailtyWithinputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(voID (^)(AVAssetExportSession*))handler {    [[NSfileManager defaultManager] removeItemAtURL:outputURL error:nil];    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetname:AVAssetExportPresetPassthrough];    exportSession.outputURL = outputURL;    exportSession.outputfileType = AVfileTypeMPEG4;    [exportSession exportAsynchronouslyWithCompletionHandler:^(voID) {        handler(exportSession);    }];}

这里我将压缩视频保存到应用程序的文档目录中.您可以在下面的示例代码中查看详细信息:

Sample demo:

总结

以上是内存溢出为你收集整理的uiimagepickercontroller – 具有mp4格式的IOS UIImagePicker全部内容,希望文章能够帮你解决uiimagepickercontroller – 具有mp4格式的IOS UIImagePicker所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1036038.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存