                     unit_header = 3;
                     unit_start = nalu.position;
                     unit_type = nalu.readByte() & 0x1F;
+                    // NDR or IDR NAL unit
                     if(unit_type == 1 || unit_type == 5) { break; }
                 } else {
                     nalu.position -= 3;

            } else if (pps == -1) {
                throw new Error("No PPS NAL unit found in this stream.");
            }
            // Write startbyte, profile, compatibility and level.
            var avcc:ByteArray = new ByteArray();
            avcc.writeByte(0x01);
            avcc.writeBytes(nalu,units[sps].start+1, 3);
            // 111111 + NALU bytesize length (4?)
            avcc.writeByte(0xFF);
            // Number of SPS, Bytesize and data.
            avcc.writeByte(0xE1);
            avcc.writeShort(units[sps].length);
            avcc.writeBytes(nalu,units[sps].start,units[sps].length);
            // Number of PPS, Bytesize and data.
            avcc.writeByte(0x01);
            avcc.writeShort(units[pps].length);
            avcc.writeBytes(nalu,units[pps].start,units[pps].length);
            // Grab profile/level
            avcc.position = 1;

                    unit_header = 4;
                    unit_start = nalu.position;
                    unit_type = nalu.readByte() & 0x1F;
                    // NDR or IDR NAL unit
                    if(unit_type == 1 || unit_type == 5) { break; }
                // Match three-byte startcodes
                } else if((window & 0xFFFFFF00) == 0x100) {
