从 YUV420 ByteBuffer 创建 org.webrtc.JavaI420Buffer

问题描述

嗨,我正在开发一个实时流媒体解决方案,我需要在其中编辑本地视频帧并将其发送到连接的对等方,为此我正在编辑此任务 https://webrtc.googlesource.com/src/+/master/sdk/android/src/java/org/webrtc/Camera2Session.java#201,来自这里的 VideoFrame 被处理到编辑引擎,稍后它返回一个 YUV420 ByteBuffer 具有以下值:

  • frameWidth=1280
  • frameHeight=720
  • RowStrideY:1280
  • RowStrideU:640
  • RowStrideV:640
  • PlaneHeightY:720
  • PlaneHeightU:360
  • PlaneHeightV:360
  • PlaneOffsetY:0
  • PlaneOffsetU:921600
  • PlaneOffsetV:1152000
  • PixelStrideY=1
  • PixelStrideU=1
  • PixelStrideV=1

现在我想根据这个细节重新创建 VideoFrame 对象,我尝试了各种方法来实现这一点,并且几乎非常接近解决方案,只是无法将 Y、U 和 V ByteBuffer 从 ByteBuffer 中分离出来,因此输出是有点毁了。

enter image description here

我使用以下代码进行转换:

public static I420Buffer convert(ImageProcessResult result) {
    int frameWidth = result.getWidth();
    int frameHeight = result.getHeight();

    int rowStrideY = result.getRowStride(0);
    int rowStrideU = result.getRowStride(1);
    int rowStrideV = result.getRowStride(2);

    int offsetY = result.getPlaneOffset(0);
    int offsetU = result.getPlaneOffset(1);
    int offsetV = result.getPlaneOffset(2);

    ByteBuffer i420ByteBuffer = result.getBuffer();
    i420ByteBuffer.position(offsetY);
    final ByteBuffer dataY = i420ByteBuffer.slice();

    i420ByteBuffer.position(offsetU);
    final ByteBuffer dataU = i420ByteBuffer.slice();

    i420ByteBuffer.position(offsetV);
    final ByteBuffer dataV = i420ByteBuffer.slice();

    JavaI420Buffer frame = JavaI420Buffer.wrap(frameWidth,frameHeight,dataY,rowStrideY,dataU,rowStrideU,dataV,rowStrideV,() -> {
                JniCommon.nativeFreeByteBuffer(i420ByteBuffer);
            });
    return frame;
}

任何解决此问题的帮助将不胜感激,提前致谢..!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...