media
media copied to clipboard
Support transparent video with ExoPlayer
Use case description
Android is to my knowledge the only major operating system which in 2024 still does not support video playback of transparent (alpha) video. ExoPlayer is the main recommended video player of Android.
People have been requesting this feature in the following thread since 2020:
https://github.com/google/ExoPlayer/issues/7789
We have heard nothing formally from Google or Android about why this is not supported or if there will ever be support for it or when.
Google is the primary developer for VP8 and VP9 which it seeks to make standard codecs for broad usage. Both support transparent backgrounds. VP9 was released by Google in 2013. But yet 11 years later, Android cannot in any way natively play back transparent video using these codecs.
This does not seem logical. It would be hoped that someone at Google could fix ExoPlayer so we can utilize the very transparent video codecs Google has developed for us.
Proposed solution
Please allow the TextureView mode of ExoPlayer to playback transparent video (alpha video support, eg. VP8/VP9) such that a transparent region of the video will show the view underneath as would be expected.
Alternatives considered
The only existing workaround for the lack of transparency support was proposed here: https://medium.com/go-electra/unlock-transparency-in-videos-on-android-5dc43776cc72
This individual:
- Created a custom video with a side by side view (rgb channel on one side, and alpha channel on other side in gray levels)
- Played this video using ExoPlayer
- Outputted ExoPlayer into a SurfaceTexture
- Used an OpenGL shader to merge the data of the SurfaceTexture to output rgb+a pixels
- Rendered the shader output on a TextureView
The amount of technical expertise and custom coding required to do all this is absurd considering again that Google's flagship video codecs VP8/VP9 already support transparency. No other operating system prohibits simple rendering of a transparent video.
Is it not at this point logical that ExoPlayer should support the basic VP8/VP9 transparency feature, like other operating systems do equivalently?
Thanks for any help.
Thanks for your report!
Android cannot in any way natively play back transparent video using these codecs
You are correct that playing media efficiently with ExoPlayer requires codec support from the operating system it runs on.
I'm not sure if this issue tracker is the right place to track framework codec feature development, but I keep this issue open for visibility. We as the Media3 team can't really help you with this expect by raising awareness for the issue. I actually think this is a known issue and I'm not involved into codec development and the reasoning behind this or that roadmap. However, I'll make sure the codec team is aware of this issue even though I think this is already the case.
Internal bug ref: 190802665
if it helps for context, this is also blocking cross-platform adoption for transparent video in frameworks like flutter, where the video players rely on exoplayer for android builds.
ios had support for transparent videos in 2017 and chrome added it back in 2013.
i think an important use case (at least for me) is animation videos to overlay on top of other app content.
@marcbaechinger - is there a public link for the codec-level issue? thank you for keeping this open
@jonmdev one workaround you might want to try in the meantime is using a webview since the browsers do support alpha channels
one workaround you might want to try in the meantime is using a webview since the browsers do support alpha channels
Yes that is exactly what I did, though I think it is insanely foolish that this is required. If the web view can render transparent video, why not Android directly? Doesn't add up.
It is not like Google is some poor volunteer run company with no resources.
I've asked for an update from the framework team on the internal bug. I'm afraid we don't have an efficient way to support this in media3 until the underlying limitations in the framework are removed.
one other solution for anybody looking - if your transparency is always in the same place, you can use a mask to clip the transparent parts. clearly this wouldnt work if your transparency moves throughout the duration of the video, but this ended up being a smoother solution for me than webview (i had an opaque circle with transparent background). hopefully this helps anyone else trying to solve this in the meantime. took me >1 month to think of this retrospectively obvious solution.