media icon indicating copy to clipboard operation
media copied to clipboard

Is possible to change video effect dynamically ?

Open peterstickermaker opened this issue 1 year ago • 4 comments

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.' 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?

peterstickermaker avatar May 24 '24 03:05 peterstickermaker

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?

andrewlewis avatar May 24 '24 17:05 andrewlewis

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.

peterstickermaker avatar May 27 '24 06:05 peterstickermaker

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.

claincly avatar May 28 '24 19:05 claincly

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 avatar May 30 '24 02:05 peterstickermaker

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

peterstickermaker avatar Jul 11 '24 01:07 peterstickermaker

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 May I ask if this issue has been resolved?

chenru1106 avatar Dec 09 '24 10:12 chenru1106

Hmm do you still see the video player being stuck? If possible could you open a separate bug and attach your set up so we could reproduce?

claincly avatar Dec 09 '24 10:12 claincly

Hello, did anyone find a fix for this issue, by chance? It still gets stuck if you do something like this:

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

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

valentinbrad-wolfpack avatar Feb 18 '25 07:02 valentinbrad-wolfpack

Hi @valentinbrad-wolfpack , what media3 version are you testing with and what kind of effects?

droid-girl avatar Feb 18 '25 10:02 droid-girl

Same problem. I face. The effect doesn't shows up in the preview and we need to reinitialize the player to see to see the applied preview.

Although if we use:

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

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

for now as mentioned. We see this issue #2505

ranjitsingha avatar Jun 06 '25 03:06 ranjitsingha

@ranjitsingha Let's continue the discussion in #2505.

claincly avatar Jun 06 '25 10:06 claincly