0

使用 H264Decoder 我想获得解码的 YUV420 数据作为 Java 字节数组。我已经搜索了所有内容,但没有看到任何适合的示例。

ByteBuffer buf = ByteBuffer.wrap(h264EncodedByteArray);
H264Decoder 解码器 = new H264Decoder();
// 假设解码器上设置了sps和pps
图片输出 = Picture.create(320, 240, ColorSpace.YUV420);
图片真实=decoder.decodeFrame(buf, out.getData());

“h264EncodedByteArray”将是来自流或文件的 h264 编码字节数组。

4

1 回答 1

0

据我所知,在进行解码时必须提供 buf 和 avcC 框。在开始任何解码之前,您必须提供 avcC 数据。

AvcCBox avcCBox = new AvcCBox();
avcCBox.parse(buf);

在avcC创建完成后,可以使用下面这行来获取Picture。

解码器.decodeFrame(H264Utils.splitMOVPacket(buf, avcCBox), out.getData());

在上面的代码中,buf 可能包含也可能不包含多个 NAL 元素。

于 2014-10-13T12:27:55.660 回答