MOV to Mp4 video conversion iPhone programmatically

后端 未结 7 1569
南方客
南方客 2020-12-01 01:11

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

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

相关标签:
7条回答
  • 2020-12-01 01:41

    Use the below code

        NSURL * mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
        AVAsset *video = [AVAsset assetWithURL:mediaURL];
        AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
        exportSession.shouldOptimizeForNetworkUse = YES;
        exportSession.outputFileType = AVFileTypeMPEG4;
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
        basePath = [basePath stringByAppendingPathComponent:@"videos"];
        if (![[NSFileManager defaultManager] fileExistsAtPath:basePath])
            [[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:nil];
    
        compressedVideoUrl=nil;
        compressedVideoUrl = [NSURL fileURLWithPath:basePath];
        long CurrentTime = [[NSDate date] timeIntervalSince1970];
        NSString *strImageName = [NSString stringWithFormat:@"%ld",CurrentTime];
        compressedVideoUrl=[compressedVideoUrl URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",strImageName]];
    
        exportSession.outputURL = compressedVideoUrl;
    
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
    
            NSLog(@"done processing video!");
            NSLog(@"%@",compressedVideoUrl);
    
            if(!dataMovie)
                dataMovie = [[NSMutableData alloc] init];
            dataMovie = [NSData dataWithContentsOfURL:compressedVideoUrl];
    
        }];
    
    0 讨论(0)
提交回复
热议问题