0

我正在尝试将 Android 的视图捕获为位图并将它们保存为 .mp4 文件。

我正在使用MediaCodec对位图进行编码,并使用MediaMuxer将它们混合到 .mp4 中。

使用 YUV420p 颜色格式,我希望来自 MediaCodec 的输入缓冲区具有一定的大小resWidth * resHeight * 1.5,但高通OMX.qcom.video.encoder.avc给我的远不止这些(无论我选择什么分辨率)。我相信它希望我在我的输入字节流中做一些对齐,但我不知道如何找出它到底希望我做什么。

当我使用高通的编解码器将数据紧紧地打包在 Nexus 7 (2013) 上的输入缓冲区中时,我得到了这样的结果: https: //www.youtube.com/watch?v=JqJD5R8DiC8

此视频由在 Nexus 10(编解码器OMX.Exynos.AVC.Encoder)上运行的相同应用制作:https ://www.youtube.com/watch?v=90RDXAibAZI

所以看起来亮度平面在有缺陷的视频中没有问题,但色度平面发生的事情对我来说是个谜。

我准备了暴露此问题的最小(2 类)工作代码示例:https ://github.com/eeprojects/MediaCodecExample

您只需运行此应用即可获得上面显示的视频(如果您的设备使用高通的编解码器,则会出现相同的伪影)。

4

1 回答 1

1

There are multiple ways of storing YUV 420 in buffers; you need to check the individual pixel format you chose. MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar and MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedPlanar are in practice the same, called planar or I420 for short, while the others, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedSemiPlanar and MediaCodecInfo.CodecCapabilities.COLOR_TI_FormatYUV420PackedSemiPlanar are called semiplanar or NV12.

In semiplanar, you don't have to separate planes for U and V, but you have one single plane with pairs of interleaved U,V.

See https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java (lines 925-949) for an example on how to fill in the buffer for the semiplanar formats.

于 2016-10-10T19:36:46.217 回答