Ios 缩短/编辑录制为固定时间的AVCaptureMovieFileOutput的视频

Ios 缩短/编辑录制为固定时间的AVCaptureMovieFileOutput的视频,ios,cocoa-touch,avfoundation,avcapturesession,video-editing,Ios,Cocoa Touch,Avfoundation,Avcapturesession,Video Editing,在我的应用程序中,我正在使用设备的摄像头录制视频并AVCaptureSession保存。长话短说,我需要能够剪掉这个录制剪辑的第一个x秒。我不想让用户看到“编辑视频”视图,而且这不是一个“固定”的时间量,但在一天结束时,我在这里留下了一个CMTime,它的值正好是我必须从剪辑的开始处剪切多少。我一直在看AVAssetWriter等,但运气不好。对于播放,我猜[player seekToTime:time]可以,但我需要实际的视频时间持续时间更短,从一开始就剪掉。什么方法,或者在哪里可以获取此文档

在我的应用程序中,我正在使用设备的摄像头录制视频并
AVCaptureSession
保存。长话短说,我需要能够剪掉这个录制剪辑的第一个x秒。我不想让用户看到“编辑视频”视图,而且这不是一个“固定”的时间量,但在一天结束时,我在这里留下了一个
CMTime
,它的值正好是我必须从剪辑的开始处剪切多少。我一直在看
AVAssetWriter
等,但运气不好。对于播放,我猜
[player seekToTime:time]可以,但我需要实际的视频
时间
持续时间更短,从一开始就剪掉。什么方法,或者在哪里可以获取此文档?

您尝试过AVMutableComposition吗?但它将有处理时间。比如:

// get your asset
AVAsset *asset = [AVAsset assetWithURL:yourURL];

// get asset tracks
AVAssetTrack *assetTrackVideo = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

AVAssetTrack *assetTrackAudio = [[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];

// create composition
AVMutableComposition *composition = [AVMutableComposition composition];

AVMutableCompositionTrack *trackVideo = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

AVMutableCompositionTrack *trackAudio = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

// YOUR_DURATION is something like CMTimeSubstruct(asset.duration, YOURTIME_START);
[trackVideo insertTimeRange:CMTimeRangeMake(YOURTIME_START, YOUR_DURATION)
                    ofTrack:assetTrackVideo
                     atTime:kCMTimeZero
                      error:nil];

[trackAudio insertTimeRange:CMTimeRangeMake(YOURTIME_START, YOUR_DURATION)
                    ofTrack:assetTrackAudio
                     atTime:kCMTimeZero
                      error:nil];

// do the orientation change if needed

NSString* filename = [NSString stringWithFormat:@"videoFileName-%d.mov",arc4random() % 1000];
NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];

NSURL *exporterURL = [NSURL fileURLWithPath:path];

// Create exporter
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL = exporterURL;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;

[exporter exportAsynchronouslyWithCompletionHandler:^{

        // NSLog(@"Finished Output composition with error '%@' reason '%@'",   exporter.error.localizedDescription,exporter.error.localizedFailureReason);
    }];

谢谢不过,不需要所有的曲目等,只需要资产和AVAssetExportSession,它有一个变量
时间范围
,我可以轻松输入开始和停止位置。