Fix HKSV recording stream closure with prebuffer integration and H.264 optimization#1511
Merged
donavanbecker merged 3 commits intobeta-4.1.0from Sep 10, 2025
Merged
Fix HKSV recording stream closure with prebuffer integration and H.264 optimization#1511donavanbecker merged 3 commits intobeta-4.1.0from
donavanbecker merged 3 commits intobeta-4.1.0from
Conversation
…4 optimization Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] HKSV recording closes with “reason: 6” right after motion on camera index 0 (“Door”) with prebuffer enabled — previous TypeError fixed by yielding prebuffer fragments, but stream still stops
Fix HKSV recording stream closure with prebuffer integration and H.264 optimization
Sep 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a critical issue where HomeKit Secure Video (HKSV) recording would close immediately with "reason: 6" (STREAM FORMAT INCOMPATIBILITY) when prebuffer is enabled on cameras.
Problem
Users with prebuffer-enabled cameras experienced HKSV recording failures:
The issue occurred because:
handleRecordingStreamRequest()didn't ensure prebuffer was initialized before usethis.preBuffercould be undefined when prebuffer was enabled, causing stream format incompatibilitySolution
Prebuffer Integration Fix
handleRecordingStreamRequest()startPreBuffer()is called before attempting to use prebuffer dataHKSV-Compatible H.264 Parameters
maxrateandbufsizecalculations from configurationultrafasttoveryfastfor better encoding stabilityEnhanced Error Handling & Diagnostics
Testing
The fix has been validated with:
RecordingDelegateAfter the fix, users should see continuous HKSV recording:
Fixes #1509.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
192.168.1.100ffmpeg -hide_banner -rtsp_transport tcp -i rtsp://admin:password@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0 -f lavfi -i anullsrc=cl=mono:r=32000 -f mp4 -acodec aac -profile:a aac_low -ar 32000 -b:a 64k -ac 1 -sn -dn -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level:v 3.1 -preset veryfast -tune zerolatency -b:v 2048k -maxrate 2457k -bufsize 4096k -g 30 -keyint_min 15 -sc_threshold 0 -force_key_frames expr:gte(t,n_forced*1) -r 15 -movflags frag_keyframe+empty_moov+default_base_moof+omit_tfhd_offset pipe:1(packet block)ffmpeg -hide_banner -rtsp_transport tcp -i rtsp://admin:password@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0 -f lavfi -i anullsrc=cl=mono:r=32000 -f mp4 -acodec aac -profile:a aac_low -ar 32000 -b:a 64k -ac 1 -sn -dn -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level:v 3.1 -preset veryfast -tune zerolatency -b:v 1000k -maxrate 1200k -bufsize 2000k -g 30 -keyint_min 15 -sc_threshold 0 -force_key_frames expr:gte(t,n_forced*1) -r 15 -movflags frag_keyframe+empty_moov+default_base_moof+omit_tfhd_offset pipe:1(packet block)esm.ubuntu.com/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.