Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

ios4 - 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?

I know you could merge multiple clips and create a single video by appending one after other using AVFoundation classes- AVURLAsset, AVMutableComposition, AVMutableCompositionTrack etc.

There are apps like 'Video-Joiner' that do that.

What I want to do is to juxtaposition 2 videos.

My app idea - SelfInterviewer please don't steal :)

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.

I am almost sure its not feasible in iOS, just wanted to confirm.

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.

Appreciate any ideas.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...