13

I have an AVMutableComposition with a video track and I would like to add a still image into the video track, to be displayed for some given time. The still image is simply a PNG. I can load the image as an asset, but that’s about it, because the resulting asset does not have any tracks and therefore cannot be simply inserted using the insertTimeRange… methods.

Is there a way to add still images to a composition? It looks like the answer is somewhere in Core Animation, but the whole thing seems to be a bit above my head and I would appreciate a code sample or some information pointers.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • Did you add empty time ranges to the track where the photos come in? When setting up the instructions, do you still treat the track as if there is content there? (transitioning to and from it) – box86rowh Aug 22 '12 at 18:13
  • I didn’t go the video composition + Core Animation route in the end, I created a class to create a video from still frames and use the video. – zoul Aug 22 '12 at 18:22
  • Cool, I am working on a project where the user can mix video and photos at their discretion, so the compilation code has to be flexible. I am working the photo end into the code now. – box86rowh Aug 22 '12 at 19:03
  • can you post an example of creating a video from still frames please? thanks! – greenhouse Aug 28 '14 at 20:45
  • How to add transition effect , We created video from image and we want to add transition between each image like crossfeed,dissolve,zooming image , How we get that functionality any idea , – Jaywant Khedkar Jun 01 '16 at 11:40

2 Answers2

15

OK. There’s a great video called Editing Media with AV Foundation from WWDC that explains a lot. You can’t insert images right to the AVComposition timeline, at least I did not find any way to do that. But when exporting or playing an asset you can refer to an AVVideoComposition. That’s maybe not a perfect name for the class, since it allows you to mix between various video tracks in the asset, very much like AVAudioMix does for audio. And the AVVideoComposition has an animationTool property that lets you throw Core Animation layers (CALayer) into the mix. CALayer has a contents property that can be assigned a CGImageRef. Does not help in my case, might help somebody else.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • I am just starting with video editing. As per your answer, correct me if I am wrong, you are saying that throwing layers of images in between live video recording or after the video is recorded ? – nr5 Aug 09 '14 at 07:23
  • After the video is recorded. `AVVideoComposition` is something like a video editing tool – a kind of programmable Final Cut Pro, if you will. So you can stitch a few video segments together with some Core Animation Layers. – zoul Aug 09 '14 at 13:49
  • Yup I succeeded in inserting an image throughout the recorded video. But this is ok for editing/inserting static objects into the video. What if the I want to play with the hue and saturation and other things? and at the same time user will be seeing the result as he is recording. Something like Video Star app on app store. I think real time video processing is the answer for that but I am not sure if editing frames/camera-input of a video before the user can see it, will be a good idea. QQQuite resource intensive. Any link that you can point to for this topic? – nr5 Aug 11 '14 at 04:54
  • Sorry, I haven’t touched AVFoundation since this project several years ago. – zoul Aug 11 '14 at 06:18
  • so finally it is possible or not? image + video = video – Developer Aug 20 '14 at 07:19
  • It is. One possible option is the way described above, using `AVVideoComposition` and the `animationTool` property. – zoul Aug 20 '14 at 08:23
0

I also need still images in my composition. My line of thinking is a little different. Insert on-the-fly movies of black in place of when images should be appearing (possibly one such video would suffice). Add a dictionary reference to each such insert, linking composition time-ranges to bona-fide desired images. When the correct time range arrives in my full-time custom compositor, pull out the desired image and paint that into the output pixel buffer, ignoring the incoming black frames from the composition. I think that'd be another way of doing it.

zzyzy
  • 973
  • 6
  • 21