2

我正在使用新的 API MediaCodec。我想获取解码的视频帧并在某个调度时间将它们呈现在表面上。现在我可以在模拟器上正确运行我的代码并获得如下视频帧格式:

{height=192, what=1869968451, color-format=19, slice-height=192, crop-left=0, width=320, crop-bottom=179, crop-top=0, mime=video/raw, stride=320, crop-right=319}

但是当我在 nexus 4 上运行我的代码时,视频帧格式更改为

{height=180, what=1869968451, color-format=2141391875, slice-height=192, crop-left=0, width=320, crop-bottom=179, crop-top=0, mime=video/raw, stride=384, crop-right=319}

查不出2141391875的颜色格式是什么,为什么高度不是192。一个有趣的问题是,当我将configure函数从codec.configure(format, surface /* surface */, null /* crypto */, 0 /* flags */)to修改时codec.configure(format, null/* surface */, null /* crypto */, 0 /* flags */),输出缓冲区长度会从0变为114688。但实际上,如果帧格式为 YUV420p (320*192*1.5),则正确的缓冲区长度应为 92160。我发现当我在模拟器上运行时,输出缓冲区在输出格式发生变化之前发生了变化。但是当我在nexus 4上运行时,这并没有改变。日志如下所示,在模拟器上:

03-26 14:42:38.466: I/VideoPlayTAG(1212): count=0
03-26 14:42:38.476: I/VideoPlayTAG(1212): sampleSize:700
03-26 14:42:38.496: D/VideoPlayTAG(1212): next:true
03-26 14:42:38.496: I/VideoPlayTAG(1212): output index:-3
03-26 14:42:38.566: D/VideoPlayTAG(1212): output buffers have changed.
03-26 14:42:38.566: I/VideoPlayTAG(1212): count=1
03-26 14:42:38.566: I/VideoPlayTAG(1212): sampleSize:140
03-26 14:42:38.596: D/VideoPlayTAG(1212): next:true
03-26 14:42:38.596: I/VideoPlayTAG(1212): output index:-2
03-26 14:42:38.686: D/VideoPlayTAG(1212): color=19 width=320 height=192
03-26 14:42:38.686: I/JNI(1212): begin setRender 1734
03-26 14:42:38.686: I/JNI(1212): setRender
03-26 14:42:38.716: D/VideoPlayTAG(1212): output format has changed to {height=192, what=1869968451, color-format=19, slice-height=192, crop-left=0, width=320, crop-bottom=179, crop-top=0, mime=video/raw, stride=320, crop-right=319}
03-26 14:42:38.716: I/VideoPlayTAG(1212): count=2

在关系 4 上:

03-26 10:17:59.674: I/VideoPlayTAG(29899): count=0
03-26 10:17:59.684: I/VideoPlayTAG(29899): sampleSize:700
03-26 10:17:59.684: D/VideoPlayTAG(29899): next:true
03-26 10:17:59.694: I/VideoPlayTAG(29899): output index:-1
03-26 10:17:59.694: I/VideoPlayTAG(29899): count=1
03-26 10:17:59.704: I/VideoPlayTAG(29899): sampleSize:140
03-26 10:17:59.704: D/VideoPlayTAG(29899): next:true
03-26 10:17:59.704: I/VideoPlayTAG(29899): output index:-1
03-26 10:17:59.714: I/VideoPlayTAG(29899): count=2
03-26 10:17:59.714: I/VideoPlayTAG(29899): sampleSize:131
03-26 10:17:59.714: D/VideoPlayTAG(29899): next:true
03-26 10:17:59.724: I/VideoPlayTAG(29899): output index:-1
03-26 10:17:59.724: I/VideoPlayTAG(29899): count=3
03-26 10:17:59.724: I/VideoPlayTAG(29899): sampleSize:59
03-26 10:17:59.724: D/VideoPlayTAG(29899): next:true
03-26 10:17:59.724: I/VideoPlayTAG(29899): output index:-2
03-26 10:17:59.744: D/VideoPlayTAG(29899): color=2141391875 width=320 height=180
03-26 10:17:59.744: I/JNI(29899): begin setRender 1734
03-26 10:17:59.744: I/JNI(29899): setRender
03-26 10:17:59.744: D/VideoPlayTAG(29899): output format has changed to {height=180, what=1869968451, color-format=2141391875, slice-height=192, crop-left=0, width=320, crop-bottom=179, crop-top=0, mime=video/raw, stride=384, crop-right=319}
03-26 10:17:59.744: I/VideoPlayTAG(29899): count=4

谁能帮我?我发现问题可能是由软件渲染和硬件渲染的差异引起的。

4

1 回答 1

1
  1. 2141391875 (0x7fa30c03) 是 NV12 肾上腺素平铺(又名 HAL_PIXEL_FORMAT_NV12_ADRENO_TILED,又名 HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED)。这种颜色格式具有像素数据排序的最佳硬件处理方式。
  2. 模拟器中的图片高度也不是 192。请注意:上面写着“crop-bottom=179”。这意味着高度实际上是相同的(180)。
  3. 114688 字节是缓冲区的合适大小。以这种方式计算 = slice-height(192) * stride(384) * 1.5 并与 8K 对齐。
  4. INFO_OUTPUT_FORMAT_CHANGED 和 INFO_OUTPUT_BUFFERS_CHANGED 有不同的意义,那些顺序无关紧要。

仍然没有问题,一切看起来都很好。

于 2013-05-25T20:44:40.087 回答