0

The mediacodec's official document said:

Data Types Codecs operate on three kinds of data: compressed data, raw audio data and raw video data. All three kinds of data can be processed using ByteBuffers, but you should use a Surface for raw video data to improve codec performance. Surface uses native video buffers without mapping or copying them to ByteBuffers; thus, it is much more efficient. You normally cannot access the raw video data when using a Surface, but you can use the ImageReader class to access unsecured decoded (raw) video frames. This may still be more efficient than using ByteBuffers, as some native buffers may be mapped into direct ByteBuffers. When using ByteBuffer mode, you can access raw video frames using the Image class and getInput/OutputImage(int).

How to under stande this? you should use a Surface for raw video data to improve codec performance, What is native video buffers? How do I use Surface to improve encode or decode performance?

lxacoder
  • 191
  • 1
  • 11

2 Answers2

2

You can use the input surface of a codec for ecoding video frames, you can get this surface using createInputSurface() then (if you don't use NDK) you can get the canvas from the surface and draw frames on it or you can use NDK and copy frame data to the surface buffer, both of this approaches in the result will give you encoded frame data.

As for decoding you can create some surface in your UI and pass it to decoder using configure() it will allow the decoder to render a decoded frame into the surface so you won't need to copy decoded data from output buffers of decoder the only thing you should do is to pass true as "render" argument to releaseOutputBuffer() of the decoder.

easy_breezy
  • 1,073
  • 7
  • 18
1

When you use a surface you don't have to feed the byte buffers explicitly to the encoder. Encoder will directly grab the the input data from surface. Here are some of the examples of using it. BigFlake BigFlake is the best site for starting with. EncodeAndMuxTest Hope this will help you to understand the concept.

Mohan
  • 53
  • 5