I am trying to get specific frames at specific times as images from a movie using MediaExtractor
and MediaCodec
. I can do it successfully if:
- I use
extractor.seekTo(time, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
, however, this only gives the nearest sync frame not the target frame. - I sequentially extract all frames using
extractor.advance();
, but I need to get the target frame not all.
So, I try the following:
extractor.seekTo(time, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
while(extractor.getSampleTime()<time /*target time*/) extractor.advance();
This provides the correct frame, but for some reason the image is corrupted. It looks like the correct image (the one I get from the successful cases), but with some pixelation and a strange haze.
The while-loop
is the only thing that is different between the successful cases and the corrupted ones. What to do to advance MediaExtractor
to a specific time (not just sync time) without getting a corrupted image?