+-
android – Glide – 在特定时间从视频加载单帧?
我正在尝试使用Glide逐步浏览视频文件中的帧(而不会遇到关键帧寻求 Android遭受的问题).我可以通过以下方式在毕加索做到这一点:

picasso = new Picasso.Builder(MainActivity.this).addRequestHandler(new PicassoVideoFrameRequestHandler()).build();
picasso.load("videoframe://" + Environment.getExternalStorageDirectory().toString() +
                    "/source.mp4#" + frameNumber)
                    .placeholder(drawable)
                    .memoryPolicy(MemoryPolicy.NO_CACHE)
                    .into(imageView);

(frameNumber只是一个int,每次增加50000微秒).我也有像这样的PicassoVideoFrameRequestHandler:

public class PicassoVideoFrameRequestHandler extends RequestHandler {
public static final String SCHEME = "videoframe";

@Override public boolean canHandleRequest(Request data) {
    return SCHEME.equals(data.uri.getScheme());
}

@Override
public Result load(Request data, int networkPolicy) throws IOException {
    FFmpegMediaMetadataRetriever mediaMetadataRetriever = new FFmpegMediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(data.uri.getPath());
    String offsetString = data.uri.getFragment();
    long offset = Long.parseLong(offsetString);
    Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(offset, FFmpegMediaMetadataRetriever.OPTION_CLOSEST);
    return new Result(bitmap, Picasso.LoadedFrom.DISK);
}

}

我想改用Glide,因为它可以更好地处理内存.有没有办法在Glide中使用此功能?

或者,实际上,从视频中创建一组帧的任何其他方式,我可以单步执行!

谢谢!

最佳答案
你需要通过“.override(width,height)”来让Sam Judd的方法起作用.否则你只会得到视频的第一帧,因为我已经测试了几个小时的各种方法.希望它为某人节省时间.

BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool();
int microSecond = 6000000;// 6th second as an example
VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond);
FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888);
Glide.with(getApplicationContext())
    .load(yourUri)
    .asBitmap()
    .override(50,50)// Example
    .videoDecoder(fileDescriptorBitmapDecoder)
    .into(yourImageView);
点击查看更多相关文章

转载注明原文:android – Glide – 在特定时间从视频加载单帧? - 乐贴网