Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在iPhone上剪切视频_Ios_Video - Fatal编程技术网

Ios 在iPhone上剪切视频

Ios 在iPhone上剪切视频,ios,video,Ios,Video,我有一个来自设备摄像头的视频文件——例如,存储为/private/var/mobile/Media/DCIM/100APPLE/IMG_0203.MOV,我需要剪切此视频的前10秒。我可以使用什么API或库?我找到了标准API的解决方案:AVAssetExportSession - (void)getTrimmedVideoForFile:(NSString *)filePath withInfo:(NSArray *)info { //[[NSFileManager defaultManage

我有一个来自设备摄像头的视频文件——例如,存储为/private/var/mobile/Media/DCIM/100APPLE/IMG_0203.MOV,我需要剪切此视频的前10秒。我可以使用什么API或库?

我找到了标准API的解决方案:
AVAssetExportSession

- (void)getTrimmedVideoForFile:(NSString *)filePath withInfo:(NSArray *)info
{
//[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:filePath] options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];

// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
// NSString *outputURL = paths[0];
NSFileManager *manager = [NSFileManager defaultManager];
// [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
// outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
NSString *outputURL = [NSString stringWithFormat:@"/tmp/%@.mp4", [info objectAtIndex:2]];
NSLog(@"OUTPUT: %@", outputURL);
// Remove Existing File
// [manager removeItemAtPath:outputURL error:nil];

if (![manager fileExistsAtPath:outputURL]) {
    exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
    exportSession.shouldOptimizeForNetworkUse = YES;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    CMTime start = kCMTimeZero;
    CMTime duration = kCMTimeIndefinite;
    if ([[NSString stringWithFormat:@"%@", [info objectAtIndex:3]] floatValue] > 20.0) {
        start = CMTimeMakeWithSeconds(1.0, 600);
        duration = CMTimeMakeWithSeconds(10.0, 600);
    }

    CMTimeRange range = CMTimeRangeMake(start, duration);
    exportSession.timeRange = range;
    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
        switch (exportSession.status) {
            case AVAssetExportSessionStatusCompleted:
                NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
                [self sendVideoPreview:info];
                break;
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Failed:%@",exportSession.error);
                // [self addToDelayed:info withAction:@"add"];
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Canceled:%@",exportSession.error);
                // [self addToDelayed:info withAction:@"add"];
                break;
            default:
                break;
        }
    }];
} else {
    [self sendVideoPreview:info];
}

我不确定这是否是越狱相关的问题。你在信息传送中使用了什么pss,这种方法叫什么