Problems with MediaExtractor

I am trying to get specific frames at specific times as images from a movie using MediaExtractor

and MediaCodec

. I can do this successfully if:

  • I am using extractor.seekTo(time, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);

    however this only gives the closest sync frame and not the target frame.
  • I fetch all frames sequentially with help extractor.advance();

    , but I don't need to get the target frame 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 the image is corrupted for some reason. This looks like the correct image (the one I get from successful cases), but with some pixelation and a weird haze.

while-loop

- the only thing that differs between successful cases and damaged ones. What can I do to promote MediaExtractor

at a specific time (not just sync time) without getting a corrupted image?

+2


source to share


1 answer


Thanks to fadden's comments, I have to keep feeding the encoder since it I-frame

has a complete image and the frames P

and B

have differences (this is how compression is achieved). So I need to start with I-frame

(it was the same as in the sync frame) and keep feeding other frames to the decoder to get the complete picture.



+1


source







All Articles