I search lot but not find any solution. My question is how to add text to video while recording so that we can get same text when we see video. I want something like this when i see capture video. Currently i am getting time and video sepratly. So issue is how to combine it.Any kind of help will be appreciated.Thanks in advance..
This is a pretty difficult problem to solve generally using android assuming that you are attempting to add the text to the actual video file, and not simply displaying a TextView
over a VideoView
. You mention that you currently have the time and video separately, so I assume you are trying to add text to the video file itself.
In order to add text to a video you would need to re-encode the video on the actual device. Re-encoding video on Android is tricky primarily due to the different processors on Android phones, and that encoding is processor dependent. There is an open source iOS library called GPUImage
that allows you to do this, but this is unfortunately not available on Android.
There has been some effort to compile FFMPEG for Android (which would theoretically allow this kind of thing to occur), but this involves some serious work with underlying C++ code, and I haven't found any application that implements this simply on many devices (check out this video converter, and notice how for different phones different codecs need to be downloaded). For one specific device you may have more luck, but if you are looking for easy distribution across many devices you may have a hard time doing this.
At this time, there is no easy solution for this problem.
I use camera2 API. I create preview and ImageReader. I get canvas from recording surface. Each frame convert to bitmap and put to canvas, then draw logo, text, etc. ,
private val mOnImageAvailableListener = ImageReader.OnImageAvailableListener { reader ->
val image = reader.acquireNextImage() ?: return@OnImageAvailableListener
val bytes = image.toNV21()//image.convertYUV420888ToNV21()
val bitmap = Bitmap.createBitmap(image.width, image.height,
Bitmap.Config.ARGB_8888);
val bmData: Allocation = Converter.renderScriptNV21ToRGBA888(requireContext(),
image.width, image.height, bytes)
bmData.copyTo(bitmap)
val canvas = recorderSurface!!.lockCanvas(null)
canvas.drawBitmap(bitmap, 0f, 0f, Paint())
drawData(canvas)
recorderSurface!!.unlockCanvasAndPost(canvas)
bitmap.recycle()
image.close()
}
© 2022 - 2024 — McMap. All rights reserved.