iOS视频编辑 - 是否可以使用iOS 4 AVFoundation类将两个视频文件合并(并排而不是一个接一个)? [英] iOS Video Editing - Is it possible to merge (side by side not one after other) two video files into one using iOS 4 AVFoundation classes?
问题描述
我知道您可以合并多个剪辑并通过使用AVFoundation类 - AVURLAsset,AVMutableComposition,AVMutableCompositionTrack等依次附加一个视频来创建单个视频。
I know you could merge multiple clips and create a single video by appending one after other using AVFoundation classes- AVURLAsset, AVMutableComposition, AVMutableCompositionTrack etc.
有类似的应用程序'Video-Joiner'这样做。
There are apps like 'Video-Joiner' that do that.
我想做的是并置2个视频。
What I want to do is to juxtaposition 2 videos.
我的应用创意 - SelfInterviewer请不要窃取:)
My app idea - SelfInterviewer please don't steal :)
首先我使用前置录制视频1相机站在框架左侧。然后视频2站在右边。在视频1中提出问题并在视频中2我回答。
First I record video 1 using front facing camera standing left to the frame. Then video 2 standing to the right. In video 1 ask a question and in video 2 I answer.
当我合并时,看起来好像我正在接受我自己的采访。
When I merge, it should appear like I am being interviewed by myself.
我几乎可以肯定它在iOS中不可行,只是想确认一下。
I am almost sure its not feasible in iOS, just wanted to confirm.
此外,如果不行,我会对任何服务器端解决方案感兴趣 - 上传两个视频并完成相同的操作。我认为adobe premiere可以做到。不确定他们是否有任何公共API。
Also, if it's a no go, I would be interested in any server-side solutions - Upload the two videos and accomplish the same. I think adobe premiere can do it. Not sure if they have any public API.
欣赏任何想法。
谢谢。
推荐答案
是的,可以合并2个视频:
1.在开始时间0将两个资源添加到AVMutableComposition。
2.将首选变换设置为轨道,在此示例中为缩放变换。
Yes it is possible to merge 2 videos:
1. Add both assets to an AVMutableComposition at start time 0.
2. Set the preferred Transform to the tracks, in this example scale transform.
- (void) mergeVideos{
///... after getting hold or your assets....firstAsset, secondAsset
AVMutableComposition* mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTracfirst:kCMPersistentTracfirst_Invalid];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration)
ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero error:nil];
AVMutableCompositionTrack *secondTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTracfirst:kCMPersistentTracfirst_Invalid];
[secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration)
ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero error:nil];
[secondTrack setPreferredTransform:CGAffineTransformMakeScale(0.25f,0.25f)];
//... export video here...
}
这篇关于iOS视频编辑 - 是否可以使用iOS 4 AVFoundation类将两个视频文件合并(并排而不是一个接一个)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!