Anyone know what kind of video can support a transparent background?

I just learned that MP4 files don't support alpha channel / transparent backgrounds. I'd like to play a logo animation over a UIView.


Has anyone successfully done this, and/or can point me in a direction? Thank you.

Answered by QuinceyMorris in 116446022

MP4 is a container format, not an encoding format. What encoding are you looking to use?


The last time I tried, H.264 video with transparency played back just fine, but AVFoundation was unable to encode *into* H.264 with transparency. So I could play an existing track with transparency, but not create a new one via AVFoundation. Whether or not this has changed since I tried, I don't know.


However, playing back transparent video is awkard because the default background is black, which kind of defeats the purpose. What I had to do was to create a AVMutableVideoComposition using "instructions" to grab the video track out of an asset, and explicitly specify that the AVMutableVideoCompositionInstruction backgroundColor should be clear, rather than the default of black.


Again, this was a while ago. This might be easier to achieve now.

ProRes 4444

Interesting, thanks -- I've never heard of that format. This looks to be some special format for Final Cut Pro. Are you thinking it can be exported into something like a Quicktime file that could be played in iOS?

Accepted Answer

MP4 is a container format, not an encoding format. What encoding are you looking to use?


The last time I tried, H.264 video with transparency played back just fine, but AVFoundation was unable to encode *into* H.264 with transparency. So I could play an existing track with transparency, but not create a new one via AVFoundation. Whether or not this has changed since I tried, I don't know.


However, playing back transparent video is awkard because the default background is black, which kind of defeats the purpose. What I had to do was to create a AVMutableVideoComposition using "instructions" to grab the video track out of an asset, and explicitly specify that the AVMutableVideoCompositionInstruction backgroundColor should be clear, rather than the default of black.


Again, this was a while ago. This might be easier to achieve now.

Ah OK, that helps me understand more, thanks. Video's not my area, as you can tell. 🙂


Encoding format isn't really important as much, as long as I can play back and the quality is decent. It's a small and short video clip of a pre-canned logo animation that a client's video person made. I've been trying to ask him to make the background transparent so I can place it on top of an existing view in the app, but have been unsure what to specifically request.


If H.264 works, that could be an option. Maybe I could throw it in a webview and play it that way. I guess not a lot of people do this, I've been surprised how little I can find specifically to using transparent video in iOS apps.


Thanks for the tips guys, I'll see if this info helps their video person produce a file I can use. I guess if I have to key out the background programatically, that's a possible solution.

Any news on that front?

Anyone know what kind of video can support a transparent background?
 
 
Q