UVCCamera OpenGL 添加时间戳水印

Android使用OpenGL添加视频流水印的实现
该文介绍了如何在Android中通过OpenGL进行视频流渲染并添加水印的过程。首先,通过USB摄像头获取预览数据输出到外部纹理,然后利用FBO(帧缓冲对象)进行混合操作,结合相机纹理和水印纹理最终在SurfaceView上显示。文章详细阐述了创建外部纹理、初始化EGL上下文、绑定显示窗口缓冲区以及FBO渲染的过程,同时展示了动态绘制时间水印的方法。

视频流添加水印方式较多 本文只从渲染角度修改 

修改  CameraViewInterface 预览视图 自定义 CameraSurfaceView 将相机预览数据输出到外部纹理 通过fbo 混合水印纹理及Camera纹理 最终输出到 SurfaceView 上

打开相机输出到外部纹理

mHandlerL.startPreview(mUVCCameraViewL.getSurfaceTexture());

private final OnDeviceConnectListener mOnDeviceConnectListener = new OnDeviceConnectListener() {
		@Override
		public void onAttach(final UsbDevice device) {
			if (DEBUG) Log.v(TAG, "onAttach:" + device);
			Toast.makeText(MainActivity.this, "USB_DEVICE_ATTACHED", Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onConnect(final UsbDevice device, final UsbControlBlock ctrlBlock, final boolean createNew) {
			if (DEBUG) Log.v(TAG, "onConnect:" + device);
			if (!mHandlerL.isOpened()) {
				if (DEBUG) Log.v(TAG, "mHandlerL not opend:");
				mHandlerL.open(ctrlBlock);
				mHandlerL.startPreview(mUVCCameraViewL.getSurfaceTexture());
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						mCaptureButtonL.setVisibility(View.VISIBLE);
					}
				});
			} else if (!mHandlerR.isOpened()) {
				if (DEBUG) Log.v(TAG, "mHandlerR not opend:");
				mHandlerR.open(ctrlBlock);
				mHandlerR.startPreview(mUVCCameraViewR.getSurfaceTexture());
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						mCaptureButtonR.setVisibility(View.VISIBLE);
					}
				});
			}
		}

创建外部纹理 及  SurfaceTexture 

     cameraTexture = GlUtil.createRecordCameraTextureID();
        surfaceTexture = new SurfaceTexture(cameraTexture);

RenderThread 中绑定EGL上下文 绑定显示窗口缓冲区  

   private final void init() {
                if (DEBUG) Log.v(TAG, "RenderThread#init:");
                try {
                    glRenderManager.setCameraRotate(180);
                    glRenderManager = new GlRenderManager(appContext, mTexId, mDispSurface, mPreviewSurface);
                    glRenderManager.onInputSizeChanged(640, 480);
                    glRenderManager.onDisplaySizeChanged(mViewWidth, mViewHeight);


                    // notify to caller thread that previewSurface is ready
                } catch (GlUtil.OpenGlException e) {
                    e.printStackTrace();
                }
            }
 public GlRenderManager(Context context, int texture, Surface disPlaySurface, SurfaceTexture surfaceTexture) throws GlUtil.OpenGlException {
        this.context = context;
        this.texture = texture;
        this.surfaceTexture = surfaceTexture;
        mEglCore = new EglCore(null, EglCore.FLAG_TRY_GLES3);
        setDisPlaySurface(disPlaySurface);
     
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值