当前位置: 首页 > news >正文

海康IPC接入TRTC时,从海康中获取的数据显示时色差不正确

2021/1

记录海康IPC接入TRTC时的历史日志
 

从海康sdk接口获取数据,进行解码

org.MediaPlayer.PlayM4.Player.T_YV12;private void setDecodeCB() {Player.getInstance().setDecodeCB(m_iPort, (nPort, data, nDataLen, nWidth, nHeight, nFrameTime, nDataType, arg7) -> {if (nDataType == T_YV12 ) {byte[] i420bytes = swapYV12toI420(data, nWidth, nHeight);callback.afterCall(context, i420bytes.length, i420bytes, nWidth, nHeight, nFrameTime);}});}


解码后如下展示的时候,出现图片偏差

    byte[] nv12bytes = RSNV12ToBitmap.getInstance(context).swapI420toNV12(data, nWidth, nHeight);//额外转换 3msBitmap buffBitmap = RSNV12ToBitmap.getInstance(context).nv12ToBitmap(nv12bytes, nWidth, nHeight);//20毫秒

可能是android.renderscript.ScriptIntrinsicYuvToRGB接受的YUV是nv21而不是nv12

    byte[] nv21bytes = RSNV12ToBitmap.getInstance(context).swapI420toNV21(data, nWidth, nHeight);//额外转换 3msBitmap buffBitmap = RSNV12ToBitmap.getInstance(context).nv21ToBitmap(nv21bytes, nWidth, nHeight);//20毫秒

图像格式转换函数

package com.sunshine.mhs.pension.doctormodule.trct.ipc.util;/*** 作者:Administrator on 2020/3/26* 邮箱:9611153@qq.com*/import android.content.Context;
import android.graphics.Bitmap;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicYuvToRGB;
import android.renderscript.Type;public class RSNV21ToBitmap {private static RSNV21ToBitmap instance;private RenderScript rs;private ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic;private byte[] nv21bytes;private RSNV21ToBitmap(Context context) {nv21bytes = null;rs = RenderScript.create(context);yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));}public static RSNV21ToBitmap getInstance(Context context) {if (instance == null) {instance = new RSNV21ToBitmap( context);}return instance;}public static void destory() {if (instance != null) {instance.yuvToRgbIntrinsic.destroy();instance.rs.destroy();instance = null;}}public Bitmap nv21ToBitmap(byte[] nv21, int width, int height) {if (nv21 == null) return null;Type.Builder yuvType, rgbaType;Allocation in, out;yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);Bitmap bmpout = null;try {in.copyFrom(nv21);yuvToRgbIntrinsic.setInput(in);yuvToRgbIntrinsic.forEach(out);bmpout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);out.copyTo(bmpout);} catch (Exception e) {e.printStackTrace();}return bmpout;}public byte[] swapI420toNV21(byte[] I420bytes, int width, int height) {if (null == nv21bytes) {nv21bytes = new byte[I420bytes.length];}if (I420bytes.length != nv21bytes.length)return null;int nLenY = width * height;int nLenU = nLenY / 4;System.arraycopy(I420bytes, 0, nv21bytes, 0, nLenY);for (int i = 0; i < nLenU; i++) {nv21bytes[nLenY + 2 * i + 1] = I420bytes[nLenY + i];//先v后Unv21bytes[nLenY + 2 * i] = I420bytes[nLenY + nLenU + i];}return nv21bytes;}}

http://www.lryc.cn/news/487627.html

相关文章:

  • 『VUE』31. 生命周期的应用(详细图文注释)
  • Mybatis框架之建造者模式 (Builder Pattern)
  • Java从入门到精通笔记篇(十三)
  • 嵌入式:STM32的启动(Startup)文件解析
  • ElasticSearch学习笔记四:基础操作(二)
  • ODA-em-application.log太大处理
  • 基于现金红包营销活动的开源 AI 智能名片与 S2B2C 商城小程序融合发展研究
  • 远程管理不再难!树莓派5安装Raspberry Pi OS并实现使用VNC异地连接
  • React中 setState 是同步的还是异步的?调和阶段 setState 干了什么?
  • 【D3.js in Action 3 精译_040】4.4 D3 弧形图的绘制方法
  • C++设计模式:抽象工厂模式(风格切换案例)
  • 搜维尔科技:Xsens随时随地捕捉,在任何环境下实时录制或捕捉
  • 爬虫基础总结 —— 附带爬取案例
  • 图像处理学习笔记-20241118
  • 不能打开网页,但能打开QQ、微信(三种方式)
  • 使用 start-local 脚本在本地运行 Elasticsearch
  • 计算机网络:概述知识点及习题练习
  • python蓝桥杯刷题2
  • 在openi平台 基于华为顶级深度计算平台 openmind 动手实践
  • KF UKF
  • 中伟视界:AI智能分析算法如何针对非煤矿山的特定需求,提供定制化的安全生产解决方案
  • Unity 编辑器下 Android 平台 Addressable 加载模型粉红色,类似材质丢失
  • Pytest-Bdd-Playwright 系列教程(10):配置功能文件路径 优化场景定义
  • rust逆向初探
  • 【Linux】apt 关闭 ssl 认证
  • 【算法】P5018 对称二叉树
  • Unifying Top-down and Bottom-up Scanpath Prediction Using Transformers
  • JavaSE(十四)——文件操作和IO
  • 【视觉SLAM】4b-特征点法估计相机运动之PnP 3D-2D
  • android 性能分析工具(04)Asan 内存检测工具