zoukankan      html  css  js  c++  java
  • iOS~视频编码转换

    在iOS中,摄像头录制的视频是mov格式的,虽然mov兼容mp4,但是有些需求需要用到mp4格式的视频文件。在翻边了stackoverflow之后找到了一段转换视频格式的代码。以此记录一下。

    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
    
    if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
    
    {
    
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
        NSString *exportPath = [NSString stringWithFormat:@"%@/%@.mp4",
                                [NSHomeDirectory() stringByAppendingString:@"/tmp"],
                                @"1"];
        exportSession.outputURL = [NSURL fileURLWithPath:exportPath];
        NSLog(@"%@", exportPath);
        exportSession.outputFileType = AVFileTypeMPEG4;
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
    
            switch ([exportSession status]) {
                case AVAssetExportSessionStatusFailed:
                    NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
                    break;
                case AVAssetExportSessionStatusCancelled:
                    NSLog(@"Export canceled");
                    break;
                    case AVAssetExportSessionStatusCompleted:
                    NSLog(@"转换成功");
                    break;
                default:
                    break;
            }
        }];
    }
  • 相关阅读:
    Stream概念的理解
    nodejs进程间通信
    nodejs多进程spawn execFile exec fok方法的区别
    socket这个名词的理解
    Object.defineProperty方法总结
    git中HEAD^和HEAD~区别
    http常见的9种方法
    java怎么建立JAVA工程项目?
    树莓派mjpg-stream摄像头监控
    制作OS X 10.9 Mavericks 安装U盘
  • 原文地址:https://www.cnblogs.com/kevingod/p/4930401.html
Copyright © 2011-2022 走看看