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?

查看:24
本文介绍了iOS 视频编辑 - 是否可以使用 iOS 4 AVFoundation 类将两个视频文件合并(并排而不是一个接一个)为一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆