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:
- Create a
MediaItem
with clipping configuration to trim the video. - Use
EditedMediaItem
to apply video effects (changing resolution). - Build a
Composition
with theEditedMediaItem
. - Initialize a
Transformer
with the required settings. - 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.
@PrinceVergil no problem. Happens to everyone
will look into providing a better message for this use cases. @PrinceVergil thanks for reporting to help us make the API more robust!