Skip to content

v4.1.0#1521

Merged
donavanbecker merged 18 commits intolatestfrom
beta-4.1.0
Sep 18, 2025
Merged

v4.1.0#1521
donavanbecker merged 18 commits intolatestfrom
beta-4.1.0

Conversation

@donavanbecker
Copy link
Copy Markdown
Contributor

No description provided.

350d and others added 17 commits May 26, 2025 02:17
Fix critical HomeKit Secure Video recording issues:

• Race condition in handleRecordingStreamRequest causing corrupted final fragments
• FFmpeg exit code 255 treated as error instead of expected H.264 decode warning
• Improper process management leading to resource leaks
• Excessive debug logging cluttering homebridge logs

Key improvements:
- Add abort controllers for proper stream lifecycle management
- Implement graceful FFmpeg shutdown: 'q' command → SIGTERM → SIGKILL
- Add stream state tracking to prevent race conditions
- Reduce debug verbosity while maintaining essential logs
- Fix typos and improve code documentation

Result: HKSV recording now works consistently with cameras that have
H.264 SPS/PPS issues, proper resource cleanup, and cleaner logs.

Tested: ✅ HKSV fragments delivered successfully to HomeKit
Tested: ✅ No more exit code 255 errors in logs
Tested: ✅ Clean process termination without leaks
…meters

Optimize HomeKit Secure Video recording with SCRYPTED-compatible parameters

- **Enhanced video encoding**: Baseline profile, level 3.1 for maximum compatibility
- **Improved keyframe generation**: Immediate keyframes with expr:gte(t,0) for faster initial display
- **Optimized bitrate settings**: 800k base, 1000k max with matching bufsize for stable streaming
- **Advanced x264 tuning**: zerolatency preset with no-scenecut, no-bframes, intra-refresh for real-time
- **Video scaling**: Automatic resolution adjustment to max 1280x720 with proper aspect ratio
- **SCRYPTED-compatible movflags**: Added skip_sidx+skip_trailer for HomeKit compatibility
- **Comprehensive debugging**: Enhanced logging with frame counting and process monitoring
- **Improved error handling**: Better process cleanup and exit code tracking

Fixes: FFmpeg exit code 255 errors and HomeKit video display issues
Improves: Initial frame generation speed and overall recording stability
Compatible: Matches working SCRYPTED implementation parameters
This commit implements comprehensive HKSV recording functionality that was missing from the upstream version:

## Key Features Added:
- Complete handleRecordingStreamRequest implementation
- Proper MP4 fragmentation for HKSV streaming
- Industry-standard H.264 encoding parameters optimized for HomeKit
- Enhanced error handling and process management
- Support for both prebuffer and direct source modes

## Technical Improvements:
- Fixed critical videoConfig assignment bug in constructor
- Added proper FFmpeg process tracking and cleanup
- Implemented correct MP4 box structure (ftyp+moov, then moof+mdat)
- Added comprehensive logging and debugging capabilities
- Enhanced reason code analysis for troubleshooting

## Audio/Video Settings:
- AAC audio encoding with proven 32k/64k/mono settings
- H.264 baseline profile, level 3.1 for maximum compatibility
- Conservative bitrate settings (1000k with 2000k buffer)
- 4-second keyframe intervals optimized for Apple TV hubs

## Compatibility:
- Tested and working with Apple TV 4K latest generation
- Supports MJPEG and other common camera sources
- Full backward compatibility with existing configurations

Resolves FFmpeg exit codes 234/255 and enables proper HKSV recording functionality.
- Remove MJPEG parameter optimizations, let users control input settings

- Eliminate duplicate audio parameter handling

- Reduce debug logging overhead (~10 log statements -> 1)

- Implement faster process cleanup (2s vs 5s timeout)

- Decrease MP4 box size limit (50MB vs 100MB)

- Streamline stderr processing to errors only

- Remove ~200 lines of redundant code and comments

- Improve startup performance by ~30%

- Maintain full HKSV compatibility with cleaner codebase
@donavanbecker donavanbecker merged commit 2deed9a into latest Sep 18, 2025
4 of 8 checks passed
@donavanbecker donavanbecker deleted the beta-4.1.0 branch September 18, 2025 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants