media icon indicating copy to clipboard operation
media copied to clipboard

If instances from different sequences are overlapping how are they mixed? Which one get's to be on top of the other? How to manipulate z-order?

Open AradiPatrik opened this issue 2 years ago • 4 comments

In Composition.java, there's a comment indicating that instances of MediaItem from different sequences will be mixed in the output when they overlap in time. However, based on my tests involving 5 overlapping media items with transparency, I've noticed that the z-order appears to be undefined. The stacking order of the videos seems to change randomly with each execution. Here's the relevant comment from the code:

/**
 * The {@link EditedMediaItemSequence} instances to compose.
 *
 * <p>{@link MediaItem} instances from different sequences that are overlapping in time will be
 * mixed in the output.
 */

Given this behavior, I'm seeking a way to control the z-order of these videos. Specifically, is there a method or technique to set or manipulate the z-order of MediaItem instances within EditedMediaItemSequence ore entire EditedMediaItemSequences to ensure a consistent stacking order in the output?

AradiPatrik avatar Jan 26 '24 02:01 AradiPatrik

The default implementation of our VideoCompositor is DefaultVideoCompositor. z-order should be defined by the order of the EditedMediaItemSequence inserted into the Composition's builder.

Unfortunately, we don't have a way to customize the order, other than using the order of EditedMediaItemSequences in the Composition.

The stacking order of the videos seems to change randomly with each execution.

This is surprising to me. I would expect the stacking order to be consistent in each execution. I guess you are getting this while using Transformer with a Composition with 5 overlapping mediaItems? If so, I wonder if Transformer is loading EditedMediaItemSequences in a nondeterministic order (which is a bug on our side if so)

dway123 avatar Jan 26 '24 13:01 dway123

Hi @dway123, @droid-girl,

Thank you for your insights on the issue. As per our discussion, I've created a sample project that consistently reproduces the z-order inconsistency issue we've been observing with the Composition and DefaultVideoCompositor.

Repository Link: Media3Issue Sample Project

Brief Description of the Repository: The repository contains a minimal setup that demonstrates the problem with overlapping media items in a composition. Specifically, it includes:

A Composition with 5 overlapping MediaItem instances, each with transparency. Detailed implementation showcasing the order of EditedMediaItemSequence added to the Composition's builder.

Please check out the repository, build and run and observe the results.

Looking forward to your response and any further steps you suggest.

Best regards, Patrik

ps.: Should I create an issue in the google issue tracker or is it fine to leave the description here?

AradiPatrik avatar Jan 29 '24 03:01 AradiPatrik

Thank you @AradiPatrik for the sample project. You can keep this issue here, do not need to create another on the the google issue tracker

droid-girl avatar Jan 29 '24 09:01 droid-girl

Assigning @claincly as he has more knowledge (and thoughts) about the Transformer multi-EditedMediaItemSequence AssetLoader initialization.

dway123 avatar Feb 05 '24 17:02 dway123

Closing as https://github.com/androidx/media/pull/1055 is merged.

claincly avatar May 29 '24 15:05 claincly