Merging videos with different sizes & rates

I've got two sets of video cameras monitoring wildlife movement. Each camera set has a different naturalSize and frameDuration, but I'd like to interleave clips from each set as the animal wanders through each camera's view. I've looked at the demo apps and played around with AVMutableComposition and AVMutableVideoComposition feeding into AVAssetExportSession, but my scheme only works when all clips share the same size and frame rate. It's not clear to me what's causing the problem, so I don't know whether I need to put each camera's clips into different tracks and then ??? or what. Any clues?

Replies

Have you tried using a different clip for each track?

From the AVFoundation Programming Guide I get the impression that aspect ratio of all video tracks has to be the same.

I don't know about frame rate requirements. At any rate (no pun intended) frame rate conversion is probably not going to look great, especially if you have interlaced video clips.

Why don't you want to do this in iMovie or Final Cut?


Jan E.

| Why don't you want to do this in iMovie or Final Cut?


As a practical matter, this would probably be the best solution. But programming is more fun than clipping, dragging & dropping in iMovie.


| I get the impression that aspect ratio of all video tracks has to be the same.


Well, one of the code fragments shows the naturalSize of a composition being derived by using the MAX of the heights and widths of two input tracks. So that led me to believe I could combine different sizes.


I just can't seem to grasp the essential characteristics of the various classes, e.g. what is the real difference between an AVAssetTrack, an AVCompositionTrack, an AVVideoCompositionTrack, an AVCompositionTrackSegment, etc. I have islands of understanding, but am missing bridges between them.

An AVAssetTrack is a track of an existing asset (media file). It is immutable.

An AVCompositionTrack is a track of a new movie you are composing, for example, created with the mutableTrackCompatibleWithTrack method.

An AVCompositionTrackSegment results from adding a segment of an AVAssetTrack to an AVMutableCompositionTrack, using the insertTimeRange method.

An AVComposition can be exported with compression settings resulting in a new media file.


Hope this clarifies things a little for you.


Jan E.

You'll need to set up some CGAffineTransforms' that will translate the individual frames from one video format to the other, using an AVCompositionInstruction .. the tricky part is in determining the orientation of each video (its different according to the camera source), determining what the transform is for each of rotate/scale/translate operations that you'll need to perform for your needs (perhaps you want to do picture-in-picture?) and so on .. its not difficult once you grasp the concept of CGAffineTransforms' being applied to your video composition on a frame by frame basis, but the linear algebra required may take you back to trig in high school, and we all know how painful that can be! 🙂