How to turn a MediaExtractor sample into a full image Bitmap?

114 Views Asked by At

I'm trying to make a video-compression algorithm, and one way I want to reduce size is by dropping the frame rate. The code below shows how I achieve this - basically I keep advancing to the next sample until the time difference is greater than the inverse of the desired frame rate.

if (!firstFrame) {
    while (!eof && extractor.getSampleTime() - prevSampleTime < 1000000 / frameRate) {
        eof = !extractor.advance();
    }
}
firstFrame = false;
prevSampleTime = extractor.getSampleTime();

However the obvious problem with this is that dropping a frame means that the next diff frame is going off the wrong frame, resulting in a distorted video. Is there any way to get extract the full image Bitmap at a particular frame? Basically I want to achieve something like this:

  1. Video frames are extracted iteratively and unwanted frames are dropped
  2. Remaining frames are converted into their full Bitmap
  3. All Bitmaps are strung together to form the raw video
  4. Raw video is compressed with AVC compression.

I don't mind how long this process takes as it will be running in the background and the output will not be displayed immediately.

1

There are 1 best solutions below

0
dev.bmax On

Since most video compression algorithms today use Inter Frame Prediction, some frames (usually most of them) can't be decoded on their own (without feeding previous frames) as you noted in the question.

It means, that you must decode all frames. And then you can drop some of them before encoding.