简体   繁体   中英

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.

我最终使用了在这里找到的FFmpeg android库: https : //github.com/wseemann/FFmpegMediaMetadataRetriever

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

I have the same problem.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM