4

I have seen many similar questions like mine, but i have one difference i need to do this in java not in c/c++ and i need it work on android devices.

I found 1 way to do it with the "MediaMetadataRetriever".

but it takes me too long to seperate the frames(~1 sec to frame) and i need to read like 600 frames so it takes me 10 minutes only to read the images without the image processing.

I would like to know if there is another way to split the frames from a video, or manipulate MediaMetadataRetriever and make it work fast.

Thanks alot!

user2235615
  • 1,513
  • 3
  • 17
  • 37
  • Check out [this](http://stackoverflow.com/questions/22684347/extract-all-video-frames-in-android/43026616#43026616) answer regarding how to extract image frames from video file using ffmpeg..It's fast.. – Android Developer Mar 26 '17 at 08:47

1 Answers1

3

It sounds like you want to use a MediaCodec decoder. There are some examples here.

In particular, if you look at the DecodeEditEncodeTest code, the checkVideoFile() function decodes a previously-created stream to an external texture, then manipulates it with OpenGL ES. (To do this from a .mp4 file, you'd want to access it through a MediaExtractor.)

MediaMetadataRetriever#getFrameAtTime() is really meant for extracting thumbnails, and isn't particularly suited to extracting large numbers of frames.

Update: there's now sample code for extracting video frames using MediaExtractor, MediaCodec, and GLES (API 16+).

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Is there a way to download all cts classes and use it as library? And can i convert the output to openCV matrix? – user2235615 Oct 24 '13 at 07:16
  • (1) Assuming the video format is supported by `MediaCodec`, all the work is done by hardware or drivers through the point where you copy the data into your buffer with `glReadPixels`. (2) CTS is a collection of conformance tests; last I checked, the APK was about 100MB. So you definitely don't want *all* CTS classes. :-) Better to just pick out the parts you need. Some of the other examples on that page (e.g. EncodeAndMuxTest) were written that way. (3) I haven't used OpenCV; `glReadPixels` returns simple RGBA (which can be annoying if you need YUV). – fadden Oct 24 '13 at 14:46
  • Actually i need a gray scale matrix. i don't need image at all. and after i use glReadPixels function it take again too long to calculate. – user2235615 Oct 28 '13 at 06:36
  • It's supported only from API level 16, do you have an idea for api level 11 and above? – Nativ Oct 29 '13 at 13:52