简体   繁体   中英

Decode H264 From Array of Integers

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 01 61 E4 80 6F D3 5B 76 97 DF 04 3A EF 54 97 0E D9 F5...more

The code I'm using is :

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 );

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

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)

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

That looks to me like no fault of your own, but rather an internal JCodec bug. You can check through the issues on their issue tracker to see if this is known. If not, you may want to create an issue for this. Provide the stack trace and as much information as you can.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM