caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.1k stars 260 forks source link

How to play videos with alpha channel? #1228

Closed EderV closed 1 month ago

EderV commented 2 months ago

HI,

I am trying to play videos with transparent background. I have a .webm video that has transparent background but when I play it using VLCJ the background becomes black. The video has a corretly format to be played with tranparent background because I have an Eletron app in which I am playing this video and the background is transparent.

Here is how I am using the MediaPlayer in KMM:

@Composable
fun MyVideoPlayer(
    path: String,
    modifier: Modifier,
) {
    val mediaPlayerComponent = remember { EmbeddedMediaPlayerComponent() }
    val mediaPlayer = remember { mediaPlayerComponent.mediaPlayer() }
    val factory = remember { { mediaPlayerComponent } }

    LaunchedEffect(path) {
        mediaPlayer.media().play(path)
    }
    DisposableEffect(Unit) {
        onDispose { mediaPlayer.release() }
    }
    SwingPanel(
        factory = factory,
        background = Color.Transparent,
        modifier = modifier
    )
}
fun main() = application {
    Window(
        onCloseRequest = ::exitApplication,
        title = "KMM-POC",
    ) {
        MyVideoPlayer("resvid/Tocino.webm", Modifier.fillMaxSize())
    }
}

Thanks in advice!

caprica commented 2 months ago

A year or more ago I did a lot of investigation into this.

The short version of the story is that VLC does NOT play transparent webm, so that means vlcj can't.

The one format that did work was hap-alpha, I suspect even this working was a fluke.

So if you can use hap-alpha, or transcode in real time, then this MIGHT work, but sadly, out of the box at the moment VLC does not play webm with transparency.

Even when I did have it working with hap-alpha, it was with JavaFX, I am not sure if the Canvas approach would work, I can't remember everything I tried.

Parts 1, 2, 3 from here show it working, but again, with severe constraints and not webm.

https://www.youtube.com/watch?v=DFOq_M7y6yo&list=PL6S442tu09UAU75e-yL8LWKm0_BlZQPVm&index=3