Translations: 简体中文
Sketch provides the sketch-video-*
series of modules to support decoding video frames
Module | DecoderProvider | Decoder | Android | iOS | Desktop | Web |
---|---|---|---|---|---|---|
sketch-video | VideoFrameDecoderProvider | VideoFrameDecoder | ✅(API 27) | ❌ | ❌ | ❌ |
sketch-video-ffmpeg | FFmpegVideoFrameDecoderProvider | FFmpegVideoFrameDecoder | ✅ | ❌ | ❌ | ❌ |
- VideoFrameDecoder:
- Decode video frames using Android's built-in MediaMetadataRetriever class
- It is recommended to use Android 8.1 and above, because versions 8.0 and below do not support reading frame thumbnails, which will consume a lot of memory when decoding larger videos such as 4k.
- FFmpegVideoFrameDecoder:
- Decode video frames using the FFmpegMediaMetadataRetriever class of the wseemann/FFmpegMediaMetadataRetriever-project library
- Library size is approximately 23 MB
${LAST_VERSION}
: (Not included 'v')
implementation("io.github.panpf.sketch4:sketch-video:${LAST_VERSION}")
// or
implementation("io.github.panpf.sketch4:sketch-video-ffmpeg:${LAST_VERSION}")
Important
The above components all support automatic registration. You only need to import them without additional configuration. If you need to register manually, please read the documentation: 《Register component》
ImageRequest and ImageOptions support some video frame-related configurations, as follows:
ImageRequest(context, "file:///sdcard/sample.mp4") {
// Extract the frame at 1000000 microseconds
videoFrameMicros(1000000)
// or extract the frame at 10000 ms
videoFrameMillis(10000)
// or get the frames in between
videoFramePercentDuration(0.5f)
// Set the processing strategy when frames cannot be extracted at the specified time
videoFrameOption(MediaMetadataRetriever.OPTION_CLOSEST)
}