My goal is to add some text info in the video output file obtained after recording a video with the Camera2 API
(e. g. date/time, user id etc.). I have checked some references about how to do this using camera API
but I didn't find any information about how to do achieve this with Camera2 API
. Can anyone help me?

- 1
- 1

- 354
- 2
- 15
-
You want to add it over the output video? Like a video with a text in the right corner(as a watermark) or just as information inside the video metadata? – Francisco Durdin Garcia Mar 09 '17 at 15:37
-
@FranciscoDurdinGarcia as a watermark – Hank Moody Mar 10 '17 at 20:19
-
Then check my answer – Francisco Durdin Garcia Mar 10 '17 at 20:33
-
try to read .hope this will give you some idea about it . – Atif AbbAsi Mar 13 '17 at 04:39
-
FFMPEG can help you – Hamid Reza Mar 13 '17 at 08:08
4 Answers
The link that you provided about how to achieve your solution using Camera API will work also for Camera2 API
. You should generate a GLSurfaceView
with the information that you want to achieve together with a GLSurfaceView.Renderer
to process each frame of your camera with OpenGL
.
After configure your surface you should generate a new Surface
from your SurfaceTexture
:
Surface videoSurface = new Surface(surfaceGLTexture);
After that you can use createCaptureSession
together with your Surface
and a CameraCaptureSession.StateCallback()
to generate a video preview using CameraDevice.TEMPLATE_RECORD
in your CaptureRequest.Builder
.

- 12,540
- 9
- 53
- 95
Take a look at grafica. Take a look specifically at TextureMovieEncoder.java. Replace the code in private void drawBox(int posn)
with the code found in the best answer to this question:
Draw text in OpenGL ES
copied here for reference:
// Create an empty, mutable bitmap
Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
// get a canvas to paint over the bitmap
Canvas canvas = new Canvas(bitmap);
bitmap.eraseColor(0);
// get a background image from resources
// note the image format must match the bitmap format
Drawable background = context.getResources().getDrawable(R.drawable.background);
background.setBounds(0, 0, 256, 256);
background.draw(canvas); // draw the background to our bitmap
// Draw the text
Paint textPaint = new Paint();
textPaint.setTextSize(32);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0x00, 0x00, 0x00);
// draw the text centered
canvas.drawText("Hello World", 16,112, textPaint);
//Generate one texture pointer...
gl.glGenTextures(1, textures, 0);
//...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
//Clean up
bitmap.recycle();
The same approach works, pretty much - the camera2 API wants a Surface to draw to, but you can create one from a SurfaceTexture:
Surface s = new Surface(mSurfaceTexture);
Then you can pass this Surface to the camera2 CameraDevice.createCaptureSession() call; see for example Camera2Video for a basic recording app to modify.
From your GL rendering, you have to then send the data to a video encoder.

- 17,243
- 2
- 42
- 47
FFMPEG provides too many thing that you can do what you want. Please try this tool. May be it will help you. I suggest you. Please check this link:

- 1
- 1

- 787
- 4
- 19