Skip to content

Video capture: x264 lossless is really lossless now, and FFV1 stops warning about its pixel format (#1662) - #1677

Merged
ccoventry merged 6 commits into
devfrom
fix/lossless-pixel-formats-1662
Dec 4, 2026
Merged

ccoventry merged 6 commits into
devfrom
fix/lossless-pixel-formats-1662

Conversation

@ccoventry

@ccoventry ccoventry commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Release note: Fixed: Video capture mode's "x264 lossless" codec is now really lossless (it was quietly converting to YUV), FFV1 no longer logs a pixel-format warning, and HUD takes captured with the old x264 option render again.

Closes #1662

What changed

CaptureCodec::args (native/src/patch/types.rs) asked FFmpeg for -pix_fmt gbrp with FFV1 and x264. Neither encoder takes it, so FFmpeg picked its own format and only printed a warning:

Codec Before FFmpeg actually wrote After
Ut Video -c:v utvideo -pix_fmt gbrp gbrp unchanged
FFV1 -c:v ffv1 -level 3 -pix_fmt gbrp bgr0 (lossless, with a warning) -c:v ffv1 -level 3 -pix_fmt bgr0
x264 lossless -c:v libx264 -qp 0 -pix_fmt gbrp yuv444p, not lossless -c:v libx264rgb -qp 0 -pix_fmt bgr24
Uncompressed -c:v rawvideo -pix_fmt bgr24 bgr24 unchanged

FFV1 files come out exactly as before (it was already auto-picking bgr0); only the warning goes. x264 lossless now uses libx264rgb, the RGB encoder, since plain libx264 only takes YUV. Container stays video.avi for every codec (scanner::VIDEO_FILE); no .mp4 is involved. UI labels and setting ids are unchanged.

Old takes: main streams captured with the old x264 option (yuv444p) still render. HUD takes did not: their hudalpha is yuv444p too, and the HUD merge's extractplanes=r has no red plane to take from YUV, so FFmpeg stopped the render ("Requested planes not available"; true on dev before this PR too). The merge is now [1:v]format=gbrp,extractplanes=r[alpha] in one shared constant used by the one-piece and segmented renders (renderer/ffmpeg_args.rs, renderer/segment_plan.rs); for RGB alpha (BMP, Ut Video, FFV1, x264 RGB) the conversion changes no pixel. An old take's matte is still only as good as its lossy YUV capture.

Tests:

  • types_capture_codec_tests.rs: an FFmpeg round trip per codec with codec.args() the way HLAE pipes frames (no "Incompatible pixel format", framemd5 equal to the input); every -pix_fmt is one its encoder lists; x264 uses libx264rgb; FFV1 asks for bgr0.
  • ffmpeg_args.rs: a_hud_take_renders_with_a_yuv_or_an_rgb_alpha_video runs the renderer's real HUD inputs and merge on a yuv444p alpha (renders) and an RGB alpha (same frames as before).
  • The FFmpeg tests skip (pass) where no FFmpeg runs, using the shared test_support::test_ffmpeg() (DODSTUDIO_TEST_FFMPEG, else ffmpeg on PATH), which the take checks and preview frame tests now share instead of keeping their own copies. A DODSTUDIO_TEST_FFMPEG that doesn't run now fails them instead of skipping. Only libx264rgb (and libx264 for the old-take case) may be missing, decided from ffmpeg -encoders; the round trip pipes both bgr24 and bgra and needs at least three codecs to run. They don't run in CI yet ([Chore] FFmpeg-gated Rust tests never run in CI #1687).

docs/direct_to_video_capture.md notes the old x264 size figure was lossy and gives new measurements; the take_frames.rs comment no longer says HLAE's codecs are all intra-only.

Test done

  • Pipe replay of HLAE 2.192.4's exact command (prefix from AfxHookGoldSrc/filming.cpp, see Test direct-to-video capture with FFmpeg 9 (HLAE builds the input arguments) #1660: ffmpeg -f rawvideo -pixel_format {bgr24|bgra} -loglevel repeat+level+warning -framerate 120 -video_size 320x240 -i pipe:0 -vf setsar=sar=1/1,vflip <codec args> video.avi), 60 noisy test-pattern frames piped in as bgr24 and as bgra, on FFmpeg 7.1.1, 8.1.4 and 9.1 (BtbN). Round trip checked with framemd5 (decoded to bgr24) against the vflipped input:

    • Old args: FFV1 warns "Incompatible pixel format 'gbrp'... auto-selecting 'bgr0'" (bit-exact); x264 warns "auto-selecting 'yuv444p'" and is not bit-exact, on all three versions.
    • New args: all 4 codecs x 2 input formats x 3 versions exit 0, no warnings, 60/60 frames, bit-exact. Output streams: utvideo gbrp, ffv1 bgr0, h264 High 4:4:4 Predictive gbrp, rawvideo bgr24.
  • In game, Brain account, HLAE 2.192.4, test-fixtures/ci_fixture.dem, mirv_movie_separate_hud 1, -afxForceAlpha8 1, 120 fps, one ~4 s take per codec, via game_probe.py and the hook's remote pipe:

    Install Codec all / hudcolor / hudalpha (ffprobe) Frames vs wav
    PRE FFV1 ffv1 bgr0 x3 413 = 3.442 s (wav 3.442)
    PRE x264 lossless h264 High 4:4:4 Predictive gbrp x3 352 = 2.933 s (wav 2.933)
    POST FFV1 ffv1 bgr0 x3 402 = 3.350 s (wav 3.350)
    POST x264 lossless h264 High 4:4:4 Predictive gbrp x3 395 = 3.292 s (wav 3.292)

    No "Incompatible pixel format" in the logs, no crash. Both HUD streams carry content (red channel up to 255). Each take rendered to ProRes 422 (main) and through the HUD merge to ProRes 4444, all exit 0. Capture speed against Ut Video was not measured in game.

  • Old x264 HUD takes, in game: the same set-up with the pre-PR args (-c:v libx264 -qp 0 -pix_fmt gbrp) on PRE (151 frames) and POST (65): all three streams yuv444p, and HLAE's console logged FFmpeg's "Incompatible pixel format" warning (so the new takes' clean logs mean something). Their HUD passes now render to ProRes 4444 with the new merge. Looked at by eye, 6x crops composited over the main stream for all six takes (old x264, FFV1, x264 RGB on PRE and POST): the crosshair, the only HUD element this demo shows, has clean edges, no fringe and nothing see-through. Stills kept out of the repo in local\review-images\1662\.

  • FFmpeg tests in cargo test pass with DODSTUDIO_TEST_FFMPEG set to 7.1.1, 8.1.4 and 9.1. On the old code, the round trip test fails (FFV1 "Incompatible pixel format") and the HUD test fails ("Requested planes not available"), checked by putting the old args and graph back.

  • Size and speed, 600 frames of a real 1280x720 BMP capture (1,582 MB raw), FFmpeg 9.1: Ut Video 806 MB (~950 fps), FFV1 705 MB, libx264rgb 681 MB (~65 fps), old libx264 yuv444p 417 MB (~67 fps, lossy).

  • cargo test -p native (2,051 passed, after merging dev), clippy (-p native --all-targets -D warnings, 1.98.1) and rustfmt clean. Not tested in VEGAS.

Decisions

  • FFV1 bgr0, not gbrp10 or similar: FFV1 has no 8-bit planar RGB, bgr0 is 8-bit, bit-exact, and is what files already were. A 10-bit format would grow files for nothing.
  • libx264rgb with bgr24 (HLAE's own frame format; bgra input converts losslessly in RGB).
  • x264 lossless stays truly lossless though its files grow ~60% (now about the size of FFV1): the owner chose that.

Follow-ups filed from the review

Other open PRs

#1390 touches native/src/patch/types.rs but not CaptureCodec; no interaction.

🤖 Generated with Claude Code

…1662)

FFmpeg refused -pix_fmt gbrp for FFV1 and libx264 and picked its own
format with a warning; libx264's pick (yuv444p) was not lossless. Each
codec now asks for an RGB format its encoder accepts, checked bit-exact
through HLAE's exact pipe command on FFmpeg 7.1, 8.1 and 9.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ccoventry and others added 2 commits December 4, 2026 00:08
…fore extractplanes) (#1662)

A hudalpha captured with the old x264 lossless option is yuv444p, and
extractplanes=r alone stops the render ("Requested planes not
available"). One shared graph for the three places; a no-op for RGB
alpha. test_ffmpeg() moves to test_support for the tests that share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts, comment fixes (#1662)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry

Copy link
Copy Markdown
Owner Author

Review findings

Fable review of 803b340 (SAFE WITH FOLLOW-UPS). The owner kept x264 lossless truly lossless (libx264rgb).

# Finding Severity Outcome
1 HUD takes captured with the old x264 lossless option cannot render: their yuv444p hudalpha has no red plane for extractplanes=r medium Fixed in 96843ad: format=gbrp before extractplanes=r in one shared graph for the one-piece and segmented renders, PR body corrected, test a_hud_take_renders_with_a_yuv_or_an_rgb_alpha_video
2 On FFmpeg 9.1, 4:2:2/4:2:0 renders of an x264 take differ slightly in chroma siting from Ut Video/FFV1 ones low Filed #1680
3 "Smallest" label and the disk.rs comment are not reliably true for x264 lossless any more low Filed #1681
4 Previews and take checks are slow on long-GOP x264 takes, CHECK_TIMEOUT does not scale, and a comment says HLAE takes are intra-only low Filed #1682 for the timeout scaling and the -g 1 question; the intra-only comment in take_frames.rs is corrected in cb09517
5 The new tests never run FFmpeg, and two compare the whole args string to itself low Fixed in cb09517: FFmpeg round trip per codec.args() through HLAE's pipe shape (no Incompatible pixel format, framemd5 equal), the two string tests narrowed to the encoder and the pixel format, test test_every_codec_round_trips_hlae_frames_bit_exact_through_ffmpeg
6 A types.rs comment tells history instead of the present nit Fixed in cb09517: history sentence dropped, x264 described as about the size of FFV1
7 Test step: a real capture with each changed codec on PRE and POST test No effect: run in game on PRE and POST (Brain, HLAE 2.192.4, ci_fixture.dem, separate HUD), all three streams came out bgr0 for FFV1 and h264 High 4:4:4 Predictive gbrp for x264, frame counts match the wav, no pixel-format warning or crash, and every take rendered to ProRes 422 and the HUD pass to ProRes 4444
8 Test step: take checks and a segmented render on a long, large x264 take test Filed #1683

The FFmpeg tests pass with FFmpeg 7.1.1, 8.1.4 and 9.1, and fail on the old args and graph (checked by putting them back). Not checked: HUD edges by eye, and capture speed against Ut Video in game.

…ay skip, bgra too, literal old HUD graph (#1662)

Round-2 review of #1677: test_ffmpeg panics when the variable names an
FFmpeg that doesn't run; encoder availability comes from -encoders;
the round trip pipes bgr24 and bgra and needs three codecs to run;
the HUD test compares against the old graph written out; FFV1's
keyframe comment says one in twelve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry

Copy link
Copy Markdown
Owner Author

Review findings

Round-2 Fable review of cb09517 (SAFE WITH FOLLOW-UPS, no app-code finding). Dev merged in (9e417d1); fixes in 9bb93c2.

# Finding Severity Outcome
1 The FFmpeg-gated tests never run in CI, so the green check covers neither fix low Filed #1687
2 A DODSTUDIO_TEST_FFMPEG that doesn't run counts as no FFmpeg and the tests pass low Fixed in 9bb93c2: test_ffmpeg panics with the path when the variable is set but doesn't run, None only when unset and no ffmpeg on PATH, test a_set_test_ffmpeg_that_does_not_run_fails_instead_of_skipping
3 The round-trip test can skip Ut Video and FFV1 on help wording and pass on Uncompressed alone low Fixed in 9bb93c2: only libx264rgb may skip, decided from ffmpeg -encoders, and at least three codecs must run, test an_encoder_is_found_by_its_name_column_only
4 The HUD test's "same frames as before" compares the graph with itself once the constant changes, and any failed yuv444p encode skips the case low Fixed in 9bb93c2: "before" uses the old graph written out, the two argument lists must differ, the yuv444p case skips only when -encoders has no libx264 and otherwise a failed encode fails, test a_hud_take_renders_with_a_yuv_or_an_rgb_alpha_video (a lossy yuv444p mutation of the constant now fails it)
5 The round trip pipes only bgr24 while the comment says bgra was checked too low Fixed in 9bb93c2: the encode loops over bgr24 and bgra input, test test_every_codec_round_trips_hlae_frames_bit_exact_through_ffmpeg
6 A comment says every FFV1 frame is a keyframe; it is one in twelve nit Fixed in 9bb93c2: take_frames.rs says FFV1 has a keyframe every 12 frames (35 in 413 in a real HLAE take), and the figure is added to #1682
7 An encoder that stops early panics on the pipe write and loses FFmpeg's message nit Fixed in 9bb93c2: the write's error is ignored so the status assert prints FFmpeg's log, test test_every_codec_round_trips_hlae_frames_bit_exact_through_ffmpeg
8 Test step: a real old x264 HUD take rendered and looked at, and the new HUD edges by eye test No effect: run in game on PRE and POST with the pre-PR x264 args (Brain, HLAE 2.192.4), the yuv444p HUD takes render to ProRes 4444 with the new merge, and 6x crops of all six takes (old x264, FFV1, x264 RGB, both installs) show a clean, solid crosshair with no fringe

All FFmpeg tests pass with FFmpeg 7.1.1, 8.1.4 and 9.1; a broken DODSTUDIO_TEST_FFMPEG path now fails. cargo test -p native 2,051 passed after merging dev; clippy and rustfmt clean. Limit of step 8: the crosshair is the only HUD element the test demo shows, so text and icons were not looked at.

)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry
ccoventry merged commit e74baa7 into dev Dec 4, 2026
12 checks passed
@ccoventry
ccoventry deleted the fix/lossless-pixel-formats-1662 branch December 4, 2026 06:50
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.

Direct-to-video FFV1 and x264 lossless ask FFmpeg for a pixel format it refuses (x264 isn't lossless)

1 participant