Recording a Surface using MediaCodec
Asked Answered
S

1

15

So, In my application, I am able to show effects(like blur filter, gaussian) to video that comes from Camera using GPUImage library.

Basically, I (library) will take the input from the Camera, get's the raw byte data, converts it into RGBA format from YUV format, then applies effects to this image and displays on the Surface of GLSurfaceView using OpenGL. finally, to the user, it looks like a video with effects applied.

Now I want to record the frames of Surface as a video using MediaCodec API.

but this discussion says that we can not pass a predefined Surface to the MediaCodec.

I have seen some samples at bigflake where he is creating Surface using MediaCodec.createInputSurface() but for me, Surface comes from the GLSurfaceView.

So, how can I record a frames of a Surface as a video?

I will record the audio parallelly, merge that video and audio using FFMPEG and present to the user as a Video with effects applied.

Strap answered 3/2, 2014 at 11:13 Comment(0)
C
9

You can see a complete example of this in Grafika.

In particular, the "Show + capture camera" activity records camera output to .mp4. It also demonstrates applying some simple image processing techniques in the GL shader. It uses a GLSurfaceView and a convoluted dance to keep the recording going across orientation changes.

Also possibly of interest, the "Record GL app with FBO" activity records OpenGL ES rendering a couple different ways. It uses plain SurfaceView and is much more straightforward.

Copywriter answered 3/2, 2014 at 15:48 Comment(1)
is it possible to record video in background (Service) using MediaCodec, I do it with FFmpegFrameRecorder right now and it works fine, I start my activity, then I reset Camera onPreviewFrame callback from Activity to Service method and I get bytes in Service to able record it with FFmpeg. But what about MediaCodec all those GL Views stuff?Furtado

© 2022 - 2024 — McMap. All rights reserved.