diff --git a/CLAUDE.md b/CLAUDE.md
index d9f9a5a2..04645389 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1995,9 +1995,18 @@ original frames of a frame-rate conversion done by blending. Rules, from
- Not exposed: `thresh`, `mode`, `omode`, `speed` (upstream defaults); no
built-in preset turns it on.
+- **Its decisions are not stable to a level of input change** (task #64):
+ the detector thresholds min/max statistics of blend maps, so QTGMC's
+ rounding at 10 bits (~0.35 levels) moves ~10% of decisions and ~5-8% of
+ output frames to a neighbouring original, with recovery as good. Never
+ expect two depths, deinterlacers or plugin versions to pick the same
+ frames; only the same picture at two depths (an exact shift) does.
+
`integration_unblend_test.dart` (heavy) checks recovery on the blended
fixtures (`generate_blended_test.sh`) against plain decimation, exact length
-and rate, 8 = 10-bit, and preview = encode.
+and rate, depth two ways (the same picture at 8 and 10 bits: identical
+output; a real 10-bit source: as good a recovery, mostly the same picks),
+and preview = encode.
### Frame Rate targets (issue #129)
@@ -3118,6 +3127,13 @@ Subtitle heavy tests skip when the whisper add-on is absent.
cd worker && cargo run --release -- --config test_job.json
```
+> **A heavy test job on a >8-bit fixture sets `inputPixelFormat` and asserts
+> the output's `pix_fmt`.** Before the source model (task #50) a job without
+> it was decoded as 8-bit 4:2:0, silently, and Unblend's "10-bit = 8-bit"
+> test compared the 8-bit run with itself for as long as it existed
+> (task #64). The worker now probes the format, but only the assertion makes
+> a test fail if its depth stops reaching the pass.
+
> **The heavy tests run the worker BINARY, not the library**, and
> `app/lib/**/*.g.dart` is gitignored — **run `cargo build` before the heavy
> suite** and `dart run build_runner build` before any Dart test, or you'll
diff --git a/app/test/integration_unblend_test.dart b/app/test/integration_unblend_test.dart
index b7633122..0adcb1f5 100644
--- a/app/test/integration_unblend_test.dart
+++ b/app/test/integration_unblend_test.dart
@@ -9,7 +9,12 @@
/// - length and rate: exactly floor(n * num / den) frames;
/// - preview = encode, at frames near the start and well into the clip,
/// where the detector's window is decoded fresh by the preview;
-/// - depth: a 10-bit copy of the fixture gives the 8-bit result.
+/// - depth, two ways (task #64): the same picture at 8 and 10 bits (an
+/// exact shift, nothing ahead of Unblend that rounds) gives the same frames
+/// exactly; a real 10-bit copy of the source, deinterlaced at 10 bits, is
+/// unblended as well as the 8-bit one. Not the same frames: QTGMC rounds
+/// differently at 10 bits, and srestore's min/max statistics turn that
+/// into different picks for ~5-8% of frames, each a neighbouring original.
///
/// Heavy (full encodes): runs in the nightly workflow, not the push gate.
@Tags(['heavy'])
@@ -63,6 +68,57 @@ Future> _frames(String path, {String? vf}) async {
Future> _truth(int count) => _frames(_fixture('small_clip.mp4'),
vf: "select='between(n\\,$_first\\,${_first + count - 1})',setpts=N/TB");
+/// Every frame's luma (Y plane), in 8-bit levels. Decoded in the planar
+/// format itself, never through `gray`, which expands the range.
+Future> _lumas(String path, {bool tenBit = false, String? vf}) async {
+ final all = await _raw(path, tenBit ? 'yuv420p10le' : 'yuv420p', vf: vf);
+ const luma = _width * _height, samples = luma * 3 ~/ 2;
+ final bps = tenBit ? 2 : 1;
+ final view = ByteData.sublistView(all);
+ return [
+ for (var o = 0; o + samples * bps <= all.length; o += samples * bps)
+ Float64List.fromList([
+ for (var i = 0; i < luma; i++)
+ tenBit ? view.getUint16(o + 2 * i, Endian.little) / 4 : all[o + i].toDouble(),
+ ]),
+ ];
+}
+
+double _lumaDiff(Float64List a, Float64List b) {
+ var sum = 0.0;
+ for (var i = 0; i < a.length; i++) {
+ sum += (a[i] - b[i]).abs();
+ }
+ return sum / a.length;
+}
+
+/// For each output frame, the original within +-3 of where it belongs that
+/// is nearest in luma, and its distance.
+List<(int, double)> _nearestLuma(List out, List truth) => [
+ for (var m = 0; m < out.length; m++)
+ [
+ for (var k = m - 3; k <= m + 3; k++)
+ if (k >= 0 && k < truth.length) (k, _lumaDiff(out[m], truth[k])),
+ ].reduce((a, b) => a.$2 <= b.$2 ? a : b),
+ ];
+
+/// Every sample of every frame, raw (yuv420p bytes or yuv420p10le words).
+Future _raw(String path, String pixFmt, {String? vf}) async {
+ final r = await Process.run(
+ WorkerHarness.ffmpegPath,
+ ['-v', 'error', '-i', path, if (vf != null) ...['-vf', vf], '-fps_mode', 'passthrough',
+ '-f', 'rawvideo', '-pix_fmt', pixFmt, '-'],
+ environment: WorkerHarness.ffmpegEnv,
+ stdoutEncoding: null,
+ );
+ if (r.exitCode != 0) throw Exception('decoding $path: ${r.stderr}');
+ final bytes = r.stdout as List;
+ return bytes is Uint8List ? bytes : Uint8List.fromList(bytes);
+}
+
+Future _pixFmt(String path) async =>
+ (await WorkerHarness.firstStream(path, selector: 'v:0', entries: ['pix_fmt']))?['pix_fmt'] as String?;
+
/// For each output frame, its distance (rgb mean abs diff) to the nearest
/// original within +-3 of where it belongs.
List _nearest(List out, List truth) => [
@@ -76,6 +132,7 @@ List _nearest(List out, List truth) => [
VideoJob _job(String name, String input, double fps, {
required ProcessingPipeline pipeline,
ContainerFormat container = ContainerFormat.mkv,
+ String? pixelFormat,
}) =>
VideoJob(
id: const Uuid().v4(),
@@ -88,6 +145,10 @@ VideoJob _job(String name, String input, double fps, {
audioMode: AudioMode.none,
),
inputFrameRate: fps,
+ // Set for every >8-bit fixture: before task #50 a job without it was
+ // decoded as 8-bit 4:2:0, silently, and a depth test compared the
+ // 8-bit run with itself (task #64).
+ inputPixelFormat: pixelFormat,
);
ProcessingPipeline _unblend(FrameRateTarget target) => ProcessingPipeline(
@@ -150,7 +211,8 @@ void main() {
test('recovers PAL frames from NTSC blending, at 10-bit 4:2:2', () async {
final path = await _encode(_job('pal_unblend', _fixture('blended_pal_5994i.mkv'), 29.97,
- pipeline: _unblend(FrameRateTarget.pal25)));
+ pipeline: _unblend(FrameRateTarget.pal25), pixelFormat: 'yuv422p10le'));
+ expect(await _pixFmt(path), 'yuv422p10le', reason: 'the 10-bit 4:2:2 path must really run');
final pal = await _truth(125);
final out = await _frames(path);
// 150 frames of 29.97i -> 300 at 59.94p -> floor(300 * 1001 / 2400).
@@ -158,7 +220,7 @@ void main() {
final unblended = _nearest(out, pal);
final decimated = _nearest(
await _frames(await _encode(_job('pal_decimate', _fixture('blended_pal_5994i.mkv'), 29.97,
- pipeline: _decimate(FrameRateTarget.pal25)))),
+ pipeline: _decimate(FrameRateTarget.pal25), pixelFormat: 'yuv422p10le'))),
pal);
int clean(List d) => d.where((v) => v <= _cleanLimit).length;
print(' clean: unblend ${clean(unblended)}/${out.length}, '
@@ -177,30 +239,87 @@ void main() {
expect(v?['nb_read_frames'], '143');
}, timeout: const Timeout(Duration(minutes: 10)));
- test('a 10-bit copy of the source gives the 8-bit result', () async {
- final ten = '$_outDir/blended_film_50i_10bit.mkv';
+ test('the same picture at 10 bits gives the 8-bit result exactly', () async {
+ // The detector's own input, deinterlaced once at 8 bits, and its exact
+ // 10-bit copy (ffmpeg's 8 -> 10 is a shift by 2). Nothing ahead of
+ // Unblend rounds, so every measurement and pick must be the same: a
+ // threshold left in 8-bit units at 10 bits would move most of them.
+ final eightIn = await _encode(_job('film_deint_8bit', _fixture('blended_film_50i.mkv'), 25,
+ pipeline: ProcessingPipeline(deinterlace: const QTGMCParameters(enabled: true, tff: true))));
+ final tenIn = '$_outDir/film_deint_10bit.mkv';
+ final r = await Process.run(WorkerHarness.ffmpegPath, [
+ '-y', '-v', 'error', '-i', eightIn, '-c:v', 'ffv1', '-pix_fmt', 'yuv420p10le', tenIn,
+ ], environment: WorkerHarness.ffmpegEnv);
+ expect(r.exitCode, 0, reason: '${r.stderr}');
+ final progressive = ProcessingPipeline(
+ deinterlace: const QTGMCParameters(enabled: false),
+ unblend: UnblendParameters(enabled: true, target: FrameRateTarget.film23976),
+ );
+ final eight = await _encode(
+ _job('film_exact_8bit', eightIn, 50, pipeline: progressive, pixelFormat: 'yuv420p'));
+ final ten = await _encode(
+ _job('film_exact_10bit', tenIn, 50, pipeline: progressive, pixelFormat: 'yuv420p10le'));
+ expect(await _pixFmt(ten), 'yuv420p10le', reason: 'the 10-bit path must really run');
+ final a = await _raw(eight, 'yuv420p');
+ final b = await _raw(ten, 'yuv420p10le');
+ // 300 frames at 50p -> floor(300 * 480 / 1001).
+ const frameSamples = _width * _height * 3 ~/ 2;
+ expect(a.length, 143 * frameSamples);
+ expect(b.length, a.length * 2);
+ final words = ByteData.sublistView(b);
+ var differ = 0;
+ int? firstFrame;
+ for (var i = 0; i < a.length; i++) {
+ if (words.getUint16(2 * i, Endian.little) != a[i] << 2) {
+ differ++;
+ firstFrame ??= i ~/ frameSamples;
+ }
+ }
+ expect(differ, 0, reason: '$differ samples differ, first in output frame $firstFrame');
+ }, timeout: const Timeout(Duration(minutes: 10)));
+
+ test('a 10-bit copy of the source is unblended as well as the 8-bit one', () async {
+ final tenSource = '$_outDir/blended_film_50i_10bit.mkv';
final r = await Process.run(WorkerHarness.ffmpegPath, [
'-y', '-v', 'error', '-i', _fixture('blended_film_50i.mkv'),
- '-c:v', 'ffv1', '-pix_fmt', 'yuv420p10le', ten,
+ '-c:v', 'ffv1', '-pix_fmt', 'yuv420p10le', tenSource,
], environment: WorkerHarness.ffmpegEnv);
expect(r.exitCode, 0, reason: '${r.stderr}');
- final eight = await _frames(filmEncode);
- final deep = await _frames(await _encode(
- _job('film_unblend_10bit', ten, 25, pipeline: _unblend(FrameRateTarget.film23976))));
+ final ten = await _encode(_job('film_unblend_10bit', tenSource, 25,
+ pipeline: _unblend(FrameRateTarget.film23976), pixelFormat: 'yuv420p10le'));
+ expect(await _pixFmt(ten), 'yuv420p10le', reason: 'the 10-bit path must really run');
+ final truth = await _lumas(_fixture('small_clip.mp4'),
+ vf: "select='between(n\\,$_first\\,${_first + 143})',setpts=N/TB");
+ final eight = await _lumas(filmEncode);
+ final deep = await _lumas(ten, tenBit: true);
expect(deep.length, eight.length);
- // The detector measures an 8-bit copy of the luma, so it picks the same
- // frames; what differs is only the deinterlacer's rounding at 10-bit.
- var worst = 0.0;
- for (var m = 0; m < eight.length; m++) {
- final d = WorkerHarness.meanAbsDiff(eight[m], deep[m]);
- if (d > worst) worst = d;
- }
- print(' worst 8 vs 10-bit frame difference: ${worst.toStringAsFixed(3)}');
- expect(worst, lessThan(1.0), reason: 'a different frame would differ by several levels');
+ final n8 = _nearestLuma(eight, truth), n10 = _nearestLuma(deep, truth);
+ // Luma: within 2 levels of an original (report: originals repeated
+ // through the same chain sit within ~1.5, a blend ~3.6 from either).
+ int clean(List<(int, double)> d) => d.where((x) => x.$2 <= 2.0).length;
+ final same = [for (var m = 0; m < eight.length; m++) if (n8[m].$1 == n10[m].$1) m];
+ final diffs = [for (final m in same) _lumaDiff(eight[m], deep[m])]..sort();
+ final median = diffs[diffs.length ~/ 2], worst = diffs.last;
+ print(' clean (luma <= 2.0): 8-bit ${clean(n8)}/${eight.length}, '
+ '10-bit ${clean(n10)}/${deep.length}; same original ${same.length}/${eight.length}; '
+ 'luma 8 vs 10 where same: median ${median.toStringAsFixed(3)}, max ${worst.toStringAsFixed(3)}');
+ // Measured on macOS arm64 (task #64): 143/143 at both depths, 136/143
+ // the same original (the report's probe: 132), median 0.37 and max
+ // 1.26 levels where the same. Picks differ a little per platform.
+ expect(clean(n10), greaterThanOrEqualTo((deep.length * 0.95).floor()));
+ expect(clean(n10), greaterThanOrEqualTo(clean(n8) - (deep.length * 0.02).ceil()));
+ expect(same.length, greaterThanOrEqualTo((eight.length * 0.85).floor()));
+ expect(median, lessThanOrEqualTo(0.6));
+ expect(worst, lessThanOrEqualTo(2.0));
}, timeout: const Timeout(Duration(minutes: 10)));
test('the preview shows the encode\'s frame', () async {
- final encoded = await _frames(filmEncode);
+ // Decoded as the preview converts to RGB (pipeline_executor.rs,
+ // preview_scale_filter, task #56 F8; the fixture is untagged, so
+ // limited range): with ffmpeg's default flags the same frame read
+ // 0.54 apart.
+ final encoded = await _frames(filmEncode,
+ vf: 'scale=in_range=tv:out_range=pc:flags=accurate_rnd+full_chroma_int');
// Near the start (the detector starts at the clip's first frame) and
// past the window, where the preview decodes only part of the clip.
for (final t in [3, 30, 60, 100, 140]) {
diff --git a/docs/ENGINEERING_NOTES.md b/docs/ENGINEERING_NOTES.md
index 00d5b69a..c6395fea 100644
--- a/docs/ENGINEERING_NOTES.md
+++ b/docs/ENGINEERING_NOTES.md
@@ -5222,3 +5222,28 @@ for 48-px blocks. Ships in deps 1.18.0; the push gate's `fft3dfilter is
deterministic` and the heavy `integration_fft3dfilter_determinism_test.dart`
skip on bundles up to 1.17.x. Report:
[docs/reports/task-62-fft3dfilter-determinism](reports/task-62-fft3dfilter-determinism/index.html).
+
+### Unblend's 8 = 10-bit test was vacuous; a real 10-bit source picks differently (task #64, 2026-11-17)
+
+Report: [docs/reports/2026-11-srestore](reports/2026-11-srestore/index.html), section 8's correction.
+
+- From dc9e36c (task #50) the heavy test "a 10-bit copy of the source gives
+ the 8-bit result" failed on every platform (13.08 levels on arm64, 13.43
+ on x86). Nothing in Unblend changed: its job named no `inputPixelFormat`,
+ and before the source model the worker decoded such a source as 8-bit
+ 4:2:0, so the test had compared the 8-bit run with itself (0.000). The
+ deps version was ruled out (1.16.0 and 1.17.0-rc2 identical).
+- At 10 bits QTGMC rounds differently (luma ~0.35 levels); srestore's
+ min/max statistics magnify that (`SrBMax` up to 31), 30 of 300 decisions
+ change, and 7-11 of 143 output frames take a neighbouring original.
+ Recovery is equal (143/143 clean at both depths). The exact-shift result
+ (same picture at both depths, identical decisions) stands.
+- The test is now two: the same picture at 8 and 10 bits (Deinterlace off on
+ a lossless 50p intermediate) must give identical output, and a real 10-bit
+ source must recover as well, with >= 85% of picks the same. Both set
+ `inputPixelFormat` and assert the output's `pix_fmt`; forcing the 10-bit
+ job back to `yuv420p` fails the exact test.
+- The preview test's own decode had drifted too: task #56 F8 made the
+ preview convert with `accurate_rnd+full_chroma_int`, which put the same
+ frame 0.54 rgb levels from a default-flags decode of the encode. The test
+ now decodes the encode with the preview's flags (0.00 again).
diff --git a/docs/reports/2026-11-srestore/data/depth_source.json b/docs/reports/2026-11-srestore/data/depth_source.json
new file mode 100644
index 00000000..ead1cc6c
--- /dev/null
+++ b/docs/reports/2026-11-srestore/data/depth_source.json
@@ -0,0 +1,141 @@
+{
+ "qtgmc_output_luma_mad_8_vs_10": {
+ "median": 0.3524609375,
+ "max": 0.5159244791666666
+ },
+ "detector_props": {
+ "SrBMin": {
+ "frames_differing": 213,
+ "max_abs_diff": 16
+ },
+ "SrBMax": {
+ "frames_differing": 258,
+ "max_abs_diff": 31
+ },
+ "SrDMax": {
+ "frames_differing": 175,
+ "max_abs_diff": 5
+ },
+ "SrMDiff": {
+ "frames_differing": 297,
+ "max_abs_diff": 0.0005746416213544244
+ }
+ },
+ "decisions": {
+ "frames": 300,
+ "differing": 30,
+ "at": [
+ 20,
+ 52,
+ 74,
+ 75,
+ 103,
+ 104,
+ 107,
+ 108,
+ 109,
+ 110,
+ 111,
+ 112,
+ 113,
+ 153,
+ 161,
+ 162,
+ 163,
+ 164,
+ 182,
+ 183,
+ 184,
+ 185,
+ 186,
+ 187,
+ 199,
+ 201,
+ 212,
+ 249,
+ 250,
+ 251
+ ]
+ },
+ "output_frames": 143,
+ "same_original": 132,
+ "moved_to_a_neighbour": [
+ {
+ "output": 25,
+ "pick8": 25,
+ "pick10": 24
+ },
+ {
+ "output": 50,
+ "pick8": 50,
+ "pick10": 49
+ },
+ {
+ "output": 52,
+ "pick8": 52,
+ "pick10": 51
+ },
+ {
+ "output": 53,
+ "pick8": 53,
+ "pick10": 52
+ },
+ {
+ "output": 54,
+ "pick8": 54,
+ "pick10": 53
+ },
+ {
+ "output": 78,
+ "pick8": 78,
+ "pick10": 77
+ },
+ {
+ "output": 79,
+ "pick8": 79,
+ "pick10": 78
+ },
+ {
+ "output": 88,
+ "pick8": 88,
+ "pick10": 87
+ },
+ {
+ "output": 89,
+ "pick8": 89,
+ "pick10": 88
+ },
+ {
+ "output": 90,
+ "pick8": 90,
+ "pick10": 89
+ },
+ {
+ "output": 120,
+ "pick8": 120,
+ "pick10": 119
+ }
+ ],
+ "luma_8_vs_10_where_same": {
+ "median": 0.34638020833333333,
+ "max": 1.2550130208333332
+ },
+ "worst_8_vs_10_frame": 10.97484375,
+ "clean_le_2.0": {
+ "8bit": 143,
+ "10bit": 143
+ },
+ "clean_le_1.5": {
+ "8bit": 136,
+ "10bit": 140
+ },
+ "worst_to_truth": {
+ "8bit": 1.7725390625,
+ "10bit": 1.752578125
+ },
+ "distinct_originals": {
+ "8bit": 117,
+ "10bit": 117,
+ "of": 144
+ }
+}
\ No newline at end of file
diff --git a/docs/reports/2026-11-srestore/index.html b/docs/reports/2026-11-srestore/index.html
index dcabcfd3..e3d68498 100644
--- a/docs/reports/2026-11-srestore/index.html
+++ b/docs/reports/2026-11-srestore/index.html
@@ -183,7 +183,8 @@ 6. Order, threads and the preview
In the app, ProcessingPipeline::preview_output computes the padding and the detector origin
for Unblend as it does for the Frame Rate pass (both, when both are on). The heavy test
(integration_unblend_test.dart) previews five source frames of the film fixture through the real
-worker and finds each identical to its encode frame (difference 0.00).
+worker and finds each identical to its encode frame (difference 0.00; since task #56 the preview converts to RGB
+with accurate_rnd+full_chroma_int, and the test decodes the encode the same way).
7. Length, rates and refusals
srestore computes its own ratio (numr/denm) in floating point from the input and target rates.
@@ -205,8 +206,24 @@
8. Depth, Expr implementation, cost
scripts/depth_speed.py and scripts/cache.py:
- 8 vs 10-bit: the film fixture after QTGMC, shifted exactly to 10-bit: identical measurements,
-identical decisions, outputs identical after converting back. Through the worker, a 10-bit copy of the source
-gives the 8-bit encode's frames exactly. The PAL fixture is 10-bit 4:2:2 throughout.
+identical decisions, outputs identical after converting back. Through the worker, a 10-bit copy of the source
+gives the 8-bit encode's frames exactly. (Corrected below.) The PAL fixture is 10-bit 4:2:2 throughout.
+- Correction (2026-11-17, task #64). The
+struck sentence was measured on a path that never ran at 10 bits: the heavy test's job named no
+
inputPixelFormat, and before the source model (task #50) the worker then decoded every source as
+8-bit 4:2:0, so it compared the 8-bit run with itself. Decoded at 10 bits, the source is deinterlaced at 10 bits,
+and QTGMC rounds differently there (luma median 0.35, max 0.52 levels from the 8-bit run). The detector's
+min/max statistics turn that into differences of up to 16 (SrBMin), 31 (SrBMax) and 5
+(SrDMax) on most frames, and 30 of 300 decisions change. 11 of 143 output frames take a neighbouring
+original instead (8-bit frame 89 vs 10-bit 88, for example), so the outputs differ by up to 11 levels on those
+frames. Recovery is as good: 143/143 clean (≤ 2.0 luma levels) at both depths, 136 vs 140 within 1.5, 117
+distinct originals each (scripts/depth_source.py, data/depth_source.json; luma MAD to the
+nearest original within ±3, a 10-bit frame converted exactly to 8 bits, so it carries up to half a level of
+rounding the 8-bit frame doesn't). Through the worker on macOS arm64: 7 of 143 frames moved, 143/143 clean at
+both depths. The exact-shift result above stands, and the heavy test now checks both: the same picture at 8 and
+10 bits gives the same output exactly, and a real 10-bit source recovers as well as the 8-bit one. The PAL
+fixture's heavy test had been running at 8 bits too; at 10-bit 4:2:2 it measures 88/125 clean, decimation 63/125
+(rgb24 metric, limit 2.2).
- Expr: the one expression goes through the usual
_expr() helper (akarin on ARM).
akarin and VapourSynth's own std.Expr give bit-identical measurements on both fixtures; this was
checked because the detector thresholds them.
@@ -266,6 +283,7 @@ 11. Scripts
order.py | Section 6 (data/order.json) |
lengths.py | Section 7 (data/ratio_table.json, read by the Rust tests) |
depth_speed.py, cache.py | Section 8 (data/depth_speed.json, data/cache.json) |
+depth_source.py | Section 8's correction: a real 10-bit source (data/depth_source.json) |
images.py | img/ |
diff --git a/docs/reports/2026-11-srestore/scripts/depth_source.py b/docs/reports/2026-11-srestore/scripts/depth_source.py
new file mode 100644
index 00000000..493e19c1
--- /dev/null
+++ b/docs/reports/2026-11-srestore/scripts/depth_source.py
@@ -0,0 +1,75 @@
+"""A real 10-bit source vs the same source at 8 bits (task #64).
+
+depth_speed.py shifts the film fixture to 10-bit *after* QTGMC, so the
+detector sees the same picture and decides identically. A 10-bit source is
+deinterlaced at 10 bits, and QTGMC rounds differently there. This measures
+what that does to the detector and the picks, on the film fixture (its exact
+10-bit copy, as the heavy test makes it): QTGMC (Slower, double rate) on
+each, then Unblend to 23.976, the shipped window of 48.
+
+Metric: luma MAD in 8-bit levels against the nearest original within +-3 of
+where the frame belongs (probelib.nearest_truth); a 10-bit frame is compared
+after an exact conversion to 8 bits, so it carries up to half a level of
+rounding the 8-bit run doesn't. "Clean" is <= 2.0 levels, the heavy test's
+limit (score.py's calibrated limits are per fixture and close to it).
+"""
+import json
+import os
+
+import probelib as P
+from probelib import core, vs
+
+S = P.srestore
+num, den = P.TARGETS['film']
+
+src8 = P.fixture_film_50i()
+src10 = core.resize.Point(src8, format=vs.YUV420P10) # exact: a shift by 2
+bob8 = P.bobbed('film')
+bob10 = P.cache_raw(P.bob(src10), 'film50p_qtgmc_from10')
+
+# The detector's input: QTGMC's output at each depth.
+lu = P.mad(bob8, bob10)
+frfac, numr, denm = S.ratio(bob8.fps_num, bob8.fps_den, num, den)
+p8 = P.props(bob8, 'film50p_qtgmc')
+p10 = P.props(bob10, 'film50p_qtgmc_from10')
+names = ['SrBMin', 'SrBMax', 'SrDMax', 'SrMDiff']
+props = {}
+for k, name in enumerate(names):
+ d = [abs(a[k] - b[k]) for a, b in zip(p8, p10)]
+ props[name] = {'frames_differing': sum(1 for v in d if v > 0), 'max_abs_diff': max(d)}
+d8 = P.decisions_window(p8, frfac, numr, denm, 48)
+d10 = P.decisions_window(p10, frfac, numr, denm, 48)
+flipped = [n for n in range(len(d8)) if d8[n] != d10[n]]
+
+gt = P.truth(P.TRUTH_COUNT['film'])
+o8 = S.unblend(bob8, num, den)
+o10 = S.unblend(bob10, num, den)
+n8 = P.nearest_truth(o8, gt, 1.0, search=3)
+n10 = P.nearest_truth(o10, gt, 1.0, search=3)
+same = [m for m in range(len(n8)) if n8[m][0] == n10[m][0]]
+moved = [{'output': m, 'pick8': n8[m][0], 'pick10': n10[m][0]} for m in range(len(n8)) if m not in same]
+od = P.mad(o8, o10)
+od_same = sorted(od[m] for m in same)
+
+
+def clean(picks, limit):
+ return sum(1 for _, v, _ in picks if v <= limit)
+
+
+res = {
+ 'qtgmc_output_luma_mad_8_vs_10': {'median': sorted(lu)[len(lu) // 2], 'max': max(lu)},
+ 'detector_props': props,
+ 'decisions': {'frames': len(d8), 'differing': len(flipped), 'at': flipped},
+ 'output_frames': len(n8),
+ 'same_original': len(same),
+ 'moved_to_a_neighbour': moved,
+ 'luma_8_vs_10_where_same': {'median': od_same[len(od_same) // 2], 'max': od_same[-1]},
+ 'worst_8_vs_10_frame': max(od),
+ 'clean_le_2.0': {'8bit': clean(n8, 2.0), '10bit': clean(n10, 2.0)},
+ 'clean_le_1.5': {'8bit': clean(n8, 1.5), '10bit': clean(n10, 1.5)},
+ 'worst_to_truth': {'8bit': max(v for _, v, _ in n8), '10bit': max(v for _, v, _ in n10)},
+ 'distinct_originals': {'8bit': len({i for i, _, _ in n8}), '10bit': len({i for i, _, _ in n10}),
+ 'of': P.TRUTH_COUNT['film']},
+}
+print(json.dumps(res, indent=1))
+json.dump(res, open(os.path.join(P.HERE, '..', 'data', 'depth_source.json'), 'w'), indent=1)
diff --git a/docs/reports/2026-11-srestore/scripts/probelib.py b/docs/reports/2026-11-srestore/scripts/probelib.py
index 4ddacedf..7249a09f 100644
--- a/docs/reports/2026-11-srestore/scripts/probelib.py
+++ b/docs/reports/2026-11-srestore/scripts/probelib.py
@@ -32,6 +32,7 @@
_FMT = {
'yuv420p': (vs.YUV420P8, 1, 1, 1),
+ 'yuv420p10le': (vs.YUV420P10, 2, 1, 1),
'yuv422p10le': (vs.YUV422P10, 2, 1, 0),
}
@@ -154,7 +155,8 @@ def summarise(label, picks, clean_limit):
def cache_raw(clip, name):
"""Render ``clip`` once to SCRATCH/name.raw (slow steps like QTGMC) and
return a reader over the file."""
- pix = {vs.YUV420P8: 'yuv420p', vs.YUV422P10: 'yuv422p10le'}[clip.format.id]
+ pix = {vs.YUV420P8: 'yuv420p', vs.YUV420P10: 'yuv420p10le',
+ vs.YUV422P10: 'yuv422p10le'}[clip.format.id]
out = os.path.join(SCRATCH, name + '.raw')
if not os.path.exists(out):
tmp = out + '.part'