diff --git a/plugins/prebuffer-mixin/src/au.ts b/plugins/prebuffer-mixin/src/au.ts index 162425c8b..476dec7b2 100644 --- a/plugins/prebuffer-mixin/src/au.ts +++ b/plugins/prebuffer-mixin/src/au.ts @@ -29,11 +29,8 @@ export function createAUHeader( // Combine size and index into a single value const combinedValue = (frameSize << indexLength) | auIndex; - // Convert to bytes (little-endian within the multi-byte value) - const header = new Buffer(totalBytes); - for (let i = 0; i < totalBytes; i++) { - header[i] = (combinedValue >> ((totalBytes - 1 - i) * 8)) & 0xFF; - } + const header = Buffer.alloc(totalBytes); + header.writeUintBE(combinedValue, 0, totalBytes); return header; } diff --git a/plugins/prebuffer-mixin/src/flv.ts b/plugins/prebuffer-mixin/src/flv.ts index 50b5f1a05..ce6df4355 100644 --- a/plugins/prebuffer-mixin/src/flv.ts +++ b/plugins/prebuffer-mixin/src/flv.ts @@ -224,10 +224,7 @@ function parseNALUUnits(buffer: Buffer, offset: number, length: number, naluLeng } while (pos + naluLengthSize <= offset + length) { - let naluLength = 0; - for (let i = 0; i < naluLengthSize; i++) { - naluLength = (naluLength << 8) | buffer[pos + i]; - } + const naluLength = buffer.readUintBE(pos, naluLengthSize); pos += naluLengthSize; if (naluLength === 0) {