3

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?

This is what I found for camera API

Community
  • 1
  • 1
Hank Moody
  • 354
  • 2
  • 15

4 Answers4

2

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.

Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
2

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();
Community
  • 1
  • 1
Thingy
  • 171
  • 3
0

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.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
0

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:

https://stackoverflow.com/a/38299320/3992798

Community
  • 1
  • 1
parik dhakan
  • 787
  • 4
  • 19