androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.6k stars 378 forks source link

Is possible to change video effect dynamically ? #1393

Open peterstickermaker opened 4 months ago

peterstickermaker commented 4 months ago

I have an application that allows users to select different filters/effects to be applied to a video preview before exporting. I know that we can call exoPlayer.setVideoEffects() to set the list of effects, but the method has noted that 'This method should be called before calling [prepare](https://developer.android.com/reference/kotlin/androidx/media3/common/Player#prepare()).' I tried to call exoPlayer.setVideoEffects to change the video effect dynamically, but the video preview sometimes got stuck.

The third-party library https://github.com/MasayukiSuda/GPUVideo-android that allows integration with ExoPlayer works very nicely, but I am looking for the official approach from Media3 (if any). Do you have any solution for this?

andrewlewis commented 4 months ago

Calling setVideoEffects to update the effects sounds like the right way to do this (though it may be inefficient if it needs to tear everything down and set up the pipeline again).

@claincly Please could you take a look?

peterstickermaker commented 4 months ago

Hi @andrewlewis I have a list of effects that users can choose from, allowing them to see a video preview. However, if I reset the player and then prepare it again every time a new effect is applied, it seems awkward. I would like to keep the player playing while the user applies different effects, similar to many video apps.

claincly commented 4 months ago

Hey @peterstickermaker, the intended usage is just call .setVideoEffects() when you want to change the set of effects, and you don't need to re-initialize the player. To be more concrete, you can do

ExoPlayer player = new ExoPlayer.Builder(context).build();
player.setMediaItem(...);
player.setVideoEffects(effectList1);
player.prepare();
player.play();

// Change effects
player.setVideoEffects(effectList2);
player.setVideoEffects(effectList3);
player.setVideoEffects(effectList4);
...

There's a caveat here though - the effect change won't be frame specific, i.e. there is no guarantee that the new set of effects will be applied on the immediate next frame after the user-touch-event.

peterstickermaker commented 4 months ago

Thank you @claincly When I change the effects, sometimes it takes a long time for the effects to be applied, and sometimes the video player gets stuck.

peterstickermaker commented 2 months ago

Thank you @claincly When I change the effects, sometimes it takes a long time for the effects to be applied, and sometimes the video player gets stuck.

Related to https://github.com/androidx/media/issues/1535