AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

[AndroidX.Media3.Transformer] EditedMediaItem.Builder missing

Open tipa opened this issue 1 year ago • 12 comments

Android application type

Android for .NET (net8.0-android)

Description

I am trying to follow Googles "Getting Started" for the Media3 Transformer package to do a media file transformation, documented here.

Steps to Reproduce

In C#, this would be something like the following:

var inputMediaItem = MediaItem.FromUri(uri);
var editedMediaItem = new EditedMediaItem.Builder(inputMediaItem).SetRemoveAudio(true).Build();

The EditedMediaItem class doesn't seem to be present (not bound?), the same seems to be the case for many other classes in the same package/namespace. Maybe the class hasn't been bound (using remove-node) or has only been added in a recent version of Media3, which hasn't been bound yet.

tipa avatar Aug 15 '24 16:08 tipa

@tipa Thanks a lot for feedback

The EditedMediaItem class doesn't seem to be present (not bound?), the same seems to be the case for many other classes in the same package/namespace.

I will take a look next week. Still on vacation.

Maybe the class hasn't been bound (using remove-node) or has only been added in a recent version of Media3, which hasn't been bound yet.

Everything is on the table. In the meantime I prepared updates for Media3, which did not require too much changes (new dependency packages etc)

moljac avatar Aug 16 '24 07:08 moljac

It looks like the EditedMediaItem class did not exist in version 1.0.2, but is now present in the bound 1.1.1 version:

image

jpobst avatar Aug 21 '24 20:08 jpobst

Thanks @moljac for getting this done quickly. I was searching for the tools to add an overlay watermark+timer to video on the weekend and was pleased to come across this conversation already in progress. Good work!

I'm looking to use the Media3.Transformer plus OverlayEffect along with a BitmapOverlay to apply my overlay watermark+timer.

Comparing the 1.1.1 generated OverlayEffect class with the java source code here, there is a constructor required for the OverlayEffect class:

  1. The AndroidX.Media3.Effect.OverlayEffect class is included in the latest build but it is currently missing its constructor method (which accepts an input param of [ImmutableList]<TextureOverlay> textureOverlays);

  2. ~~The toGlShaderProgram method in the OverlayEffect class looks like it needs to call OverlayShaderProgram and not return a SingleFrameGlShaderProgram as it currently does. (Edited this out since SingleFrameGlShaderProgram has been deprecated in a later version of AndroidX/Media so should auto-resolve with a later AndroidX/Media version.)~~

If there's anything else I can provide to help, happy to oblige. Thanks.

rgb-drm avatar Aug 21 '24 23:08 rgb-drm

@jpobst the lines I posted in my first post now build with v1.1.1. However, the very next lines of the example are still not working because the setVideoMimeType method is missing

tipa avatar Aug 22 '24 16:08 tipa

It looks like setVideoMimeType was added in version 1.2.0, hence it will not be in these bindings.

jpobst avatar Aug 22 '24 17:08 jpobst

@jpobst the lines I posted in my first post now build with v1.1.1. However, the very next lines of the example are still not working because the setVideoMimeType method is missing

Keep it open until everything is fixed. Maybe add comment or two what is fixed. Just so we have track of it.

moljac avatar Aug 22 '24 18:08 moljac

It looks like setVideoMimeType was added in version 1.2.0, hence it will not be in these bindings.

It is in the update queue, but I need to test fixes for MavenNet 1st.

moljac avatar Aug 22 '24 18:08 moljac

I tested the recently released 1.2.0 and encountered new problems. First there was this compatibility problem that required me to manually reference Xamarin.AndroidX.Collection.Jvm:

Error	NU1107	Version conflict detected for Xamarin.AndroidX.Collection.Jvm. Install/reference Xamarin.AndroidX.Collection.Jvm 1.4.3 directly to project ... to resolve this issue. 
 ... -> Xamarin.AndroidX.Media3.Transformer 1.2.1 -> Xamarin.AndroidX.Media3.ExoPlayer 1.2.1 -> Xamarin.AndroidX.Collection 1.4.3 -> Xamarin.AndroidX.Collection.Jvm (>= 1.4.3) 
 ... -> Xamarin.AndroidX.Preference 1.2.1.9 -> Xamarin.AndroidX.Fragment.Ktx 1.8.2.1 -> Xamarin.AndroidX.Collection.Ktx 1.4.2.1 -> Xamarin.AndroidX.Collection.Jvm (>= 1.4.2.1 && < 1.4.3).

Then I tried again to implement the previously mentioned example in my code:

var inputMediaItem = MediaItem.FromUri(uri);
var editedMediaItem = new EditedMediaItem.Builder(inputMediaItem).SetRemoveAudio(true).Build();
Transformer transformer = new Transformer.Builder(Application.Context)
    .SetVideoMimeType(MimeTypes.VideoH265)
    .AddListener(new Listener())
    .Build();
transformer.Start(editedMediaItem, outputPath);

sealed class Listener : Java.Lang.Object, Transformer.IListener
{
    public override void OnCompleted(Composition composition, ExportResult exportResult) {    }
}

However, I could build it: Error (active) CS0115 'Listener.OnCompleted(Composition, ExportResult)': no suitable method found to override

I think the OnCompleted and OnError interface methods need to be public

tipa avatar Sep 03 '24 06:09 tipa

I am still unable to use this package with 1.3.1:

  • I am now able to implement Transformer.IListener but the interface methods should be made public (they are currently private)
  • The AndroidX.Media3.Effect.Presentation class of the bindings inhertis from Java.Lang.Object, while it should be MatrixTransformation - which in turn inherits from Effect, which is the required type for setEffects
var inputMediaItem = MediaItem.FromUri(uri);
var editedMediaItem = new EditedMediaItem.Builder(inputMediaItem)
    .SetEffects(new Effects([], [AndroidX.Media3.Effect.Presentation.CreateForHeight(480)]))
    .Build();
var transformer = new Transformer.Builder(Application.Context)
    .SetVideoMimeType(MimeTypes.VideoH265)
    .Build();
transformer.Start(editedMediaItem, outputPath2);

Cannot implicitly convert type 'AndroidX.Media3.Effect.Presentation' to 'AndroidX.Media3.Common.IEffect'

tipa avatar Sep 14 '24 10:09 tipa

Same problem with 1.4.1. And I also had to manually reference Xamarin.AndroidX.Collection.Jvm again to install the package along with Xamarin.AndroidX.Preference.

Will there be any efforts in resolving the issues I have reported over the last couple of weeks? I am still unable to use it at all.

tipa avatar Sep 24 '24 13:09 tipa

Thanks for reporting

Will there be any efforts in resolving the issues I have reported over the last couple of weeks?

Yes. For sure, but I need to see the priorities first. Probably bindings errors/problems 1st.

And I also had to manually reference Xamarin.AndroidX.Collection.Jvm again to install the package along with Xamarin.AndroidX.Preference.

This is not bindings issue but nuget transitive dependencies. We are working on solutions for that.

Thanks

moljac avatar Sep 25 '24 19:09 moljac

After fixing:

	public sealed partial class Presentation : global::Java.Lang.Object, global::AndroidX.Media3.Effect.IMatrixTransformation

	public partial interface IMatrixTransformation : global::AndroidX.Media3.Effect.IGlMatrixTransformation

	public partial interface IGlMatrixTransformation : global::AndroidX.Media3.Effect.IGlEffect

	public partial interface IGlEffect : global::AndroidX.Media3.Common.IEffect






moljac avatar Sep 30 '24 12:09 moljac

@moljac is there any chance this will get fixed at some point in this year? :) Thanks in advance!

tipa avatar Jan 14 '25 17:01 tipa

@moljac is there any chance this will get fixed at some point in this year? :) Thanks in advance!

2025? I think it might be squeezed into my schedule.

You re welcome

moljac avatar Jan 14 '25 17:01 moljac

The latest version 1.5.1.1 resolved all the build problems with the Xamarin.AndroidX.Media3.Transformer package for me - thanks a lot!

tipa avatar Jan 22 '25 23:01 tipa

OverlaySettings.Build() the .Build() isn't displaying as an option.

I found the fix: Just use StaticOverlaySettings instead if you run into the same issue as me. It seems they renamed OverlaySettings (the one from the media effect library not media common library) to static overlay settings.

emmanueltheorb avatar Dec 20 '25 09:12 emmanueltheorb