Translations: 简体中文
Sketch supports decoding video frames, powered by the following Decoder:
- VideoFrameBitmapDecoder: Use Android's built-in MediaMetadataRetriever class to decode video
frames
- You need to import the
sketch-video
module first - 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.
- You need to import the
- FFmpegVideoFrameBitmapDecoder:Use wseemann
/FFmpegMediaMetadataRetriever-project Library's FFmpegMediaMetadataRetriever class decodes
frames of video files
- You need to import the
sketch-video-ffmpeg
module first - Library size is approximately 23MB
- You need to import the
Select the appropriate Decoder according to the situation, and then register it as follows:
/* Register for all ImageRequests */
class MyApplication : Application(), SketchFactory {
override fun createSketch(): Sketch {
return Sketch.Builder(this).apply {
components {
addBitmapDecoder(FFmpegVideoFrameBitmapDecoder.Factory())
}
}.build()
}
}
/* Register for a single ImageRequest */
imageView.displayImage("file:///sdcard/sample.mp4") {
components {
addBitmapDecoder(FFmpegVideoFrameBitmapDecoder.Factory())
}
}
DisplayRequest and LoadRequest support some video frame-related configurations, as follows:
imageView.displayImage("file:///sdcard/sample.mp4") {
// Extract the frame at 1000000 microseconds
videoFrameMicros(1000000)
// or extract the frame at 10000 ms
videoFrameMillis(10000)
// or get the frame in the middle of the extraction
videoFramePercentDuration(0.5f)
// Set the processing strategy when frames cannot be extracted at the specified time
videoFrameOption(MediaMetadataRetriever.OPTION_CLOSEST)
}