|
|
|
@ -4,7 +4,9 @@ import android.graphics.Bitmap
|
|
|
|
|
import android.opengl.EGL14
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.os.HandlerThread
|
|
|
|
|
import android.view.TextureView
|
|
|
|
|
import android.view.PixelCopy
|
|
|
|
|
import android.view.PixelCopy.OnPixelCopyFinishedListener
|
|
|
|
|
import android.view.SurfaceView
|
|
|
|
|
import com.common.commonlib.CommonApplication
|
|
|
|
|
import com.common.commonlib.utils.BitmapUtils
|
|
|
|
|
import com.yinuo.library.vlc.encoder.BaseMovieEncoder.EncoderConfig
|
|
|
|
@ -32,23 +34,47 @@ object RecordHelper {
|
|
|
|
|
mVideoEncoder = MovieEncoder1(CommonApplication.getContext(), width, height, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun onFrameAvailable(view: TextureView) {
|
|
|
|
|
fun onFrameAvailable(view: SurfaceView) {
|
|
|
|
|
if (!mVideoEncoder.isRecording) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// workHandler.post {
|
|
|
|
|
// val nanoTime = System.nanoTime()
|
|
|
|
|
// var bitmap = view.bitmap
|
|
|
|
|
// bitmap?.let {
|
|
|
|
|
// val overLayBitmap: Bitmap? = TxtOverlay.getOverlayBitmap()
|
|
|
|
|
// overLayBitmap?.let {
|
|
|
|
|
// bitmap = BitmapUtils.mergeBitmap(bitmap!!, overLayBitmap)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// val buffer = ByteBuffer.allocate(bitmap!!.getByteCount())
|
|
|
|
|
// bitmap!!.copyPixelsToBuffer(buffer)
|
|
|
|
|
// bitmap!!.recycle()
|
|
|
|
|
// mVideoEncoder.frameAvailable(buffer.array(), nanoTime)
|
|
|
|
|
// }
|
|
|
|
|
workHandler.post {
|
|
|
|
|
val nanoTime = System.nanoTime()
|
|
|
|
|
var bitmap = view.bitmap
|
|
|
|
|
bitmap?.let {
|
|
|
|
|
val overLayBitmap: Bitmap? = TxtOverlay.getOverlayBitmap()
|
|
|
|
|
overLayBitmap?.let {
|
|
|
|
|
bitmap = BitmapUtils.mergeBitmap(bitmap!!, overLayBitmap)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val buffer = ByteBuffer.allocate(bitmap!!.getByteCount())
|
|
|
|
|
bitmap!!.copyPixelsToBuffer(buffer)
|
|
|
|
|
bitmap!!.recycle()
|
|
|
|
|
mVideoEncoder.frameAvailable(buffer.array(), nanoTime)
|
|
|
|
|
var bitmap = Bitmap.createBitmap(
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
Bitmap.Config.ARGB_8888
|
|
|
|
|
)
|
|
|
|
|
PixelCopy.request(
|
|
|
|
|
view.holder.surface, bitmap, { copyResult ->
|
|
|
|
|
val nanoTime = System.nanoTime()
|
|
|
|
|
if (copyResult == PixelCopy.SUCCESS) {
|
|
|
|
|
bitmap?.let {
|
|
|
|
|
val overLayBitmap: Bitmap? = TxtOverlay.getOverlayBitmap()
|
|
|
|
|
overLayBitmap?.let {
|
|
|
|
|
bitmap = BitmapUtils.mergeBitmap(bitmap!!, overLayBitmap)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val buffer = ByteBuffer.allocate(bitmap!!.byteCount)
|
|
|
|
|
bitmap!!.copyPixelsToBuffer(buffer)
|
|
|
|
|
bitmap!!.recycle()
|
|
|
|
|
mVideoEncoder.frameAvailable(buffer.array(), nanoTime)
|
|
|
|
|
}
|
|
|
|
|
}, workHandler
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|