Skip to content

fix: for Homebase 3 & S3 Pro cameras#16

Closed
nguyening wants to merge 3 commits into
caplaz:mainfrom
nguyening:fix/h264-stream-handling
Closed

fix: for Homebase 3 & S3 Pro cameras#16
nguyening wants to merge 3 commits into
caplaz:mainfrom
nguyening:fix/h264-stream-handling

Conversation

@nguyening
Copy link
Copy Markdown

I have a Homebase 3 and a few S3 Pro cameras which have not been working particularly well with the native Eufy <> Homekit bridge. With this Scrypted plugin, I'm able to take snapshots from these cameras but streams didn't seem to work until I fixed the NAL type names & bumped the analysis time.

I'm happy to adjust the branch if this is desirable on the mainline, but I'm mainly putting this out there to help others with these battery-powered cameras.

nguyening and others added 3 commits March 25, 2026 12:03
Update getNALTypeName() to use accurate H.264/AVC NAL unit type names:
- Type 1: "Non-IDR Slice" (was incorrectly "P-slice")
- Type 2-4: Data Partition A/B/C (was missing)
- Type 5: "IDR Slice" (was "IDR-slice")
- Type 14: "Prefix NAL" (was incorrectly "Data Partitioning")
- Added missing types: 0, 10-13, 15, 19, 20

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix SPS/PPS caching to store only individual NAL units instead of
  entire buffers, preventing "missing picture in access unit" errors
- Add -err_detect ignore_err to FFmpeg to tolerate non-fatal H.264
  parsing errors (e.g., oversized SEI payloads)
- Add keyframe interval tracking to help diagnose prebuffer sync issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Increase FFmpeg analyzeduration/probesize from 5s to 15s to handle
  slow keyframe intervals (Eufy cameras can have 9+ second intervals)
- Add +genpts fflags for proper timestamp generation
- Cache last IDR keyframe and send to new clients immediately
- This prevents "Unable to find sync frame in rtsp prebuffer" errors
- Remove duplicate client connect/disconnect log messages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@acerbetti acerbetti marked this pull request as ready for review April 9, 2026 00:45
mia-pa pushed a commit that referenced this pull request Apr 10, 2026
The stream-service FFmpeg config was updated to use 15000000 (15s) for
analyzeduration and probesize to handle Eufy battery cameras with long
keyframe intervals, but the unit test was still asserting the old 5000000
value. Update the test expectations to match.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@acerbetti
Copy link
Copy Markdown
Member

PR Review: fix for Homebase 3 & S3 Pro cameras

Thanks for the detailed PR, @nguyening! The fixes here are genuinely useful and address real issues with battery-powered cameras. Here's a thorough review:


What works well

✅ NAL type name corrections (h264-parser.ts) — Accurate, spec-correct fix. The original table had fundamentally wrong names (type 2 as "B-slice", type 3 as "I-slice") that were misleading for debugging. No functional impact but good hygiene.

✅ SPS/PPS caching fix (stream-server.ts) — This is the most impactful fix. Caching the entire buffer instead of just the individual NAL unit is a real bug: when a buffer contains multiple NAL units (e.g., SPS + PPS in the same packet), sending the whole buffer as "SPS" to a new client injects duplicate/wrong units that cause missing picture in access unit errors. The fix to extract and prepend a clean start code is correct.

✅ Cached IDR keyframe for new clients — Sending SPS + PPS + last IDR to new clients is the right approach for cameras with slow keyframe intervals. The order (SPS → PPS → IDR) is correct for decoder initialization.

✅ Keyframe interval diagnostics — The lastKeyframeTime tracking and warning log is useful for diagnosing prebuffer sync failures.

-err_detect ignore_err + +genpts — These FFmpeg flags are well-motivated for Eufy streams with oversized SEI payloads and missing timestamps.


Issues blocking merge

❌ Merge conflicts — PR needs rebase onto current main
This PR was based on an older main. Since then, several significant changes landed (H.265/HEVC support, codec auto-detection in FFmpeg args, stream-server refactors). mergeStateStatus is DIRTY. The PR cannot be merged as-is.

stream-service.ts changes are incompatible with current main
Current main uses dynamic codec detection:

const inputFormat = FFmpegUtils.toFFmpegFormat(eufyCodec); // "h264" or "hevc"

The PR replaces this with a hardcoded "-f", "h264" and removes -hide_banner -loglevel error. The analyzeduration/probesize increase and the new flags (+genpts, -err_detect ignore_err) are desirable, but they need to be adapted to the current codec-aware FFmpeg config rather than reverting it.

❌ H.265 SPS/PPS caching has the same bug but is not addressed
Current main caches H.265 VPS/SPS/PPS as full buffers too (types 32, 33, 34). The same "cache entire buffer" bug applies there and should be fixed with the same pattern.

❌ IDR keyframe caching is H.264-only (type 5)
The cachedKeyframe logic only extracts H.264 IDR (NAL type 5). For H.265 streams, IDR frames use types 19 (IDR_W_RADL) and 20 (IDR_N_LP), which are not covered. H.265 cameras with long keyframe intervals will still experience the "Unable to find sync frame" issue.


Minor concerns

  • Removed connection-manager.ts connect/disconnect logs — These are useful for diagnosing TCP connection issues. Consider keeping them at debug level rather than removing entirely.
  • 15s analyzeduration increases stream startup latency — This is a valid trade-off for cameras with 9+ second keyframe intervals, but it makes all cameras slower to start. Consider making this configurable via device settings, or only applying the longer duration when a prior stream attempt failed.

Suggested next steps

  1. Rebase onto current main to resolve conflicts.
  2. Keep the codec-aware FFmpeg detection in stream-service.ts — only add the new flags (+genpts, -err_detect ignore_err) and update the analyzeduration/probesize values on top of the existing structure.
  3. Extend the SPS/PPS caching fix to H.265 — apply the same "cache individual NAL unit + start code" fix for VPS (type 32), SPS (type 33), PPS (type 34).
  4. Extend cachedKeyframe to H.265 — detect IDR frames with NAL types 19 and 20 in addition to type 5.
  5. Restore connect/disconnect logging at debug level in connection-manager.ts.

The core ideas here are solid and worth integrating. Happy to collaborate on a rebased version that covers H.265 too.

@mia-pa
Copy link
Copy Markdown
Collaborator

mia-pa commented May 9, 2026

Closing as stale - the stream handling improvements from this PR are already incorporated in main via the audio stream PR (#21) and other fixes. The main branch now includes:

  • Larger analyzeduration/probesize values (5s)
  • +genpts+nobuffer flags for timestamp handling
  • H.265 codec detection
  • Improved error handling

If specific issues remain with S330 cameras, please open a new issue with fresh logs.

@mia-pa mia-pa closed this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants