你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS編程技術 >> iOS 視頻轉碼MP4

iOS 視頻轉碼MP4

編輯:IOS編程技術

#import <AVFoundation/AVFoundation.h>

 

- (void)movToMP4:(NSString *)path completionHandler:(void(^)(NSURL * URL))finalUrl{

    

// path文件存放路徑

    AVURLAsset *avAsset = [AVURLAssetURLAssetWithURL:[NSURLfileURLWithPath:path] options:nil];

    NSArray *compatiblePresets = [AVAssetExportSessionexportPresetsCompatibleWithAsset:avAsset];

    

    if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])

        

    {

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

        NSString *exportPath = [NSStringstringWithFormat:@"%@/%@.mp4",[NSHomeDirectory() stringByAppendingString:@"/tmp"],@"1"];

        exportSession.outputURL = [NSURLfileURLWithPath:exportPath];

        NSLog(@"exportPath%@", exportPath);

        exportSession.outputFileType = AVFileTypeMPEG4;

        [exportSession exportAsynchronouslyWithCompletionHandler:^{

            

            switch ([exportSession status]) {

                caseAVAssetExportSessionStatusFailed:

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

                    break;

                caseAVAssetExportSessionStatusCancelled:

                    NSLog(@"Export canceled");

                    break;

                caseAVAssetExportSessionStatusCompleted:{                    NSLog(@"轉換成功");

                    finalUrl(exportSession.outputURL);

                }

                    break;

                default:

                    break;

            }

        }];

    }

}

隨筆隨記,以免忘記

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved