In Android, how to pass a predefined Surface to MediaCodec for encoding?

前端 未结 2 1283
执笔经年
执笔经年 2021-02-04 10:50

I have an app that manages its own GLSurfaceView and now I want to use Android 4.3\'s new MediaCodec feature that takes a Surface as input.

In all the examples I\'ve see

相关标签:
2条回答
  • 2021-02-04 11:12

    It seems that in API 23+ there is an API called setInputSurface(Surface):

    0 讨论(0)
  • 2021-02-04 11:29

    No, it doesn't work that way. The input surface must be created with createInputSurface().

    Bear in mind that a "surface" isn't a buffer of data, it's a queue of buffers for which the producer and consumer endpoints are often in different processes. There are a lot of moving pieces that need to be set up. Also note that Surface and EGLSurface are two different things that, while often used together, aren't closely related.

    The API seems lumpy and weird because... it is. The implementation of Surface has changed quite a bit over the years -- the underpinnings used to be far less general, so most of the APIs for altering endpoints aren't exposed. The (underspecified) MediaCodec API is still evolving.

    There's an example of presenting the same content (camera preview) to GLSurfaceView and MediaCodec in Grafika. It sounds like you're trying to do something similar. (If not, update your question, and I'll update the answer.)

    0 讨论(0)
提交回复
热议问题