Skip to content

fix(rtc-node): size NV12 and I420A chroma planes from the chroma height - #767

Open
ninglinLiu wants to merge 1 commit into
livekit:mainfrom
ninglinLiu:fix/nv12-i420a-plane-length
Open

ninglinLiu wants to merge 1 commit into
livekit:mainfrom
ninglinLiu:fix/nv12-i420a-plane-length

Conversation

@ninglinLiu

Copy link
Copy Markdown

Fixes #746

getPlaneLength computed the chroma planes of NV12 and I420A frames as chromaWidth * chromaWidth * 2. VideoFrame.fromOwnedInfo uses that length to copy frames out of native memory (video stream frames and VideoFrame.convert() results), so for non-square frames it read past the end of the native buffer (landscape, e.g. 1280x720 NV12: 1,740,800 bytes instead of 1,382,400) or truncated the frame (portrait).

This uses chromaHeight, matching getPlaneInfos and the I420 case.

Changes

  • getPlaneLength: use chromaWidth * chromaHeight for NV12 and I420A, and export it as @internal so it can be unit tested (not re-exported from index.ts).
  • video_frame.test.ts: checks I420/I420A/NV12 lengths for landscape, portrait and odd-sized frames, plus 1280x720 NV12.
  • Patch changeset for @livekit/rtc-node.

Testing

  • pnpm --filter @livekit/rtc-node test: the new tests pass; the NV12/I420A cases fail without the fix. (The e2e test files need a built livekit-server-sdk and are unchanged.)
  • eslint and prettier clean on the changed files.

getPlaneLength multiplied chromaWidth by itself for NV12 and I420A, so
VideoFrame.fromOwnedInfo copied too many bytes for landscape frames
(reading past the native buffer) and too few for portrait frames.

Fixes livekit#746
@changeset-bot

changeset-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4054b1b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/rtc-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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.

[rtc-node] NV12 and I420A frames copied from native code have the wrong length

1 participant