Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed text while recording video in Android?

My goal is to record the video in Android with stopwatch embedded in it while recording.

I followed the samples of Grafika Project, CameraCaptureActivity.java where they use OpenGL 2.0 to record a small block along with recording video. They are using following code to draw block in OpenGL 2.0

private static void drawExtra()
{
      GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
      GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
      GLES20.glScissor(0, 0, width / 3, height / 3);
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
      GLES20.glDisable(GLES20.GL_SCISSOR_TEST); 
}

The above code draw white block at the bottom left side of the video while recording and saving.

What I want is to draw text over that white box using OpenGL 2.0, so that it will also record along with video.

I dont have knowledge of OpenGL 2.0. Need help to just draw text over same surface where video is recording, so that it will get embedded into it just like that white box.

like image 349
Navjot Avatar asked May 19 '14 10:05

Navjot


2 Answers

You can try Intel INDE on https://software.intel.com/en-us/intel-inde and Media Pack for Android which is a part of INDE, tutorials on https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials. It has a sample effect called TextOverlayEffect to put text on a video

like image 176
Marlon Avatar answered Nov 08 '22 03:11

Marlon


This isn't MediaCodec-specific. Drawing text in OpenGL is a pretty common thing to want to do. The usual approach is to render text with a font engine (e.g. Skia) to a texture and then render the texture.

Android Breakout uses this approach: it renders a fixed set of strings to a texture, then renders from that texture. Most of the strings are whole ("game over"), but the score digits are handled individually. See in particular this class.

If your character set is limited and you're not too excited about kerning (e.g. ASCII text in English comes out pretty well), you can just render individual character glyphs and then draw from that. Version 1.1. of the "screenrecord" tool does this. (Note it's implemented in C++.)

You can see both at work in this video. The initial page of text and the line of text at the top of the screen are overlayed by screenrecord as the video is recorded, drawn one character at a time. The "Ready?" message with the drop shadow is rendered by the game from a single string. (The menus are just rendered with the Android framework.)

Your best bet is to find a library that does this for you and has a friendly open-source license.

like image 25
fadden Avatar answered Nov 08 '22 01:11

fadden