Skip to content

fix(VideoEncoder): remove the RVC4 H.264/H.265 need for correct timestamps - #2347

Merged
aljazdu merged 2 commits into
developfrom
fix/rvc4-video-encoder-timestamps
Dec 2, 2026
Merged

aljazdu merged 2 commits into
developfrom
fix/rvc4-video-encoder-timestamps

Conversation

@aljazdu

@aljazdu aljazdu commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

RVC4 H.264/H.265 needed correct device timestamps on input frames. Host-made frames without them got ≤40% of the bitrate (5-8 dB lower PSNR), and timestamps that went back stopped the output.

Specification

PTS = previous PTS + device-timestamp delta, else one frame interval of setFrameRate(). Host timestamps are not used. Camera streams keep the same PTS.

Dependencies & Potential Impact

RVC4 VideoEncoder only. No API or shared-type change.

Deployment Plan

Merge after the testable run passes.

Testing & Validation

New on-host test and video_encoder_test case. On RVC4 the case fails with develop firmware and passes with this one; it also passes on RVC2.

AI Usage

Assisted-by: Claude Code:claude-opus-5-5 clang-tidy clang-format

Submitted code was reviewed by a human: NO

The author is taking the responsibility for the contribution: YES

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved RVC4 H.264 and H.265 video timestamp handling. Frame timing uses valid intervals between consecutive device timestamps, with a configured frame-rate fallback when timestamps are missing, non-advancing, or outside the supported range.
    • Host timestamps are ignored for encoder timing, helping maintain consistent output when device timestamps restart or are unavailable.
  • Documentation
    • Clarified how encoder frame rates and device timestamps affect RVC4 video encoding, including fallback behavior.

@aljazdu aljazdu self-assigned this Dec 2, 2026
@aljazdu aljazdu added Medium impact The changes affect logic outside the diff testable Trigger PR testing, latest python build, and Core CI/CD labels Dec 2, 2026
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The RVC4 encoder now generates frame PTS from consecutive device timestamp intervals when they are valid. It uses the configured frame interval when timestamps are missing, non-advancing, or more than one hour apart. New on-host and on-device tests cover these cases.

Changes: RVC4 encoder PTS handling

Layer / File(s) Summary
PTS generation and unit validation
device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.hpp, device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.cpp, device/rvc4/CMakeLists.txt, tests/CMakeLists.txt, tests/src/onhost_tests/rvc4_video_encoder_pts_test.cpp
Adds VideoEncoderPts, which uses valid device timestamp differences to advance PTS and falls back to a frame interval otherwise. Registers the implementation and on-host tests. Tests cover timestamp selection, fallback, jumps, and frame-rate interval limits.
Encoder timestamp integration
device/rvc4/src/pipeline/node/rvc4/GstVaapiEncRvc4.hpp, device/rvc4/src/pipeline/node/rvc4/GstVaapiEncRvc4.cpp, device/rvc4/src/pipeline/node/VideoEncoder.hpp, device/rvc4/src/pipeline/node/VideoEncoder.cpp, include/depthai/pipeline/node/VideoEncoder.hpp
GstVaapiEnc uses VideoEncoderPts to set buffer PTS. The generic VideoEncoder copy path sets PTS to GST_CLOCK_TIME_NONE. The setFrameRate documentation describes timestamp selection and fallback behavior.
On-device timestamp comparisons
tests/src/ondevice_tests/video_encoder_test.cpp
Adds H.264 Main and H.265 Main tests that compare reference encodes with host-only, absent, and restarted timestamps. The tests check frame counts, PSNR, and encoded file size.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant GstVaapiEnc
  participant VideoEncoderPts
  participant Buffer
  GstVaapiEnc->>VideoEncoderPts: next(frame)
  VideoEncoderPts-->>GstVaapiEnc: generated PTS
  GstVaapiEnc->>Buffer: assign PTS
Loading

Suggested reviewers: aljazkonec1, asahtik

Merge Risk: Minimal · up to eee26

RVC4 H.264/H.265 encoding now derives frame timestamps from device timestamp intervals and falls back to the configured frame rate, with tests covering the main cases. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the RVC4 H.264/H.265 VideoEncoder change and the removal of its dependence on correct input timestamps, which matches the main change. The changeset replaces the device-timestamp-based…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the RVC4 H.264/H.265 VideoEncoder change and the removal of its dependence on correct input timestamps, which matches the main change. The changeset replaces the device-timestamp-based PTS logic with a new VideoEncoderPts generator that uses the device-timestamp delta or a frame-rate fallback. The title's 'fix' prefix and wording are slightly awkward ('need for correct timestamps'), but the title is specific and related to the primary change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

I hop past clocks that drift or stall,
A steady frame interval answers the call.
Device-time steps set PTS in flight,
One hare counts frames through day and night.
With tests in tow, I bound away.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 0476b274-1fcd-4089-a18c-f173bac1e8e8
Commits

Reviewing files that changed from the base of the PR and between 0f3e57c and eee2609.

Files selected for processing: 4

  • device/rvc4/src/pipeline/node/rvc4/GstVaapiEncRvc4.cpp
  • device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.cpp
  • device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.hpp
  • tests/src/onhost_tests/rvc4_video_encoder_pts_test.cpp

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: style
  • GitHub Check: Comment lint
Additional context used

Code guidelines: 1

AGENTS.md — auto-discovered
Path-based instructions: 1

Source excerpt: This repository is public.

CodeRabbit inference engine (AGENTS.md)

Files:

  • device/rvc4/src/pipeline/node/rvc4/GstVaapiEncRvc4.cpp
  • device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.cpp
  • device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.hpp
Learnings: 1

Common learnings

Learnt from: CR
Repo: luxonis/depthai-core

Timestamp: 2026-12-02T12:47:46.354Z
Learning: Source excerpt:
## Test

Every new node, message, feature and bug fix needs a test that exercises
the real behaviour. A change to a type that derives from `Buffer` needs a
serialization roundtrip test that runs on RVC2 and RVC4.
Learnt from: CR
Repo: luxonis/depthai-core

Timestamp: 2026-12-02T12:47:46.465Z
Learning: Applicability reference:
AGENTS.md: ## Rules that are easy to break
The full rule set is in the `depthai-cpp-review` skill
(`.agents/skills/depthai-cpp-review/SKILL.md`). Run it on each C++ change
before you open a PR.

Source excerpt:
# PART 1 — PROJECT RULES (highest priority)

## C. Build system

- **Formatting is enforced by CI, not by opinion.**
  `ci/check_format.sh <builddir>` fails on any diff after
  `--target clangformat`. Do not hand-format; do not fight the tool.
  Severity: MEDIUM
Learnt from: CR
Repo: luxonis/depthai-core

Timestamp: 2026-12-02T12:47:46.465Z
Learning: Applicability reference:
AGENTS.md: ## Rules that are easy to break
The full rule set is in the `depthai-cpp-review` skill
(`.agents/skills/depthai-cpp-review/SKILL.md`). Run it on each C++ change
before you open a PR.

Source excerpt:
# PART 1 — PROJECT RULES (highest priority)

## C. Build system

- **C++17 is the hard target.**
  Flag all features that use C++20 or later.
  Severity: HIGH
Cppcheck (2.22.0)

device/rvc4/src/pipeline/node/rvc4/VideoEncoderPts.cpp

[style] 45-45: The function 'getFrameRate' is never used.

(unusedFunction)

@aljazdu aljazdu added testable Trigger PR testing, latest python build, and Core CI/CD and removed testable Trigger PR testing, latest python build, and Core CI/CD labels Dec 2, 2026

@aljazkonec1 aljazkonec1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the nit is addressed and the CI re-run passes (last run: an rvc4-fwp vcpkg failure and an unrelated pytest flake), you can merge.

@aljazdu aljazdu added testable Trigger PR testing, latest python build, and Core CI/CD and removed testable Trigger PR testing, latest python build, and Core CI/CD labels Dec 2, 2026

@aljazkonec1 aljazkonec1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nit is fixed; after the CI passes, you can merge.

@aljazdu
aljazdu merged commit 4d2642c into develop Dec 2, 2026
80 checks passed
@aljazdu
aljazdu deleted the fix/rvc4-video-encoder-timestamps branch December 2, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Medium impact The changes affect logic outside the diff testable Trigger PR testing, latest python build, and Core CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants