I'm trying to understand how the surface-to-surface approach works with MediaCodec. In a ByteBuffer only approach, decoded data is placed in OutputBuffers. This non-encoded data can be processed manually then passed to the InputBuffers of an Encoder.
If we give a look at an example from Android MediaCodec CTS using a surface to surface approach to pass data between a decoder and an encoder, we configure the Decoder to output the decoded data onto a Surface called outputSurface, and we configure the Encoder to receive the data on a Surface called inputSurface.
In the documentation, the createInputSurface and the usage of this surface in the configuration of the Encoder is described as so:
createInputSurface(): Requests a Surface to use as the input to an encoder, in place of input buffers.
In other terms, and this is visible in the CTS example in the ByteBuffers declarations: there is just no InputBuffers for the Encoder. You have:
- DecoderInputBuffers (receive the video track samples from the MediaExtractor)
- DecoderOutputBuffers (output to pull decoded yuv frames)
- Nothing. (Well... The input Surface.)
- EncoderOutputBuffers (output to pull the re-encoded stuff to pass to a muxer)
Instead of enqueu-ing data in the Encoder InputBuffers, you have these line of codes:
outputSurface.awaitNewImage();
outputSurface.drawImage();
inputSurface.setPresentationTime(videoDecoderOutputBufferInfo.presentationTimeUs * 1000);
inputSurface.swapBuffers();
How is the ouputSurface content of the Decoder passed to the inputSurface of the Encoder? What is concretely happening behind the curtain?