从JCodec图片获取YUV420字节 [英] Get YUV420 bytes from JCodec Picture

查看:132
本文介绍了从JCodec图片获取YUV420字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用H264Decoder,我想将已解码的YUV420数据作为Java字节数组获取.我搜索了所有内容,但没有找到合适的示例.

Using an H264Decoder I would like to obtain the decoded YUV420 data as a Java byte array. I have searched all over and I don't see any examples that fit.


ByteBuffer buf = ByteBuffer.wrap(h264EncodedByteArray);
H264Decoder decoder = new H264Decoder();
// assume that sps and pps are set on the decoder
Picture out = Picture.create(320, 240, ColorSpace.YUV420); 
Picture real = decoder.decodeFrame(buf, out.getData());

"h264EncodedByteArray"将是来自流或文件的h264编码字节的数组.

The "h264EncodedByteArray" would be an array of h264 encoded bytes from a stream or file.

推荐答案

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

As far as I can tell the buf and avcC box must be supplied when doing the decode. Before any decoding can commence, you must provide avcC data.


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

创建avcC之后,您可以使用以下行获取图片.

After the avcC is created, you can use the following line to get the Picture.


decoder.decodeFrame(H264Utils.splitMOVPacket(buf, avcCBox), out.getData());

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

In the code above the buf may or may not contain multiple NAL elements.

这篇关于从JCodec图片获取YUV420字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆