diff --git a/lib/transmuxer/h264.js b/lib/transmuxer/h264.js index ee772dd681..88f3e919e4 100644 --- a/lib/transmuxer/h264.js +++ b/lib/transmuxer/h264.js @@ -175,7 +175,7 @@ shaka.transmuxer.H264 = class { static parseFrame(nalus) { const H264 = shaka.transmuxer.H264; let isKeyframe = false; - let data = new Uint8Array([]); + const nalusData = []; const spsNalu = nalus.find((nalu) => { return nalu.type == H264.NALU_TYPE_SPS_; }); @@ -240,13 +240,14 @@ shaka.transmuxer.H264 = class { naluLength[1] = (size >> 16) & 0xff; naluLength[2] = (size >> 8) & 0xff; naluLength[3] = size & 0xff; - data = shaka.util.Uint8ArrayUtils.concat( - data, naluLength, nalu.fullData); + nalusData.push(shaka.util.Uint8ArrayUtils.concat( + naluLength, nalu.fullData)); } } - if (!data.byteLength) { + if (!nalusData.length) { return null; } + const data = shaka.util.Uint8ArrayUtils.concat(...nalusData); return { data, isKeyframe, diff --git a/lib/transmuxer/h265.js b/lib/transmuxer/h265.js index 07335e1547..601a9cc907 100644 --- a/lib/transmuxer/h265.js +++ b/lib/transmuxer/h265.js @@ -590,7 +590,7 @@ shaka.transmuxer.H265 = class { static parseFrame(nalus) { const H265 = shaka.transmuxer.H265; let isKeyframe = false; - let data = new Uint8Array([]); + const nalusData = []; let hvcSample = false; for (const nalu of nalus) { let push = false; @@ -636,13 +636,14 @@ shaka.transmuxer.H265 = class { naluLength[1] = (size >> 16) & 0xff; naluLength[2] = (size >> 8) & 0xff; naluLength[3] = size & 0xff; - data = shaka.util.Uint8ArrayUtils.concat( - data, naluLength, nalu.fullData); + nalusData.push(shaka.util.Uint8ArrayUtils.concat( + naluLength, nalu.fullData)); } } - if (!data.byteLength) { + if (!nalusData.length) { return null; } + const data = shaka.util.Uint8ArrayUtils.concat(...nalusData); return { data, isKeyframe, diff --git a/lib/util/mp4_generator.js b/lib/util/mp4_generator.js index cb44a7db26..af904c1178 100644 --- a/lib/util/mp4_generator.js +++ b/lib/util/mp4_generator.js @@ -1037,10 +1037,8 @@ shaka.util.Mp4Generator = class { mdat_(streamInfo) { const Mp4Generator = shaka.util.Mp4Generator; const samples = streamInfo.data ? streamInfo.data.samples : []; - let bytes = new Uint8Array([]); - for (const sample of samples) { - bytes = shaka.util.Uint8ArrayUtils.concat(bytes, sample.data); - } + const allData = samples.map((sample) => sample.data); + const bytes = shaka.util.Uint8ArrayUtils.concat(...allData); return Mp4Generator.box('mdat', bytes); }