Fix audio/video decode for newer H.265 3-lens devices (IMA-ADPCM, RTP timestamps, codec detection) - #5
Open
Vasang123 wants to merge 2 commits into
Open
Fix audio/video decode for newer H.265 3-lens devices (IMA-ADPCM, RTP timestamps, codec detection)#5Vasang123 wants to merge 2 commits into
Vasang123 wants to merge 2 commits into
Conversation
- Audio: correct IMA-ADPCM decode (was assumed G.711 A-law), fix RTP timestamp reset bug, fix packet header offset - gated on audioBits==16 so older 8-bit G.711 devices keep their original behavior untouched - Video: fix H264/H265 codec misdetection (staged detection, unambiguous VCL types checked first), fix header offset, fix RTP timestamp (wall-clock based instead of raw device clock), fix marker bit per RFC 6184 (only on last NAL of access unit) - Add --no-video flag to skip the HEVC->H264 transcoder for audio-only deployments
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.
Summary
Fixes several real bugs affecting newer H.265 3-lens V380 devices, found and fixed
while debugging a dual-camera Frigate NVR integration. Audio was completely garbled and
video intermittently corrupted/dropped on this device family; both are now working
reliably.
Audio
claims and the code assumed. Confirmed against
jericjan/v380-audio-player's
pyima.py, itself based on acida/pyima. Added aproper IMA-ADPCM decoder, then re-encode to real A-law so nothing downstream (SDP,
RTSP consumers) needs to change.
AES-ECB decryption.
instead of increasing, causing playback to glitch once then go silent.
Video
NAL header) ran before the H265 check on the same byte, and real H265 headers
frequently satisfy the H264 range by coincidence - silently routing real H265 frames
around the transcoder and sending raw HEVC labeled as H264.
* 90),which produced multi-billion-tick jumps and caused clients to drop the connection
every ~10-15s.
only the last NAL of an access unit, per RFC 6184.
New flag
--no-video: skips starting the HEVC->H264 transcoder entirely, for deploymentsthat only need this instance's audio track (video coming from the camera's own
native RTSP instead). Avoids burning CPU on an unused encode.
Backward compatibility
The two changes with the widest blast radius are gated rather than unconditional:
audioBits==16(read from thelogin handshake). Devices reporting
audioBits==8(older G.711 cameras) keep theoriginal 20-byte offset and pass-through behavior untouched.
what real video frames actually use, and real H265 headers essentially never produce
them under the H264 5-bit reading - before falling back to the (now reordered)
broader H264/H265 range checks.
I don't have access to the older camera hardware (referenced as Camera A/B/C in the
README) to test directly, so this gating is reasoned from the protocol fields rather
than verified against real older-device hardware. Flagging that explicitly in case
anyone hitting this PR does have one of those units to test against.
Testing
Validated against a dual-cam (2-lens PTZ) unit — see Camera D entry added to the
README, running both units simultaneously through Frigate NVR: clean video (no more
corruption/dropped frames), clean continuous audio, stable RTSP connections over
extended runs (zero reconnects vs. one dropping every ~10-15s before the timestamp fix).
Note
These fixes were developed with AI assistance during a live debugging session against real hardware; noted in the README as well. Some results may vary across devices depending on internet connection and stability.