I\'m trying to use Glide to step through frames in a video file (without running into the keyframe seeking issue that Android suffers from). I can do this in Picasso by doin
You can pass in a frame time (In microseconds, see the MediaMetadataRetriever docs) to VideoBitmapDecoder. This is untested, but it should work:
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
FileDescriptorBitmapDecoder decoder = new FileDescriptorBitmapDecoder(
new VideoBitmapDecoder(frameTimeMicros),
bitmapPool,
DecodeFormat.PREFER_ARGB_8888);
Glide.with(fragment)
.load(uri)
.asBitmap()
.videoDecoder(decoder)
.into(imageView);
You'll need to pass ".override(width, height)" to make Sam Judd's method to work. Otherwise you'll get only the first frame of the video as I've tested variety of approaches for hours. Hope it saves time for someone.
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);
Thanks, this Post help me get there. Btw if you're using Glide 4.4 they change the way you get this result. To load a specific frame from a video uri.
You just need to use the object RequestOptions like this:
long interval = positionInMillis * 1000;
RequestOptions options = new RequestOptions().frame(interval);
Glide.with(context).asBitmap()
.load(videoUri)
.apply(options)
.into(viewHolder.imgPreview);
Where "positionInMillis" its a long variable from the video position that you want the image.