Android 使用camera2 API在视频输出文件中添加文本标签
我的目标是在使用Android 使用camera2 API在视频输出文件中添加文本标签,android,renderscript,android-camera2,textureview,Android,Renderscript,Android Camera2,Textureview,我的目标是在使用camera2api录制视频后获得的视频输出文件中添加一些文本信息(例如日期/时间、用户id等)。我查看了一些关于如何使用cameraapi实现这一点的参考资料,但没有找到任何关于如何使用camera2api实现这一点的信息。有人能帮我吗 同样的方法也很有效——camera2 API希望绘制一个曲面,但您可以从SurfaceTexture创建一个曲面: Surface s = new Surface(mSurfaceTexture); 然后可以将该曲面传递给camera2 Ca
camera2api
录制视频后获得的视频输出文件中添加一些文本信息(例如日期/时间、用户id等)。我查看了一些关于如何使用cameraapi
实现这一点的参考资料,但没有找到任何关于如何使用camera2api
实现这一点的信息。有人能帮我吗
同样的方法也很有效——camera2 API希望绘制一个曲面,但您可以从SurfaceTexture创建一个曲面:
Surface s = new Surface(mSurfaceTexture);
然后可以将该曲面传递给camera2 CameraDevice.createCaptureSession()调用;有关要修改的基本录制应用程序,请参见示例
从GL渲染中,您必须将数据发送到视频编码器。您提供的关于如何使用Camera API实现解决方案的链接也适用于
Camera2 API
。您应该使用GLSurfaceView.Renderer
生成一个GLSurfaceView
,其中包含您想要获得的信息,以便使用OpenGL
处理相机的每个帧
配置曲面后,您应该从SurfaceTexture
生成一个新的surface
:
Surface videoSurface=新曲面(surfaceGLTexture)代码>
之后,您可以使用createCaptureSession
以及Surface
和CameraCaptureSession.StateCallback()
在CaptureRequest.Builder中使用CameraDevice.TEMPLATE\u RECORD
生成视频预览。FFMPEG提供的内容太多,您可以随心所欲。请试试这个工具。也许对你有帮助。我建议你。请检查此链接:
看一看。具体看一看。将private void drawBox(int posn)
中的代码替换为此问题最佳答案中的代码:
复制于此以供参考:
// 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();
要将其添加到输出视频上吗?像一个右角有文字的视频(作为水印),或者像视频元数据中的信息一样?@franciscodingarcia作为水印,然后检查我的回答尝试阅读。希望这能给你一些想法。!我可以帮你