Xys
Xys

Reputation: 10921

Android - Encode a video while decoding it

I modify a video with glsl shaders, using a SurfaceTexture and OpenGL ES 2.0. I can also encode the result video with MediaCodec.

The problem is that the only way I've found to decode the video is with MediaPlayer and SurfaceTexture, but MediaPlayer doesn't have a frame by frame decoding option. So right now, it's like a live encoding/decoding, there is no pause.

I've also tried to use seekTo / pause / start, but it would never update the texture..

So would it be possible to do a step by step decoding instead, to follow the encoding process ? I'm afraid that my current method is not very accurate.

Thanks in advance !

Upvotes: 1

Views: 648

Answers (2)

Xys
Xys

Reputation: 10921

EDIT : Wrong, mediaPlayer's stream cannot be used frame by frame, seems like it only works in "real" speed.

I've managed to do it with MediaPlayer actually. Following this answer :

stackoverflow - SurfaceTexture.OnFrameAvailableListener stops being called

Using counters, you can speed up or speed down the video stream, and synchronize it with the preview or the encoding.

But - If you want to do a real seek to a particular frame, then mstorsjo's solution is way better. In my case, I just wanted to make sure the encoding process is not going faster or slower than the video input stream.

Upvotes: 0

mstorsjo
mstorsjo

Reputation: 13317

Yes, instead of using MediaPlayer, you need to use MediaExtractor and MediaCodec to decode it (into the same SurfaceTexture that you're already using with MediaPlayer).

An example of this would be ExtractMpegFramesTest at http://bigflake.com/mediacodec/, possibly also DecodeEditEncodeTest (or for a >= Android 5.0 async version of it, see https://github.com/mstorsjo/android-decodeencodetest).

Upvotes: 1

Related Questions