我想用UIImagePickerController
來記錄多個視頻剪輯,然後將它們拼接成一個視頻,類似於Vine應用程序。任何人都可以向我指出正確的方向,我可以如何將視頻剪輯合併到一個視頻中?拼接視頻剪輯到藤一樣的單個視頻
7
A
回答
1
Ray Wenderlich的網站有一個涵蓋這個的教程。 http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
0
下面是一個如何將視頻拼接在一起的示例,部分基於Ray Wenderlich的博客。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[appDelegate.playerLayer removeFromSuperlayer];
if (self.firstAsset)
{
self.secondAssetURL = [info objectForKey:UIImagePickerControllerMediaURL];
self.secondAsset = [AVAsset assetWithURL:self.secondAssetURL];
}
else
{
self.firstAssetURL = [info objectForKey:UIImagePickerControllerMediaURL];
self.firstAsset = [AVAsset assetWithURL:self.firstAssetURL];
}
if (self.secondAsset)
{
CMTime recordTime = CMTimeMakeWithSeconds(self.recordTime, NSEC_PER_SEC);
AVMutableComposition *mixComposition = [AVMutableComposition new];
AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.firstAsset.duration) ofTrack:[[self.firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.secondAsset.duration)
ofTrack:[[self.secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:recordTime error:nil];
AVURLAsset *firstAudioAsset = [[AVURLAsset alloc] initWithURL:self.firstAssetURL options:nil];
AVURLAsset *secondAudioAsset = [[AVURLAsset alloc] initWithURL:self.secondAssetURL options:nil];
AVAssetTrack *firstAudioTrack = [[firstAudioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVAssetTrack *secondAudioTrack = [[secondAudioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAudioAsset.duration) ofTrack:firstAudioTrack atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAudioAsset.duration) ofTrack:secondAudioTrack atTime:recordTime error:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"mergeVideo-%d.mov",arc4random() % 1000]];
NSURL *url = [NSURL fileURLWithPath:myPathDocs];
// 5 - Create exporter
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"we are now exporting");
int exportStatus = exporter.status;
switch (exportStatus) {
case AVAssetExportSessionStatusFailed: {
// log error to text view
NSError *exportError = exporter.error;
NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
break;
}
case AVAssetExportSessionStatusCompleted: {
NSLog (@"AVAssetExportSessionStatusCompleted");
self.firstAssetURL = exporter.outputURL;
self.firstAsset = [AVAsset assetWithURL:self.firstAssetURL];
dispatch_async(dispatch_get_main_queue(), ^{
[self layoutVideo:exporter.outputURL];
});
break;
}
default: { NSLog (@"didn't get export status"); break;}
}
}];
}
else
{
[self layoutVideo:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
}
}
相關問題
- 1. 拼接視頻
- 2. 音頻拼接剪輯
- 3. NReco視頻剪輯
- 4. 將2個MP4視頻拼接爲一個視頻
- 5. 添加一個Youtube視頻剪輯
- 6. FFmpeg的視頻剪輯
- 7. 視頻剪輯畫廊
- 8. 在Directshow中剪輯視頻
- 9. 拼接器視頻渲染
- 10. iOS音頻:剪切和拼接音頻?
- 11. Silverlight視頻播放虛擬視頻剪輯
- 12. 在HTML5視頻中,如何從長視頻播放小剪輯?
- 13. Flash視頻 - 創建虛擬視頻剪輯
- 14. Python視頻編輯 - 如何修剪視頻
- 15. 修剪音頻到視頻長度
- 16. 確定連續的視頻剪輯
- 17. 裁剪視頻到框架
- 18. 將兩個不同視頻的兩個剪輯合併到一個帶有javascript(客戶端)的視頻中?
- 19. 多臺攝像機的視頻拼接
- 20. 創建一個拼貼風格的視頻,與多個內部視頻
- 21. AVCaptureMovieFileOutput - 錄製順序視頻剪輯
- 22. Qt/C++多媒體播放器視頻剪輯,多個視頻小部件
- 23. 實時視頻(圖像)拼接
- 24. 使用ffmpeg從視頻捕獲的視頻創建視頻拼貼
- 25. 如何鏈接到一個視頻VIMEO
- 26. 添加一個小視頻剪輯作爲背景
- 27. uiimagepicker中的視頻裁剪
- 28. 如何使用Qt錄製或剪輯視頻文件中的視頻?
- 29. 將多個視頻無差距地拼接在一起
- 30. 編輯視頻幀