从整数数组解码H264 [英] Decode H264 From Array of Integers

查看:124
本文介绍了从整数数组解码H264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从相机解码H264原始协议,但是使用Jcodec H264Decoder时遇到了一些问题.我从相机收到一个包含信息的整数数组.下面是数据示例:

I'm trying to decode a H264 raw protocol from a camera but I'm having some problems using the Jcodec H264Decoder. I receive an array of integers with the information from the camera. Below a sample of the data:

array:00 00 01 FD 00 00 14 69 00 00 00 00 01 61 E4 80 6F D3 5B 76 97 DF 04 3A EF 54 97 0E D9 F5 ...更多

array: 00 00 01 FD 00 00 14 69 00 00 00 01 61 E4 80 6F D3 5B 76 97 DF 04 3A EF 54 97 0E D9 F5...more

我正在使用的代码是:

ByteBuffer bb = ByteBuffer.wrap( Utils.intArrayToByteArray(array, arraySize) );
bb.rewind();
// Create a buffer to hold the output picture which is big enough
Picture outBuffer = Picture.create( 1920, 1088, ColorSpace.YUV420 );
Picture pic = _decoder.decodeFrame( bb, outBuffer.getData() );
BufferedImage bufferedImage = JCodecUtil.toBufferedImage( pic );

当我尝试运行它时,我得到NullPointerException如下:

When I try to run it, I get NullPointerException as follow:

线程"Thread-6"中的异常java.lang.NullPointerException 在org.jcodec.codecs.h264.H264Decoder $ FrameDecoder.decodeFrame(H264Decoder.java:82) 在org.jcodec.codecs.h264.H264Decoder.decodeFrame(H264Decoder.java:61) 在br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.test_readNals(JCodecPlayer.java:122) 在br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.processNAL(JCodecPlayer.java:69) 网址为br.com.grupogiga.security.xm.player.XMH264Player $ 1 $ 2.NALArrived(XMH264Player.java:143) 在br.com.grupogiga.security.xm.protocols.ProtocolParser.emitNALArrived(ProtocolParser.java:408) 在br.com.grupogiga.security.xm.protocols.ProtocolParser.run(ProtocolParser.java:121) 在java.lang.Thread.run(Thread.java:722)

Exception in thread "Thread-6" java.lang.NullPointerException at org.jcodec.codecs.h264.H264Decoder$FrameDecoder.decodeFrame(H264Decoder.java:82) at org.jcodec.codecs.h264.H264Decoder.decodeFrame(H264Decoder.java:61) at br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.test_readNals(JCodecPlayer.java:122) at br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.processNAL(JCodecPlayer.java:69) at br.com.grupogiga.security.xm.player.XMH264Player$1$2.NALArrived(XMH264Player.java:143) at br.com.grupogiga.security.xm.protocols.ProtocolParser.emitNALArrived(ProtocolParser.java:408) at br.com.grupogiga.security.xm.protocols.ProtocolParser.run(ProtocolParser.java:121) at java.lang.Thread.run(Thread.java:722)

我做错了什么?如何使用JCodec解码数据? 预先感谢.

What I'm doing wrong ?? How do I decode the data using JCodec ? Thanks in advance.

推荐答案

您确定要获取一个int数组吗?从您的打印输出来看,它似乎是一个字节数组.我建议不要做数组转换,也不要倒带. ByteBuffer.wrap已经将您放置在缓冲区的位置0. 00 00 01是NAL标记的开始,而FD是NAL类型btw.

Are you certain that you're getting an int array? It would appear to be a byte array from your print-out. I would suggest not doing the array conversion and also not doing a rewind; ByteBuffer.wrap will already put you at position 0 in the buffer. The 00 00 01 is a start of NAL marker and the FD is the NAL type btw.

这篇关于从整数数组解码H264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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