我正在尝试从相机解码H264原始协议,但我在使用Jcodec H264Decoder时遇到了一些问题。我从相机收到一个整数数组。下面是数据样本:
阵列: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 ......更多
我正在使用的代码是:
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如下:
线程“Thread-6”中的异常java.lang.NullPointerException 在org.jcodec.codecs.h264.H264Decoder $ FrameDecoder.decodeFrame(H264Decoder.java:82) 在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) 在java.lang.Thread.run(Thread.java:722)
我做错了什么?如何使用JCodec解码数据? 提前谢谢。
答案 0 :(得分:0)
在我看来,这不是你自己的错,而是内部的JCodec错误。您可以查看their issue tracker上的问题,看看是否已知。如果没有,您可能想为此创建一个问题。提供堆栈跟踪和尽可能多的信息。
答案 1 :(得分:0)
您确定要获得一个int数组吗?它看起来像是打印输出的字节数组。我建议不要进行数组转换,也不要做倒带; ByteBuffer.wrap已经将你放在缓冲区的第0位。 00 00 01是NAL标记的开始,FD是NAL类型btw。