androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExportException: Unexpected runtime error when trimming and transforming video

PrinceVergil opened this issue · comments

Description:
I am encountering an androidx.media3.transformer.ExportException: Unexpected runtime error when attempting to trim a video and then change its resolution and frame rate using the transformer library.

Steps to Reproduce:

  1. Create a MediaItem with clipping configuration to trim the video.
  2. Use EditedMediaItem to apply video effects (changing resolution).
  3. Build a Composition with the EditedMediaItem.
  4. Initialize a Transformer with the required settings.
  5. Start the transformation process.

Code Snippet:

val clippedMediaItem = MediaItem.Builder()
    .setClippingConfiguration(
        MediaItem.ClippingConfiguration.Builder()
            .setStartPositionMs(0)
            .setEndPositionMs(10000)
            .build()).build()

val editedMediaItem = EditedMediaItem.Builder(clippedMediaItem).setEffects(Effects(
    /* audioProcessors= */ listOf(),
    /* videoEffects= */ listOf(Presentation.createForWidthAndHeight(640, 480, Presentation.LAYOUT_SCALE_TO_FIT))
))
.build()

val composition: Composition =
    Composition.Builder(EditedMediaItemSequence(editedMediaItem)).build()

val transformer = Transformer.Builder(this)
    .setEncoderFactory(DefaultEncoderFactory.Builder(this)
        .setRequestedVideoEncoderSettings(
            VideoEncoderSettings.Builder()
                .setBitrate(2_000_000)
                .build()
        ).build()
    ).build()

transformer.start(composition, videoPath.replace(".mp4","_clipped.mp4"))

Expected Behavior:
The video should be trimmed to the first 10 seconds and have its resolution changed to 640x480.

Actual Behavior:
I receive a ExportException: Unexpected runtime error.

Notes:

  • When I use only clippedMediaItem without applying any effects, the transformation works as expected.
  • I am not sure if I am missing something or doing anything wrong in the process.

Dependencies:

implementation(libs.androidx.media3.transformer)
implementation(libs.androidx.media3.effect)
implementation(libs.androidx.media3.common)

If this is the exact copy of your code, I think you are missing to setUri of your item in the clippedMediaItem:

val clippedMediaItem = MediaItem.Builder()
    .setUri(YOUR_URI) // here
    .setClippingConfiguration(
        MediaItem.ClippingConfiguration.Builder()
            .setStartPositionMs(0)
            .setEndPositionMs(10000)
            .build()).build()

Thanks @droid-girl it was silly mistake.

@calren maybe we should investigate if we can give a better error message here?

@PrinceVergil no problem. Happens to everyone

commented

will look into providing a better message for this use cases. @PrinceVergil thanks for reporting to help us make the API more robust!