如何减少通过我的iOS应用在手机上录制的视频的文件大小 [英] How to reduce the file size of a video recorded through my iOS app on a phone

查看:43
本文介绍了如何减少通过我的iOS应用在手机上录制的视频的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个iOS应用程序(即将推出Android),其中涉及用户通过该应用程序在手机上录制视频的过程.但是我需要该应用程序来减小这些视频的默认大小,以便将它们上传到我的服务器时使用更少的带宽,并且上传速度更快.最好的方法是什么?

I am making an iOS app (Android soon) that involves users recording videos on their phones through the app. But I need the app to reduce the default size of those videos so that when they are uploaded to my server less bandwidth is used and it uploads faster. What is the best way to do that?

推荐答案

尝试以下代码,希望您的任务完成.

Try this code hope your task done.

- (void)convertVideoToLowQuailty:(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:AVAssetExportPresetLowQuality];
        exportSession.outputURL = outputURL;
        exportSession.outputFileType = AVFileTypeQuickTimeMovie;
        [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
        {
            handler(exportSession);
            [exportSession release];
        }];
    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

    {   
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSURL *outputURL = [NSURL fileURLWithPath:@"/Users/Hems/Desktop/output.mov"];
        [self convertVideoToLowQuailty:videoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession)
         {
             if (exportSession.status == AVAssetExportSessionStatusCompleted)
             {
                 printf("completed\n");
             }
             else
             {
                 printf("error\n");

             }
         }];

    }

这篇关于如何减少通过我的iOS应用在手机上录制的视频的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆