src/main/java/org/jcodec/codecs/h264/H264Utils.java
public static ByteBuffer encodeMOVPacket(ByteBuffer avcFrame) {

        ByteBuffer dup = avcFrame.duplicate();

        List<ByteBuffer> list = new ArrayList<ByteBuffer>();
        ByteBuffer buf;
        int totalLen = 0;
        while ((buf = H264Utils.nextNALUnit(dup)) != null) {
            list.add(buf);
            totalLen += buf.remaining();
        }
        ByteBuffer result = ByteBuffer.allocate(list.size() * 4 + totalLen);
        for (ByteBuffer byteBuffer : list) {
            result.putInt(byteBuffer.remaining());
            result.put(byteBuffer);
        }
        result.flip();
        return result;
    }
public static ByteBuffer encodeMOVPacket(ByteBuffer avcFrame) {

        ByteBuffer dup = avcFrame.duplicate();

        List<ByteBuffer> list = new ArrayList<ByteBuffer>();
        ByteBuffer buf;
        int totalLen = 0;
        while ((buf = H264Utils.nextNALUnit(dup)) != null) {
            list.add(buf);
            totalLen += buf.remaining();
        }
        ByteBuffer result = ByteBuffer.allocate(list.size() * 4 + totalLen);
        for (ByteBuffer byteBuffer : list) {
            result.putInt(byteBuffer.remaining());
            result.put(byteBuffer);
        }
        result.flip();
        return result;
    }
public static ByteBuffer encodeMOVPacket ( ByteBuffer avcFrame ) { ByteBuffer dup = avcFrame . duplicate ( ) ; List < ByteBuffer > list = new ArrayList < ByteBuffer > ( ) ; ByteBuffer buf ; int totalLen = 0 ; while ( ( buf = H264Utils . nextNALUnit ( dup ) ) != null ) { list . add ( buf ) ; totalLen += buf . remaining ( ) ; } ByteBuffer result = ByteBuffer . allocate ( list . size ( ) * 4 + totalLen ) ; for ( ByteBuffer byteBuffer : list ) { result . putInt ( byteBuffer . remaining ( ) ) ; result . put ( byteBuffer ) ; } result . flip ( ) ; return result ; }
Encodes AVC frame in ISO BMF format. Takes Annex B format.

Scans the packet for each NAL Unit starting with 00 00 00 01 and replaces
this 4 byte sequence with 4 byte integer representing this NAL unit
length.

@param avcFrame
AVC frame encoded in Annex B NAL unit format
Encodes AVC frame in ISO BMF format . Takes Annex B format .