9

I am working on a project where we need to record the rendered OpenGL surface. (for example if we use GLsurfaceView, we need to record the surface along with the audio from the MIC)

Presently I am using MediaRecorder API by setting the video source as the VIDEO_SOURCE_GRALLOC_BUFFER.

I am using the following sample as the base code

I wanted to know ....

  1. Is this the right way? . Is there any better alternate ?
  2. The sample test given in the link is recording the audio and video of the EGLSURFACE but it is not displayed properly.

What might be the reason?
Any help/pointers is really appreciated.

thanks,
Satish

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Satish.
  • 95
  • 1
  • 2
  • 6

1 Answers1

18

The code you reference isn't a sample, but rather internal test code that exercises a non-public interface. SurfaceMediaSource could change or disappear in a future release and break your code.

Update: Android 4.3 (API 18) allows Surface input to MediaCodec. The EncodeAndMuxTest sample demonstrates recording OpenGL ES frames to a .mp4 file.

The MediaRecorder class doesn't take Surface input, so in your case you'd need to record the audio separately and then combine it with the new MediaMuxer class.

Update #2: Android 5.0 (API 21) allows Surface input to MediaRecorder, which is often much more convenient than MediaCodec. If you neeed to use MediaCodec, there is an example showing three different ways of recording OpenGL ES output with it in Grafika's "record GL activity".

The MediaProjection class can also be useful for screen recording.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Hi, Thanks for the information. At present we are proceeding with glreadpixels which is decreasing the the FPS. – Satish. May 23 '13 at 04:35
  • Just logged in just to say you are a life saver. Now, on to finding a way to do it on iOS as well. – TatiOverflow Mar 20 '18 at 18:05
  • 1
    MediaRecorder Surface Source is so buggy... https://stackoverflow.com/questions/51332386/mediarecorder-and-videosource-surface-stop-failed-1007-a-serious-android-bug – user924 Jul 19 '18 at 07:09
  • @user924: The code you reference creates a bitmap, and sets it as a texture with `glTexImage2D()`, but doesn't include any code to render the texture. If you're not sure how to do that, file a new question with [android] and [opengl-es] tags (and possibly [grafika]). – fadden Jul 19 '18 at 15:43
  • @fadden I made some progress https://github.com/google/grafika/issues/74#issuecomment-406852804 but it draws bitmap with black background (even If I set Transparent color for canvas), what could be wrong? p.s. I used this cloned project https://github.com/crearo/grafika – user924 Jul 22 '18 at 10:16
  • MediaRecorder setInputSurface need API 23 – shuo Han Jan 07 '19 at 13:51