问题
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?
回答1:
Thanks to fadden comment, I have to keep feeding the encoder since the I-frame
has the full picture and the P
and B
frames have differences (this is how compression is achieved). So I need to start with an I-frame
(it was same as sync frame) and keep feeding the other frames to the decoder to receive the full image.
来源:https://stackoverflow.com/questions/21103347/problems-with-mediaextractor