I'm trying to copy a part of a video, and save it as a GIF into the disk. The video can be local or remote, and the copy should be 2s max. I don't need to save every single frame, but every other frame (12-15 fps). I have the "frames to gif" part working, but the "get the frames" part is not great.
Here is what I tried so far:
- MediaMetadataRetriever
: too slow (~1s per frame on a Nexus4), and only works with local files
- FFmpegMediaMetadataRetriever
: same latency, but works with remote video
- TextureView.getBitmap()
: I'm using a ScheduledExecutorService
and every 60ms, grab the Bitmap
(while playing...) It works well with small size getBitmap(100, 100)
, but for bigger ones (> 400), the whole process becomes really slow. And as the doc says Do not invoke this method from a drawing method
anyway.
It seems that the best solution would be to access every frame while decoding, and save them. I tried OpenCV for Android but couldn't find an API to grab a frame at a specific time.
Now, I'm looking into those samples to understand how to use MediaCodec
, but while running ExtractMpegFramesTest.java
, I can't seem to extract any frame ("no output from decoder available").
Am I on the right track? Any other suggestion?
edit: went further with ExtractMpegFramesTest.java
, thanks for this post.
edit 2: just to clarify, what I'm trying to achieve here is to play a video, and press a button to start capturing the frames.