Copy consecutive frames from video
I am trying to copy part of a video and save it as a GIF to disk. The video can be local or remote, and the copy should be no more than 2 seconds. I don't need to save every frame, but every other frame (12-15fps). I have a "frames to gif" part, but the "get the frames" part is small.
Here's what I've tried so far:
- MediaMetadataRetriever
: too slow (~ 1s per frame on Nexus4) and only works with local files
- FFmpegMediaMetadataRetriever
: same latency, but works with remote video
- TextureView.getBitmap()
: I use ScheduledExecutorService
and every 60ms, grab Bitmap
(in playing time ...) It works well with small size getBitmap(100, 100)
, but for larger ones (> 400), the whole process becomes very slow. And, as they say in the document Do not invoke this method from a drawing method
.
It seems like the best solution would be to access every frame while decoding and store them. I tried OpenCV for Android , but couldn't find an API to capture a frame at a specific time.
Now I go through those samples to figure out how to use MediaCodec
, but while working ExtractMpegFramesTest.java
I can It seems that you are fetching some frame ("no exit from decoder").
Am I on the right track? Any other suggestion?
edit: moved on with ExtractMpegFramesTest.java
, thanks for the post.
edit 2: just to clarify what I'm trying to achieve here is to play the video and click a button to start capturing frames.
source to share
No one has answered this question yet
See similar questions:
or similar: