Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recording a Surface using MediaCodec

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.

like image 760
RuntimeException Avatar asked Feb 03 '14 11:02

RuntimeException


People also ask

How does MediaCodec work?

It processes data asynchronously and uses a set of input and output buffers. At a simplistic level, you request (or receive) an empty input buffer, fill it up with data and send it to the codec for processing. The codec uses up the data and transforms it into one of its empty output buffers.

What is MediaCodec?

MediaCodec class can be used to access low-level media codecs, i.e. encoder/decoder components. It is part of the Android low-level multimedia support infrastructure (normally used together with MediaExtractor , MediaSync , MediaMuxer , MediaCrypto , MediaDrm , Image , Surface , and AudioTrack .)

What is a surface in Android?

A Surface is an object holding pixels that are being composited to the screen. Every window you see on the screen (a dialog, your full-screen activity, the status bar) has its own surface that it draws in to, and Surface Flinger renders these to the final display in their correct Z-order.


1 Answers

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.

like image 144
fadden Avatar answered Sep 21 '22 09:09

fadden