coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.69k stars 648 forks source link

[coil-video] Getting frame fails for certain mp4 videos #2337

Closed Yentis closed 3 months ago

Yentis commented 3 months ago

Describe the bug When attempting to get a video frame for specific mp4 files (in this case a screen recording on my phone), the process fails and I see this message in logcat: getFrameAtTime: videoFrame is a NULL pointer.

In standard Android this is fixable by using FFmpegMediaMetadataRetriever but this option isn't present for coil-video.

To Reproduce

val videoLoader = ImageLoader.Builder(context)
    .components { add(VideoFrameDecoder.Factory()) }
    .build()

val request = ImageRequest.Builder(context)
    .data(filePath)
    .videoFramePercent(0.5)
    .build()

val result = videoLoader.execute(request)
val bitmap = result.drawable?.toBitmapOrNull()
// Bitmap is null

Version 2.6.0

Sample video that fails to read frames

https://github.com/coil-kt/coil/assets/158149375/0d01ea98-f91a-46df-97cd-b73715288789

colinrtwhite commented 3 months ago

Does this video fail to load using MediaMetadataRetriever directly? If so there's not much we can do unfortunately as the issue is in the underlying decoder. I'd prefer to avoid supporting custom video decoders like FFmpegMediaMetadataRetriever as it adds maintenance burden. FFmpegMediaMetadataRetriever itself also imports large native libraries. If you'd like to use it you can add a custom Fetcher/Decoder that implements support.

Yentis commented 3 months ago

Yes, it fails with MediaMetadataRetriever as well

colinrtwhite commented 3 months ago

Unfortunately there's not much we can do to fix this in Coil. You could report the issue to AOSP or modify the existing VideoFrameDecoder to use FFmpegMediaMetadataRetriever and add it to your ComponentRegistry.