Skip to content

Commit

Permalink
homekit: fix annexb detection
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 2, 2024
1 parent 4846822 commit f2de58f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions plugins/homekit/src/types/camera/camera-recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,29 @@ async function checkMp4StartsWithKeyFrame(console: Console, mp4: Buffer) {
await timeoutPromise(1000, new Promise(resolve => cp.on('exit', resolve)));
const h264 = Buffer.concat(buffers);
let offset = 0;
let countedZeroes = 0;
while (offset < h264.length - 6) {
if (h264.readInt32BE(offset) !== 1) {
const byte = h264[offset];
if (byte === 0) {
countedZeroes = Math.min(4, countedZeroes + 1);
offset++;
continue;
}
offset += 4;

if (countedZeroes < 2) {
countedZeroes = 0;
offset++
continue;
}

countedZeroes = 0;
if (byte !== 1) {
offset++;
continue;
}

offset++;

let naluType = h264.readUInt8(offset) & 0x1f;
if (naluType === NAL_TYPE_FU_A) {
offset++;
Expand Down

0 comments on commit f2de58f

Please sign in to comment.