Adding on to Krishna's answer, I've created a fork of alpha-movie that plays transparent videos with the alpha data included separately in each frame.
This means that you'll be able to convert transparent webm videos to normal mp4 for use with the AlphaMovieView. It produces accurate transparency as opposed to the chroma key method, allows for partial transparency and doesn't rely on you having to manually set the alpha colour. However you will need to preprocess your transparent video.
- Add the following to your project to install the package. Source here: https://github.com/nopol10/alpha-movie
// project's (top level) build.gradle
repositories {
// ...
mavenCentral()
}
// module's build.gradle
dependencies {
// ...
implementation 'io.github.nopol10:alpha-movie:1.3.4'
// ...
}
- Download ffmpeg. The most recent version is recommended. It must have libvpx.
- Run this in
ffmpeg -vcodec libvpx -i input_video.webm -vf "split [a], pad=iw*2:ih [b], [a] alphaextract, [b] overlay=w" -x264opts keyint=30 -y output_video.mp4
. Replace input_video.webm and output_video.mp4 with the desired input file and output filename.
- Place the output mp4 in your Android project's assets folder.
- Add this to your layout xml:
<com.alphamovie.lib.AlphaMovieView
android:id="@+id/video_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:packed="true"
/>
- Add this to your activity/fragment
alphaMovieView = (AlphaMovieView) findViewById(R.id.video_player);
alphaMovieView.setVideoFromAssets("output_video.mp4");
- Result:
This method is inspired by the feature in AVProVideo.