Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 2.65 KB

video_frame.md

File metadata and controls

74 lines (52 loc) · 2.65 KB

Video Frame

Sketch 支持解码视频帧,由以下 Decoder 提供支持:

注册

根据情况选择合适的 Decoder,然后在初始化 Sketch 时通过 components() 方法注册,这样所有的 ImageRequest 都可以使用,如下:

class MyApplication : Application(), SketchFactory {

    override fun createSketch(): Sketch {
        return Sketch.Builder(this).apply {
          components {
            addBitmapDecoder(FFmpegVideoFrameBitmapDecoder.Factory())
          }
        }.build()
    }
}

或者在显示图片时只给当前 ImageRequest 注册,这样就只有当前 ImageRequest 可以使用,如下:

imageView.displayImage("file:///sdcard/sample.mp4") {
    components {
        addBitmapDecoder(FFmpegVideoFrameBitmapDecoder.Factory())
    }
}

配置

DisplayRequestLoadRequest 支持一些视频帧相关的配置,如下:

imageView.displayImage("file:///sdcard/sample.mp4") {
    // 提取 1000000 微秒处的帧
    videoFrameMicros(1000000)

    // 或 提取 10000 毫秒处的帧
    videoFrameMillis(10000)

    // 或 获取提取中间的帧
    videoFramePercentDuration(0.5f)

    // 设置指定时间处无法提取帧时的处理策略
    videoFrameOption(MediaMetadataRetriever.OPTION_CLOSEST)
}