Skip to content

fix: encode still-video clips with BT.709 and tag the output - #363

Merged
rponeawa merged 1 commit into
hypit-ai:mainfrom
HEOJUNFO:fix/still-video-bt709
Oct 8, 2026
Merged

rponeawa merged 1 commit into
hypit-ai:mainfrom
HEOJUNFO:fix/still-video-bt709

Conversation

@HEOJUNFO

Copy link
Copy Markdown

Follow-up to #342, for the same issue in the local media Provider's render-still-video path.

Problem

executeRenderStillVideo (packages/media-execution/src/execute.ts) encodes authored PNG/JPEG pictures with -pix_fmt yuv420p (the multi-picture path also uses format=yuv420p). It doesn't choose a conversion matrix or write any color metadata. So FFmpeg converts with BT.601 and leaves the stream as unknown / unknown / unknown / unknown.

How an untagged stream is decoded depends on the player. I encoded a solid #20C040 (32, 192, 64) picture with the current argv and decoded the first frame in Chrome through a <video> → canvas. HyperFrames composites clips the same way (<video> in document.ts).

picture size current main this PR
640×360 32, 191, 65 33, 192, 65
1280×720 20, 169, 62 33, 192, 65
1920×1080 20, 169, 62 33, 192, 65

Chrome assumes BT.601 for untagged SD video but BT.709 for HD, so any HD still clip shifts color. The same happens in other players and platform transcoders. With FFmpeg decoding the SMPTE HD bars as BT.709, the current output scores 28.7 dB PSNR against the source; this PR's output scores 41.9 dB.

Change

Both still paths now end with the encode tail from #342:

scale=out_color_matrix=bt709:out_range=tv,format=yuv420p,setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709:range=tv

In the multi-picture path it replaces the per-segment format=yuv420p before concat. The frame-count, timing, and letterbox logic is unchanged.

Tests

  • New test in packages/provider-media-local/test/provider.test.ts. It renders a 1280×720 solid picture through the single-picture and the two-segment paths. It then checks that the stream is tagged tv,bt709,bt709,bt709 and that the decoded color is within 3 of the source when decoded as BT.709. On main it fails with actual: 'unknown,unknown,unknown,unknown'.
  • node --import tsx --test packages/provider-media-local/test/*.test.ts packages/media-execution/test/*.test.ts: 28/28 pass. This includes the existing still, spread and 24 fps spread cases.
  • pnpm check is clean.
  • Environment: FFmpeg 8.0.1, macOS arm64. The Chrome numbers above are from Google Chrome via Playwright.

🤖 Generated with Claude Code

render-still-video converted authored sRGB pictures to yuv420p with
FFmpeg's default BT.601 matrix and wrote no color metadata. Players and
Chromium decode untagged HD video as BT.709, so an HD still clip shifted
color, e.g. #20C040 came back as (20,169,62) in a Chrome <video>, which
is also how HyperFrames composites these clips.

Use the same encode tail as the HyperFrames local renderer (hypit-ai#342) for
the single-picture and the multi-picture paths, and add a test that
checks the stream tags and the decoded color of both paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rponeawa
rponeawa merged commit 31c358d into hypit-ai:main Oct 8, 2026
SanHsien pushed a commit to SanHsien/hypit that referenced this pull request Oct 24, 2026
…i#363)

render-still-video converted authored sRGB pictures to yuv420p with
FFmpeg's default BT.601 matrix and wrote no color metadata. Players and
Chromium decode untagged HD video as BT.709, so an HD still clip shifted
color, e.g. #20C040 came back as (20,169,62) in a Chrome <video>, which
is also how HyperFrames composites these clips.

Use the same encode tail as the HyperFrames local renderer (hypit-ai#342) for
the single-picture and the multi-picture paths, and add a test that
checks the stream tags and the decoded color of both paths.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 31c358d)
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.

2 participants