feat(chroma): offer to remove a green or blue screen, and key it in the decode

TASK 64 slices D and E: the feature is usable end to end.

- Add a video file → one frame is probed (new `IChromaProbe`/`FfmpegChromaProbe`, one ffmpeg
  pass at 160x90, off the UI thread) and the layer gets an offer: "Looks like a green screen —
  Remove it", with the measured colour as a swatch.
- Accepting it turns the offer into settings (Amount / Softness / Fringe) that reach ffmpeg as
  `colorkey` + `despill` + `format=bgra`, so the key is computed in the pipe and both consumers
  (the shared preview bitmap and the compositor's frame) carry the same alpha.
- Media sessions are now keyed by **path + look** (`MainViewModel.MediaSessionKey`), so two
  layers with the same settings still share one decoder, and changing the look releases the old
  session and starts the new one. Removal, load reconciliation, loop and audio settings all move
  to the same key.
- Settings persist on the `Source` row (six ALTER TABLE guards + SELECT/INSERT), so a keyed layer
  comes back keyed.
- Panel section is plain creator words: Green/Blue Screen, Amount, Softness, Fringe.

Test: `ChromaKeyApplyTests` — the pipe asks ffmpeg to key (and does not when off); a green-screen
clip is offered, accepting it starts a keyed session, the layer's resolver then reads that session
rather than the old one; the setting survives a save.

Docs: TASK 64 D/E ticked with slice F (auto-apply setting + alert clips) left open; frame-pipeline
records the decode-option design; HANDOFF rewritten. verify.sh: 544 passed, 0 failed, 0 warnings.
This commit is contained in:
2026-11-05 08:15:32 -08:00
parent 21db8a17b8
commit ea24405ba2
19 changed files with 732 additions and 106 deletions
+22 -6
View File
@@ -190,6 +190,8 @@ public partial class MainViewModel : ViewModelBase
public ICommand AddImageCommand { get; }
public ICommand AddMediaCommand { get; }
public ICommand ChangeMediaFileCommand { get; }
/// <summary>Accepts the detector's green/blue-screen offer on a clip (TASK 64).</summary>
public ICommand AcceptChromaSuggestionCommand { get; }
public ICommand RemoveSourceCommand { get; }
public ICommand EditElementCommand { get; }
public ICommand ToggleElementVisibilityCommand { get; }
@@ -266,6 +268,9 @@ public partial class MainViewModel : ViewModelBase
ChangeMediaFileCommand = new RelayCommand(
element => ChangeMediaFile(element as Source),
element => element is Source { IsMediaSource: true });
AcceptChromaSuggestionCommand = new RelayCommand(
element => AcceptChromaSuggestion(element as Source),
element => element is Source { HasChromaSuggestion: true });
RemoveSourceCommand = new RelayCommand(element => { PushPreviewUndo(); RemoveElement(element as SceneElement); });
EditElementCommand = new RelayCommand(element => BeginEditElement(element as SceneElement));
ToggleElementVisibilityCommand = new RelayCommand(element => { PushPreviewUndo(); ToggleElementVisibility(element as SceneElement); });
@@ -401,12 +406,18 @@ public partial class MainViewModel : ViewModelBase
_screenCaptureManager.PreviewBitmapChanged += OnScreenPreviewBitmapChanged;
_screenCaptureManager.CaptureFailed += OnScreenCaptureFailed;
_chromaProbe = ChromaProbeOverride
?? new FfmpegChromaProbe(new FfmpegLocator(), () => new FfmpegDecodeProcess());
_mediaManager = new MediaVideoSourceManager(
MediaFrameSourceFactoryOverride ?? (path => new MediaVideoSource(
path, MediaDecodeWidth, MediaDecodeHeight,
new FfmpegLocator(), () => new FfmpegDecodeProcess(),
frameRateProbe: new FfmpegFrameRateProbe(
new FfmpegLocator(), () => new FfmpegDecodeProcess()))),
MediaFrameSourceFactoryOverride is { } overrideFactory
? (path, _) => overrideFactory(path)
: (path, chromaKey) => new MediaVideoSource(
path, MediaDecodeWidth, MediaDecodeHeight,
new FfmpegLocator(), () => new FfmpegDecodeProcess(),
frameRateProbe: new FfmpegFrameRateProbe(
new FfmpegLocator(), () => new FfmpegDecodeProcess()),
chromaKey: chromaKey),
System.Windows.Application.Current?.Dispatcher,
// Loop intent is per Source; the manager needs the per-*path* answer.
AnyMediaReferenceLoops);
@@ -479,6 +490,10 @@ public partial class MainViewModel : ViewModelBase
/// lifecycle without spawning ffmpeg. Mirrors <see cref="CameraFrameSourceFactoryOverride"/>.</summary>
internal static Func<string, IMediaFrameSource?>? MediaFrameSourceFactoryOverride { get; set; }
/// <summary>Test seam (TASK 64): a fake chroma probe so tests never spawn ffmpeg to look at
/// a clip's backdrop.</summary>
internal static IChromaProbe? ChromaProbeOverride { get; set; }
private void LoadLayout()
{
_isLoading = true;
@@ -678,7 +693,8 @@ public partial class MainViewModel : ViewModelBase
Source { Type: SourceType.Scoreboard } => _scoreboardPresenter?.Frame,
Source { Type: SourceType.AlertBox } alertBox => RenderAlertBox(alertBox),
Source { Type: SourceType.WebSource } web => _webView2Manager?.GetLatestFrame(web.Id),
Source { IsMediaSource: true, MediaPath: not null } media => _mediaManager.GetLatestFrame(media.MediaPath),
Source { IsMediaSource: true, MediaPath: not null } media
=> _mediaManager.GetLatestFrame(MediaSessionKey(media)),
Source { AssetId: not null } image => StaticPixelCache.Get(image.AssetId),
_ => null,
};