hermt2
hermt2

Reputation: 874

Get exact frame from a video in Android

So I have an app where users can take videos, and I want to grab specific frames from the file. When I use the method MediaMetaDataRetriever.getFrameAtTime(), it can only extract one frame for every second, but I want to grab frames between the seconds as well. I also tried to implement Jcodec into my project to grab the right frames:

FrameGrab.getFrame(new File(videoFileToRetreive.getVideoFile()), currentFrame);,

However, no matter what number I put into currentFrame, the image is always returns the first frame of the video. Is there any way to perform something like this without the use of ffmpeg? If anyone knows an answer it'd be greatly appreciated.

Upvotes: 0

Views: 4937

Answers (4)

kamran liaqat
kamran liaqat

Reputation: 1

you can use the same library media metadata **retriver.MediaMetaDataRetriever.getFrameAtTime(OPTION_CLOSEST)**. you need to use OPTION_CLOSEST rather than OPTION_CLOSEST_SYNC.OPTION_CLOSEST_SYNC is faster than OPTION_CLOSEST but it replaces every first frame with 30 frames in a second. OPTION_CLOSEST is slow as compared to OPTION_CLOSEST_SYNC but it works fine.

Upvotes: 0

Jeff
Jeff

Reputation: 23

I have the same problem.

MediaMetaDataRetriever.getFrameAtTime() works as you want in API 27.

Upvotes: 0

hermt2
hermt2

Reputation: 874

I ended up using an FFmpeg android library found here: https://github.com/wseemann/FFmpegMediaMetadataRetriever

Upvotes: 1

Nick Cardoso
Nick Cardoso

Reputation: 21783

Presumably if you are using MediaMetaDataRetriever you are also using MediaPlayer from the same framework.

If this is the case, MediaPlayer provides the method seekTo(millis)

Unfortunately seekTo moves the track to a timestamp rather than a Frame, but you should be able to work out the correct position to move to if you know the frame rate.

Also: when looking at getFrameAtTime the parameter it takes is 'uSecs' which I take to be microseconds - this means that the method can return far more than one frame per second - the problem you are seeing may be because if there is no frame at that exact microsecond, it takes a nearby frame

This means is that if your video has 30fps, there will be a frame every 33.333 uSecs, so make sure to use intervals near that size when calling getFrameAtTime

Upvotes: 0

Related Questions