在iOS中将下载的视频转换为MOV格式

在iOS中将下载的视频转换为MOV格式,ios,objective-c,video,youtube,mov,Ios,Objective C,Video,Youtube,Mov,我正在开发一个iOS应用程序,它需要将使用YouTube API下载的视频转换为.mov格式。我已尝试将AVExportSession输出文件类型设置为.mov NSURL * mediaURL = [NSURL fileURLWithPath:outputURL]; AVAsset *video = [AVAsset assetWithURL:mediaURL]; AVAssetExportSession *exportSession = [AVAssetExportS

我正在开发一个iOS应用程序,它需要将使用YouTube API下载的视频转换为.mov格式。我已尝试将AVExportSession输出文件类型设置为.mov

    NSURL * mediaURL = [NSURL fileURLWithPath:outputURL];
    AVAsset *video = [AVAsset assetWithURL:mediaURL];
    AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPreset1920x1080];
    exportSession.shouldOptimizeForNetworkUse = YES;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
    documentsPath=[documentsPath stringByAppendingString:@"/Youtube"];
    BOOL isDir;
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentsPath isDirectory:&isDir]) {
        NSError *createDirError;
        if (![[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:&createDirError]) {
            if (createDirError) {
                NSLog(@"eror while creating dir == %@", createDirError);
            }
        }
    }
    documentsPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.mov",arc4random()%10000]];

    exportSession.outputURL = [NSURL fileURLWithPath:documentsPath];

    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        switch (exportSession.status) {
            case AVAssetExportSessionStatusCompleted:
            {
                ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:outputURL] completionBlock:^(NSURL *assetURL, NSError *error) {
                    if (error) {
                        NSLog(@"error>%@",error.description);
                    }
                    else{
                        if([[NSFileManager defaultManager] fileExistsAtPath:outputURL])
                        {
                            [[NSFileManager defaultManager]removeItemAtPath:outputURL error:nil];
                        }
                        NSLog(@"asseturl>%@",assetURL);
                        [[NSFileManager defaultManager] removeItemAtPath:outputURL error:nil];
                        [self addAssetURL:assetURL toAlbum:@"Fame" withCompletionBlock:^(NSError *error) {
                            if(error)
                            {
                                NSLog(@"Error in saving to Fame album : %@",error.description);
                                return;
                            }
                        }];
                    }
                }];
            }
                break;

            case AVAssetExportSessionStatusFailed:
                NSLog(@"Error : %@",exportSession.error.description);

            default:
                break;
        }
        NSLog(@"done processing video!");
    }];
`


此代码将视频保存到gallery,但当我使用asset library获取视频时,url中会出现mp4。

与容器格式类似。MP4基于MOV。那么你想要什么样的编码呢?谢谢你的回复。我没有对视频进行任何类型的显式编码,也不知道AVExportSession是否隐式编码。所以我不知道所使用的编码。请建议将mp4视频转换为mov格式的最佳方法。