以编程方式MOV到Mp4视频转换iPhone [英] MOV to Mp4 video conversion iPhone Programmatically

查看:218
本文介绍了以编程方式MOV到Mp4视频转换iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iPhone中为Play Station 3开发媒体服务器。

I am developing media server for Play station 3 in iPhone.

我发现PS3不支持.MOV文件所以我必须将其转换为Mp4或PS3支持的其他转码。

I came to know that PS3 doesn't support .MOV file so I have to convert it into Mp4 or something other transcode which PS3 support.

这就是我所做的但如果我设置的文件类型不同于源文件,它会崩溃。

This is what I have done but it crashes if I set different file type than its source files.

            AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];

            NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

            if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])

            {

                AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];

                exportSession.outputURL = [NSURL fileURLWithPath:videoPath];

                exportSession.outputFileType = AVFileTypeMPEG4;

                CMTime start = CMTimeMakeWithSeconds(1.0, 600);

                CMTime duration = CMTimeMakeWithSeconds(3.0, 600);

                CMTimeRange range = CMTimeRangeMake(start, duration);

                exportSession.timeRange = range;

                [exportSession exportAsynchronouslyWithCompletionHandler:^{

                    switch ([exportSession status]) {

                        case AVAssetExportSessionStatusFailed:
                            NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);

                            break;

                        case AVAssetExportSessionStatusCancelled:

                            NSLog(@"Export canceled");

                            break;

                        default:

                            break;

                    }

                    [exportSession release];

                }];

            }

如果我在这里设置AVFileTypeMPEG4然后崩溃,说无效文件类型。所以我必须将其设置为AVFileTypeQuickTimeMovie并且它提供MOV文件。

If I set AVFileTypeMPEG4 here then it crashes, saying "Invalid file type". So I have to set it to AVFileTypeQuickTimeMovie and it gives MOV file.

iOS中是否可以通过AVAssetExportSession将视频从MOV转换为Mp4 ...或者没有任何第三方图书馆?

Is it possible in iOS to convert video from MOV to Mp4 through AVAssetExportSession...OR without any Thirdparty libraryies?

推荐答案

presetName使用AVAssetExportPresetPassthrough代替AVAssetExportPresetLowQuality

presetName use "AVAssetExportPresetPassthrough" instead "AVAssetExportPresetLowQuality"

 AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];

这篇关于以编程方式MOV到Mp4视频转换iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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