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?
Asked Answered
P

2

11

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.

Pushover answered 22/4, 2011 at 16:11 Comment(2)
did u find a solution for this ??Luteous
HI @Krishnan, How are you... I need your help, seriously... I'm stuck with somehow same Question... I have to show the video side by side after merging... Both Videos are showing BUT not showing properly like side by side...Illuse
D
11

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

}
Dildo answered 26/4, 2011 at 11:23 Comment(7)
thanks, I will try it out. Unfortunately, I cannot vote on the answer as I am new to SO.Pushover
But, addMutableTrackWithMediaType: preferredTracfirst: API does not exists. Only the API addMutableTrackWithMediaType:preferredTrackID: exists. I tried with the API addMutableTrackWithMediaType:preferredTrackID itself and I am getting only the first video in the exported video.Peon
Sorry for late reply. YOu should use one MutableComposition tract instead of two.Mulberry
[secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration) ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; I m getting warning for the this and this is the warning - "Instance method '-setPreferredTransform:' not found (return type defaults to 'id')" - Any Idea why this is happening.Shufu
i'm getting only the first video in the exported video but the duration is right. my MutableComposition is allocated once as stated. please help.Speedway
@Luteous I have no idea, I can't get it to work.. I only see one of the video-tracks. Depending on which track was added first. If I add the second one first, even with the transform, it still shows as full-screen, and the other track is now not to be seen.. Did you find a way?Hukill
yes , check my link below , i used that to make a video on videoLuteous
L
2

i found this link when im trying to do the same thing , But for me its not side by side , its video top of another video, You can do the same thing by this link

Video Manipulation

Luteous answered 15/1, 2014 at 7:12 Comment(7)
@Torongo are u sure , it woks , just in case abdulazeem.wordpress.com/2012/04/02/…Luteous
Hi @Torongo ... I need your help in this Tutorial... Although the above link is a great tutorial... But how can I show video side by side, same like a Karaoke App Or you can say that same like Duet Video... I will really appreciate your Guidance... ThanksIlluse
Hi @Mr.G, How are you... I need your help in this Tutorial... Although the above link is a great tutorial... But how can I show video side by side, same like a Karaoke App Or you can say that same like Duet Video... I will really appreciate your Guidance... ThanksIlluse
@Mr.Ahtazaz I did this in 4 years back , but i dont think its hard to do , i think u need to adjust the video view frameLuteous
@Luteous How i can repeat one video until large video play?Redress
@Luteous how? can you explain please.Redress
what do u have to do is to keep the play continues bind two video samples together and play . what do u mean by until large video play ?Luteous

© 2022 - 2024 — McMap. All rights reserved.