From ac0b55420d953162c1d0cdb51fd3560fad56b9c4 Mon Sep 17 00:00:00 2001 From: Stuart Cameron Date: Sat, 28 Nov 2026 20:10:04 +1100 Subject: [PATCH 1/2] feat(frame-rate): advise on a target at the input rate; start at 2x it (task #139) The Frame Rate pass's target defaulted to 25 fps whatever the source, so a 25 fps source converted nothing and a 23.976 film barely changed (issue #177). - pass_advice: an enabled Frame Rate pass whose target equals, or is within 5% of, the rate the pass receives gets an advisory note (never blocking). - Switching the pass on with a video selected starts it at about twice that rate (25 -> 50, 29.97 -> 59.94, 23.976 -> Custom 47.952), only when the current target is equal or close to it and below 45 fps. The model default stays pal25, so saved jobs, presets and the worker are unchanged. - frameRateInputFps mirrors the worker's rate_before(FrameRate): Deinterlace, then Unblend. unblendInputFps now keeps a film-rate Soft Telecine source's rate, as the worker's map does. - frameRateTargetFps is the one target table, shared with Unblend, reading a custom rate as custom_fps_fraction does. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 12 + app/assets/filters/core/frame_rate.json | 2 +- app/lib/models/frame_rate_parameters.dart | 92 +++++++ app/lib/models/pass_advice.dart | 60 ++++- app/lib/models/unblend_parameters.dart | 45 ++-- app/lib/viewmodels/main_viewmodel.dart | 24 ++ .../pass_settings/pass_settings_inline.dart | 7 +- app/test/frame_rate_starting_target_test.dart | 230 ++++++++++++++++++ app/test/pass_advice_test.dart | 139 +++++++++++ 9 files changed, 583 insertions(+), 28 deletions(-) create mode 100644 app/test/frame_rate_starting_target_test.dart diff --git a/CLAUDE.md b/CLAUDE.md index dcd23feb..b544bfbe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2324,6 +2324,18 @@ rate is `FrameRateParameters.customFps` (a plain number, default 48). x64 ship v24 (`floor((n - 1) * ratio) + 1`). The script trims or extends to `floor(n * ratio)` after the call (`test_184`); a frame-count assertion that passes on one platform proves nothing about the others. +- **The target is chosen against the rate the pass receives (task #139).** + That rate is `frameRateInputFps` (app): the source's after Deinterlace and + Unblend, the only passes ahead that change it (the worker's + `rate_before(PassType::FrameRate)`). The model's default stays `pal25`. + Switching the pass on with a video selected starts it at about twice that + rate (`startingFrameRateTarget`: 25 → 50, 29.97 → 59.94, 23.976 → Custom + 47.952), but only when the current target is equal or within 5% of it + (`frameRateCloseness`), so a deliberate conversion is kept, and never from + 45 fps up. A target equal or within 5% is also advised on + (`pass_advice.dart`, enabled pass only, never blocking): at the same rate + RIFE and Repeat frames pass every frame through, and nearby motion looks no + smoother (issue #177). - **Don't check an NTSC output rate on an MKV.** Matroska's 1/1000 timebase can't hold 60000/1001, so ffprobe reports an estimate (`19001/317`) for any NTSC rate. `integration_frame_mapping_test.dart` encodes its custom-rate diff --git a/app/assets/filters/core/frame_rate.json b/app/assets/filters/core/frame_rate.json index 4a7f6c92..131440ac 100644 --- a/app/assets/filters/core/frame_rate.json +++ b/app/assets/filters/core/frame_rate.json @@ -69,7 +69,7 @@ ], "ui": { "label": "Target rate", - "description": "The frame rate the output should run at. Custom lets you type any rate.", + "description": "The frame rate the output should run at. Custom lets you type any rate. Switched on with a video selected, the pass starts at about twice the video's rate when 25 fps would change nothing visible.", "widget": "dropdown", "optionLabels": { "pal25": "PAL / SECAM (25 fps)", diff --git a/app/lib/models/frame_rate_parameters.dart b/app/lib/models/frame_rate_parameters.dart index 04655913..7404cf4e 100644 --- a/app/lib/models/frame_rate_parameters.dart +++ b/app/lib/models/frame_rate_parameters.dart @@ -94,6 +94,10 @@ class FrameRateParameters { ); } + /// The target in frames per second, as the worker will run it + /// ([frameRateTargetFps]). + double get targetFps => frameRateTargetFps(target, customFps); + String get summary { if (!enabled) return 'Off'; if (target != FrameRateTarget.custom) return target.displayName; @@ -108,3 +112,91 @@ class FrameRateParameters { _$FrameRateParametersFromJson(json); Map toJson() => _$FrameRateParametersToJson(this); } + +/// The rate [target] stands for, in frames per second; for +/// [FrameRateTarget.custom], [customFps] read as the worker reads it +/// (`custom_fps_fraction`): clamped to 1–240, and an NTSC decimal (23.976, +/// 29.97, 47.952, 59.94) taken as n×1000/1001. Shared by the Frame Rate and +/// Unblend passes, whose custom rates the worker reads the same way. +double frameRateTargetFps(FrameRateTarget target, double customFps) { + switch (target) { + case FrameRateTarget.pal25: + return 25; + case FrameRateTarget.ntsc2997: + return 30000 / 1001; + case FrameRateTarget.film23976: + return 24000 / 1001; + case FrameRateTarget.film24: + return 24; + case FrameRateTarget.pal50: + return 50; + case FrameRateTarget.ntsc5994: + return 60000 / 1001; + case FrameRateTarget.custom: + return customFpsValue(customFps); + } +} + +/// [fps] as the worker's `custom_fps_fraction` makes it exact. +double customFpsValue(double fps) { + final v = fps.isFinite ? fps.clamp(1.0, 240.0).toDouble() : 48.0; + final ntsc = v * 1.001; + if ((v - v.roundToDouble()).abs() > 0.0015 && + (ntsc - ntsc.roundToDouble()).abs() < 0.0015) { + return ntsc.roundToDouble() * 1000 / 1001; + } + return (v * 1000).roundToDouble() / 1000; +} + +/// How a Frame Rate target compares with the rate the pass receives. +enum FrameRateCloseness { + /// Nothing to convert (within 0.05%). + equal, + + /// Within 5%: a real conversion, but motion looks no smoother. + close, + + /// Anything else. + far, +} + +/// Compares [targetFps] with [inputFps], the rate at the pass +/// ([frameRateInputFps]). The one test behind both the panel's advice and the +/// starting target ([startingFrameRateTarget]), so the two can't disagree. +FrameRateCloseness frameRateCloseness(double targetFps, double inputFps) { + if (!(inputFps > 0)) return FrameRateCloseness.far; + final diff = (targetFps - inputFps).abs() / inputFps; + if (diff < 0.0005) return FrameRateCloseness.equal; + if (diff <= 0.05) return FrameRateCloseness.close; + return FrameRateCloseness.far; +} + +/// The target to start the Frame Rate pass at when it is switched on with a +/// video selected (task #139): about twice [inputFps], the rate the pass +/// receives — or `null` to leave [current] alone. Only a target equal or +/// close to the input rate is replaced (the pass would do nothing visible), +/// so a deliberate conversion (25 → 29.97, 50 → 25) is kept; and an input of +/// 45 fps or more is left alone, since doubling it is no sensible default. +/// The model's own default stays [FrameRateTarget.pal25]. +FrameRateParameters? startingFrameRateTarget( + FrameRateParameters current, double inputFps) { + if (!(inputFps > 0) || inputFps >= 45) return null; + if (frameRateCloseness(current.targetFps, inputFps) == + FrameRateCloseness.far) { + return null; + } + bool near(double a, double b, double tolerance) => + (a - b).abs() / b < tolerance; + if (near(inputFps, 25, 0.005)) { + return current.copyWith(target: FrameRateTarget.pal50); + } + if (near(inputFps, 30000 / 1001, 0.0005)) { + return current.copyWith(target: FrameRateTarget.ntsc5994); + } + if (near(inputFps, 24000 / 1001, 0.0005)) { + // The worker reads 47.952 as 48000/1001 (custom_fps_fraction). + return current.copyWith(target: FrameRateTarget.custom, customFps: 47.952); + } + final doubled = (inputFps * 2 * 1000).roundToDouble() / 1000; + return current.copyWith(target: FrameRateTarget.custom, customFps: doubled); +} diff --git a/app/lib/models/pass_advice.dart b/app/lib/models/pass_advice.dart index c6266aa4..aa1d9350 100644 --- a/app/lib/models/pass_advice.dart +++ b/app/lib/models/pass_advice.dart @@ -1,5 +1,8 @@ +import '../services/field_order_detector.dart' show VideoInfo; +import 'frame_rate_parameters.dart'; import 'processing_pipeline.dart'; import 'qtgmc_parameters.dart'; +import 'unblend_parameters.dart'; /// A note about how an enabled pass interacts with the rest of the pipeline. class PassAdvice { @@ -39,7 +42,11 @@ class PassAdvice { /// Pass order is fixed (see `PassListPanel.stages` and `script_generator.rs`), /// which is what makes the ordering advice statable at all: Sharpen genuinely /// always runs after Noise Reduction, so there is no case to qualify. -List adviseOn(ProcessingPipeline pipeline) { +/// +/// [info] is the selected video, when there is one: advice that depends on the +/// source (the Frame Rate target against the rate the pass receives) is +/// silent without it. +List adviseOn(ProcessingPipeline pipeline, {VideoInfo? info}) { final advice = []; bool on(PassType pass) => pipeline.isPassEnabled(pass); @@ -142,6 +149,46 @@ List adviseOn(ProcessingPipeline pipeline) { } } + // --- A Frame Rate target at (or near) the rate the pass receives --- + // The target defaults to 25 fps whatever the source (task #139, issue #177). + // At the rate the pass already receives it converts nothing (RIFE and Repeat + // frames pass every real frame through); within a few percent it is a real + // conversion, but motion looks no smoother. The rate is the one at the pass, + // after Deinterlace and Unblend: a 25i source deinterlaced at double rate + // reaches it at 50, where a 25 target is a halving and says nothing here. + if (on(PassType.frameRate) && info != null && info.frameRate > 0) { + final input = frameRateInputFps( + pipeline.deinterlace, pipeline.unblend, info.frameRate, + softTelecineDecimates: info.softTelecineDecimates); + final target = pipeline.frameRate.targetFps; + switch (frameRateCloseness(target, input)) { + case FrameRateCloseness.equal: + advice.add(PassAdvice( + PassType.frameRate, + 'The target, ${_fps(target)} fps, is the rate this pass already ' + 'receives, so there is nothing to convert: the output has the same ' + 'frames as the input (RIFE and Repeat frames pass them through ' + 'unchanged). For smoother motion choose a higher rate, 50 or 59.94 ' + 'fps or Custom (48 for film), or switch the pass off.', + )); + break; + case FrameRateCloseness.close: + final percent = ((target - input).abs() / input * 100); + advice.add(PassAdvice( + PassType.frameRate, + 'The target, ${_fps(target)} fps, is within ' + '${percent.toStringAsFixed(1)}% of the rate this pass receives ' + '(${_fps(input)} fps). That suits matching a delivery standard, but ' + 'motion will not look smoother: most output frames sit close to a ' + 'real one. For smoother motion choose 50 or 59.94 fps, or Custom ' + '(48 for film).', + )); + break; + case FrameRateCloseness.far: + break; + } + } + // --- Levels set by hand on top of levels set automatically --- // Automatic levels measures the picture and places black and white itself, // and it runs first — so the manual input/output points are dropped (the @@ -227,9 +274,16 @@ List adviseOn(ProcessingPipeline pipeline) { return advice; } +/// A rate to three decimals, trailing zeros dropped: 25, 23.976, 29.97. +String _fps(double v) { + final s = v.toStringAsFixed(3); + return s.replaceFirst(RegExp(r'0+$'), '').replaceFirst(RegExp(r'\.$'), ''); +} + /// The advice for one pass, or null when there is none. -String? adviceFor(PassType pass, ProcessingPipeline pipeline) { +String? adviceFor(PassType pass, ProcessingPipeline pipeline, + {VideoInfo? info}) { final matches = - adviseOn(pipeline).where((a) => a.pass == pass).map((a) => a.message); + adviseOn(pipeline, info: info).where((a) => a.pass == pass).map((a) => a.message); return matches.isEmpty ? null : matches.join('\n\n'); } diff --git a/app/lib/models/unblend_parameters.dart b/app/lib/models/unblend_parameters.dart index a41a27d4..42292ff7 100644 --- a/app/lib/models/unblend_parameters.dart +++ b/app/lib/models/unblend_parameters.dart @@ -42,25 +42,9 @@ class UnblendParameters { ); } - /// The target in frames per second. - double get targetFps { - switch (target) { - case FrameRateTarget.pal25: - return 25; - case FrameRateTarget.ntsc2997: - return 30000 / 1001; - case FrameRateTarget.film23976: - return 24000 / 1001; - case FrameRateTarget.film24: - return 24; - case FrameRateTarget.pal50: - return 50; - case FrameRateTarget.ntsc5994: - return 60000 / 1001; - case FrameRateTarget.custom: - return customFps; - } - } + /// The target in frames per second, as the worker reads it + /// ([frameRateTargetFps]). + double get targetFps => frameRateTargetFps(target, customFps); String get summary { if (!enabled) return 'Off'; @@ -79,20 +63,37 @@ class UnblendParameters { /// The rate the Unblend pass converts from: the source's, as changed by the /// Deinterlace pass ahead of it. Mirrors the worker's `FrameMap`s for that /// pass (`deinterlace_frame_map`): double rate doubles it, IVTC keeps -/// cycle-1 of every cycle. -double unblendInputFps(QTGMCParameters deinterlace, double sourceFps) { +/// cycle-1 of every cycle. Soft Telecine decimates only a source decoded at a +/// pulldown rate ([softTelecineDecimates], `VideoInfo.softTelecineDecimates`); +/// at the film rate it keeps every frame, as the worker's map does. +double unblendInputFps(QTGMCParameters deinterlace, double sourceFps, + {bool softTelecineDecimates = true}) { if (!deinterlace.enabled) return sourceFps; switch (deinterlace.method) { case DeinterlaceMethod.qtgmc: case DeinterlaceMethod.bwdif: return (deinterlace.fpsDivisor ?? 1) == 1 ? sourceFps * 2 : sourceFps; - case DeinterlaceMethod.ivtc: case DeinterlaceMethod.softTelecine: + if (!softTelecineDecimates) return sourceFps; + return sourceFps * 4 / 5; + case DeinterlaceMethod.ivtc: final cycle = (deinterlace.ivtcCycle ?? 5).clamp(2, 1000); return sourceFps * (cycle - 1) / cycle; } } +/// The rate the Frame Rate pass receives: the source's, as changed by +/// Deinterlace ([unblendInputFps]) and then Unblend, the only passes ahead of +/// it that change the rate. Mirrors the worker's +/// `rate_before(PassType::FrameRate)`. +double frameRateInputFps( + QTGMCParameters deinterlace, UnblendParameters unblend, double sourceFps, + {bool softTelecineDecimates = true}) { + final afterDeinterlace = unblendInputFps(deinterlace, sourceFps, + softTelecineDecimates: softTelecineDecimates); + return unblend.enabled ? unblend.targetFps : afterDeinterlace; +} + /// Why Unblend can't recover [targetFps] from a pass running at [inputFps], /// or `null` when it plausibly can. The worker makes the exact decision (it /// also refuses a few ratios srestore would only approximate) and refuses the diff --git a/app/lib/viewmodels/main_viewmodel.dart b/app/lib/viewmodels/main_viewmodel.dart index d8e3bc77..5a056432 100644 --- a/app/lib/viewmodels/main_viewmodel.dart +++ b/app/lib/viewmodels/main_viewmodel.dart @@ -18,6 +18,8 @@ import '../models/qtgmc_parameters.dart'; import '../models/queue_item.dart'; import '../models/source_model.dart'; import '../models/processing_pipeline.dart'; +import '../models/frame_rate_parameters.dart'; +import '../models/unblend_parameters.dart'; import '../models/subtitle_parameters.dart'; import '../models/video_job.dart'; import '../models/processing_preset.dart'; @@ -1976,7 +1978,11 @@ class MainViewModel extends ChangeNotifier { /// Toggles a pass on or off. void togglePass(PassType pass, bool enabled) { + final wasEnabled = _processingPipeline.isPassEnabled(pass); _processingPipeline = _processingPipeline.togglePass(pass, enabled); + if (pass == PassType.frameRate && enabled && !wasEnabled) { + _startFrameRateFromSource(); + } // Keep qtgmcParams in sync _qtgmcParams = _processingPipeline.deinterlace; // Sync dynamic params cache with new enabled state @@ -1990,6 +1996,24 @@ class MainViewModel extends ChangeNotifier { _requestPreviewUpdate(); } + /// Switching the Frame Rate pass on with a video selected starts it at + /// about twice the rate it receives (task #139), when its target would + /// otherwise convert nothing visible (`startingFrameRateTarget`). The + /// cached panel parameters are rebuilt so the dropdown shows the new target + /// and a later panel edit doesn't write the old one back. + void _startFrameRateFromSource() { + final info = videoInfo; + if (info == null || info.frameRate <= 0) return; + final input = frameRateInputFps(_processingPipeline.deinterlace, + _processingPipeline.unblend, info.frameRate, + softTelecineDecimates: info.softTelecineDecimates); + final started = + startingFrameRateTarget(_processingPipeline.frameRate, input); + if (started == null) return; + _processingPipeline = _processingPipeline.copyWith(frameRate: started); + _dynamicParams['frame_rate'] = ParameterConverter.fromFrameRate(started); + } + /// Convert PassType to filter ID. String _passTypeToFilterId(PassType pass) { switch (pass) { diff --git a/app/lib/views/pass_settings/pass_settings_inline.dart b/app/lib/views/pass_settings/pass_settings_inline.dart index f0239aa6..49917368 100644 --- a/app/lib/views/pass_settings/pass_settings_inline.dart +++ b/app/lib/views/pass_settings/pass_settings_inline.dart @@ -184,7 +184,8 @@ class PassSettingsInline extends StatelessWidget { /// in the advisory (not error) style, because every combination it comments on /// still renders. See [adviceFor]. Widget _buildInteractionAdvice(BuildContext context, MainViewModel viewModel) { - final message = adviceFor(passType, viewModel.processingPipeline); + final message = adviceFor(passType, viewModel.processingPipeline, + info: viewModel.videoInfo); if (message == null) return const SizedBox.shrink(); return WarningBanner(message: message); } @@ -198,7 +199,9 @@ class PassSettingsInline extends StatelessWidget { final pipeline = viewModel.processingPipeline; final message = unblendTargetProblem( pipeline.unblend.targetFps, - unblendInputFps(pipeline.deinterlace, fps), + unblendInputFps(pipeline.deinterlace, fps, + softTelecineDecimates: + viewModel.videoInfo!.softTelecineDecimates), ); if (message == null) return const SizedBox.shrink(); return WarningBanner(message: message); diff --git a/app/test/frame_rate_starting_target_test.dart b/app/test/frame_rate_starting_target_test.dart new file mode 100644 index 00000000..9df42d64 --- /dev/null +++ b/app/test/frame_rate_starting_target_test.dart @@ -0,0 +1,230 @@ +// The Frame Rate pass's target as the app reads it, the rate the pass +// receives, and the target it starts at when switched on (task #139). +// +// Run with: flutter test test/frame_rate_starting_target_test.dart + +import 'package:flutter_test/flutter_test.dart'; +import 'package:vapourbox/models/frame_rate_parameters.dart'; +import 'package:vapourbox/models/processing_pipeline.dart'; +import 'package:vapourbox/models/qtgmc_parameters.dart'; +import 'package:vapourbox/models/queue_item.dart'; +import 'package:vapourbox/models/unblend_parameters.dart'; +import 'package:vapourbox/services/field_order_detector.dart'; +import 'package:vapourbox/viewmodels/main_viewmodel.dart'; + +import 'fakes/fake_job_runner.dart'; +import 'fakes/no_source_model_continuity.dart'; + +const film = 24000 / 1001; +const ntsc = 30000 / 1001; + +FrameRateParameters? start(FrameRateParameters p, double fps) => + startingFrameRateTarget(p, fps); + +void main() { + group('frameRateTargetFps', () { + test('every broadcast target', () { + expect(frameRateTargetFps(FrameRateTarget.pal25, 0), 25); + expect(frameRateTargetFps(FrameRateTarget.ntsc2997, 0), ntsc); + expect(frameRateTargetFps(FrameRateTarget.film23976, 0), film); + expect(frameRateTargetFps(FrameRateTarget.film24, 0), 24); + expect(frameRateTargetFps(FrameRateTarget.pal50, 0), 50); + expect(frameRateTargetFps(FrameRateTarget.ntsc5994, 0), 60000 / 1001); + }); + + test('custom is read as the worker reads it (custom_fps_fraction)', () { + double c(double v) => frameRateTargetFps(FrameRateTarget.custom, v); + expect(c(48), 48); + expect(c(12.5), 12.5); + expect(c(59.94), 60000 / 1001); + expect(c(29.97), ntsc); + expect(c(23.976), film); + expect(c(47.952), 48000 / 1001); + expect(c(0), 1, reason: 'clamped to 1–240'); + expect(c(1000), 240); + }); + + test('Unblend reads its targets through the same table', () { + for (final t in FrameRateTarget.values) { + expect(UnblendParameters(target: t, customFps: 24).targetFps, + frameRateTargetFps(t, 24)); + } + }); + }); + + group('frameRateInputFps', () { + const off = QTGMCParameters(enabled: false); + const noUnblend = UnblendParameters(); + + test('no deinterlace: the source rate', () { + expect(frameRateInputFps(off, noUnblend, 25), 25); + }); + + test('double rate doubles it, single rate keeps it', () { + expect(frameRateInputFps(const QTGMCParameters(enabled: true), noUnblend, 25), 50); + expect( + frameRateInputFps( + const QTGMCParameters(enabled: true, fpsDivisor: 2), noUnblend, 25), + 25); + }); + + test('IVTC keeps four frames in five', () { + expect( + frameRateInputFps( + const QTGMCParameters(enabled: true, method: DeinterlaceMethod.ivtc), + noUnblend, + ntsc), + closeTo(film, 1e-9)); + }); + + test('Soft Telecine decimates only at a pulldown rate', () { + const st = QTGMCParameters( + enabled: true, method: DeinterlaceMethod.softTelecine); + expect(frameRateInputFps(st, noUnblend, ntsc), closeTo(film, 1e-9)); + expect( + frameRateInputFps(st, noUnblend, film, softTelecineDecimates: false), + film); + }); + + test('Unblend sets the rate to its target', () { + expect( + frameRateInputFps(const QTGMCParameters(enabled: true), + const UnblendParameters(enabled: true, target: FrameRateTarget.pal25), 25), + 25); + }); + }); + + group('frameRateCloseness', () { + test('equal, close and far', () { + expect(frameRateCloseness(25, 25), FrameRateCloseness.equal); + expect(frameRateCloseness(25, film), FrameRateCloseness.close); + expect(frameRateCloseness(25, 24), FrameRateCloseness.close); + expect(frameRateCloseness(30, ntsc), FrameRateCloseness.close); + expect(frameRateCloseness(50, 25), FrameRateCloseness.far); + expect(frameRateCloseness(ntsc, 25), FrameRateCloseness.far); + expect(frameRateCloseness(25, 0), FrameRateCloseness.far); + }); + }); + + group('startingFrameRateTarget', () { + const p = FrameRateParameters(enabled: true); + + test('the model default is still 25 fps', () { + expect(const FrameRateParameters().target, FrameRateTarget.pal25); + }); + + test('PAL 25 starts at 50', () { + expect(start(p, 25)!.target, FrameRateTarget.pal50); + }); + + test('NTSC 29.97 starts at 59.94', () { + expect(start(p.copyWith(target: FrameRateTarget.ntsc2997), ntsc)!.target, FrameRateTarget.ntsc5994); + }); + + test('film 23.976 starts at 47.952, which the worker reads as 48000/1001', () { + final s = start(p, film)!; + expect(s.target, FrameRateTarget.custom); + expect(s.customFps, 47.952); + expect(s.targetFps, 48000 / 1001); + }); + + test('film 24 and 30 fps start at Custom 48 and 60', () { + final s24 = start(p, 24)!; + expect(s24.target, FrameRateTarget.custom); + expect(s24.customFps, 48); + final s30 = start(p.copyWith(target: FrameRateTarget.ntsc2997), 30)!; + expect(s30.target, FrameRateTarget.custom); + expect(s30.customFps, 60); + }); + + test('another low rate is doubled', () { + final s = start( + p.copyWith(target: FrameRateTarget.custom, customFps: 15), 15)!; + expect(s.target, FrameRateTarget.custom); + expect(s.customFps, 30); + }); + + test('a deliberate conversion is kept', () { + expect(start(p.copyWith(target: FrameRateTarget.ntsc2997), 25), isNull); + expect(start(p, ntsc), isNull, + reason: 'the default 25 on a 29.97 source is a real conversion'); + expect(start(p.copyWith(target: FrameRateTarget.pal50), 25), isNull); + }); + + test('a high input rate is left alone', () { + expect(start(p.copyWith(target: FrameRateTarget.pal50), 50), isNull); + expect(start(p, 50), isNull); + }); + + test('an unknown rate is left alone', () { + expect(start(p, 0), isNull); + }); + + test('the rest of the parameters are kept', () { + final s = start( + p.copyWith(method: FrameRateMethod.rife, sourceFpsNum: 25, sourceFpsDen: 1), + 25)!; + expect(s.method, FrameRateMethod.rife); + expect(s.sourceFpsNum, 25); + expect(s.enabled, isTrue); + }); + }); + + group('switching the pass on (MainViewModel)', () { + TestWidgetsFlutterBinding.ensureInitialized(); + late MainViewModel vm; + + VideoInfo info(double fps) => VideoInfo( + width: 720, + height: 576, + frameRate: fps, + duration: 60, + frameCount: 1500, + codec: 'h264', + pixelFormat: 'yuv420p', + scanType: ScanType.progressive, + hasAudio: true, + ); + + Future select(double? fps) async { + await vm.addMultipleToQueue(['/tmp/vapourbox_test_frame_rate.mkv']); + final item = vm.queue.single; + item.status = QueueItemStatus.ready; + if (fps != null) item.videoInfo = info(fps); + vm.togglePass(PassType.deinterlace, false); + } + + setUp(() { + vm = MainViewModel( + runner: FakeJobRunner(), + continuityService: const NoSourceModelContinuity()); + }); + tearDown(() => vm.dispose()); + + test('a 25p source starts at 50, and the panel shows it', () async { + await select(25); + expect(vm.selectedItem?.videoInfo?.frameRate, 25, + reason: 'the added item must be the selected one'); + vm.togglePass(PassType.frameRate, true); + expect(vm.processingPipeline.frameRate.target, FrameRateTarget.pal50); + expect(vm.getDynamicParams('frame_rate').values['target'], 'pal50'); + }); + + test('no video selected: stays at 25', () async { + vm.togglePass(PassType.frameRate, true); + expect(vm.processingPipeline.frameRate.target, FrameRateTarget.pal25); + }); + + test('a target chosen before is kept when the pass is switched on', + () async { + await select(25); + vm.updateDynamicParams( + 'frame_rate', + vm + .getDynamicParams('frame_rate') + .withValue('target', 'ntsc2997')); + vm.togglePass(PassType.frameRate, true); + expect(vm.processingPipeline.frameRate.target, FrameRateTarget.ntsc2997); + }); + }); +} diff --git a/app/test/pass_advice_test.dart b/app/test/pass_advice_test.dart index 8b626b78..17f21885 100644 --- a/app/test/pass_advice_test.dart +++ b/app/test/pass_advice_test.dart @@ -19,7 +19,10 @@ import 'package:vapourbox/models/noise_reduction_parameters.dart'; import 'package:vapourbox/models/pass_advice.dart'; import 'package:vapourbox/models/processing_pipeline.dart'; import 'package:vapourbox/models/qtgmc_parameters.dart'; +import 'package:vapourbox/models/frame_rate_parameters.dart'; import 'package:vapourbox/models/sharpen_parameters.dart'; +import 'package:vapourbox/models/unblend_parameters.dart'; +import 'package:vapourbox/services/field_order_detector.dart'; void main() { group('silence by default', () { @@ -436,4 +439,140 @@ void main() { } }); }); + + group('frame rate target near the input rate (task #139)', () { + VideoInfo info(double fps, {bool pulldownRate = true, ScanType? scan}) => + VideoInfo( + width: 720, + height: 576, + frameRate: fps, + duration: 60, + frameCount: 1500, + codec: 'h264', + pixelFormat: 'yuv420p', + scanType: scan ?? ScanType.progressive, + hasAudio: true, + pulldownRate: pulldownRate, + ); + const film = 24000 / 1001; + const ntsc = 30000 / 1001; + const noDeint = QTGMCParameters(enabled: false); + + ProcessingPipeline fr(FrameRateParameters f, + {QTGMCParameters deinterlace = noDeint, + UnblendParameters unblend = const UnblendParameters()}) => + ProcessingPipeline( + deinterlace: deinterlace, unblend: unblend, frameRate: f); + + const on25 = FrameRateParameters(enabled: true); + + String? advice(ProcessingPipeline p, VideoInfo? i) => + adviceFor(PassType.frameRate, p, info: i); + + test('an untouched pipeline is silent with a video selected', () { + expect(adviseOn(const ProcessingPipeline(), info: info(25)), isEmpty); + }); + + test('silent when the pass is off', () { + expect(adviseOn(fr(const FrameRateParameters()), info: info(25)), + isEmpty); + }); + + test('silent with no video selected', () { + expect(advice(fr(on25), null), isNull); + }); + + test('25 to 25 converts nothing', () { + final all = adviseOn(fr(on25), info: info(25)); + expect(all.map((a) => a.pass), [PassType.frameRate], + reason: 'the advice attaches to the Frame Rate pass only'); + expect(all.single.message, contains('nothing to convert')); + expect(all.single.message, contains('25 fps')); + }); + + test('23.976 to 25 is close', () { + final m = advice(fr(on25), info(film))!; + expect(m, contains('within 4.3%')); + expect(m, contains('23.976 fps')); + expect(m, contains('not look smoother')); + }); + + test('29.97 to Custom 30 is close, Custom 29.97 is equal', () { + expect( + advice( + fr(on25.copyWith(target: FrameRateTarget.custom, customFps: 30)), + info(ntsc)), + contains('within 0.1%')); + expect( + advice( + fr(on25.copyWith( + target: FrameRateTarget.custom, customFps: 29.97)), + info(ntsc)), + contains('nothing to convert')); + }); + + test('a real conversion is silent', () { + expect(advice(fr(on25.copyWith(target: FrameRateTarget.pal50)), info(25)), + isNull); + expect( + advice( + fr(on25.copyWith(target: FrameRateTarget.custom, customFps: 48)), + info(24)), + isNull); + expect(advice(fr(on25), info(ntsc)), isNull); + }); + + test('a double-rate deinterlace reaches the pass at 50: 25 is silent', () { + expect( + advice( + fr(on25, deinterlace: const QTGMCParameters(enabled: true)), + info(25, scan: ScanType.interlaced)), + isNull); + }); + + test('a single-rate deinterlace keeps 25: 25 converts nothing', () { + expect( + advice( + fr(on25, + deinterlace: + const QTGMCParameters(enabled: true, fpsDivisor: 2)), + info(25, scan: ScanType.interlaced)), + contains('nothing to convert')); + }); + + test('IVTC from 29.97 reaches the pass at 23.976', () { + expect( + advice( + fr(on25.copyWith(target: FrameRateTarget.film23976), + deinterlace: const QTGMCParameters( + enabled: true, method: DeinterlaceMethod.ivtc)), + info(ntsc, scan: ScanType.telecine)), + contains('nothing to convert')); + }); + + test('Soft Telecine at the film rate keeps every frame', () { + const st = + QTGMCParameters(enabled: true, method: DeinterlaceMethod.softTelecine); + final target = on25.copyWith(target: FrameRateTarget.film23976); + expect( + advice(fr(target, deinterlace: st), + info(film, pulldownRate: false, scan: ScanType.softTelecine)), + contains('nothing to convert')); + expect( + advice(fr(target, deinterlace: st), + info(ntsc, scan: ScanType.softTelecine)), + contains('nothing to convert')); + }); + + test('Unblend to 25 ahead of a 25 target converts nothing', () { + expect( + advice( + fr(on25, + deinterlace: const QTGMCParameters(enabled: true), + unblend: const UnblendParameters( + enabled: true, target: FrameRateTarget.pal25)), + info(25, scan: ScanType.interlaced)), + contains('nothing to convert')); + }); + }); } From 5833b517e2a7e3cad438a4cf41bc04ae4988dd7e Mon Sep 17 00:00:00 2001 From: Stuart Cameron Date: Sat, 28 Nov 2026 20:15:33 +1100 Subject: [PATCH 2/2] style(pass-advice): wrap adviceFor's long line (task #139) Co-Authored-By: Claude Opus 5.5 --- app/lib/models/pass_advice.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/lib/models/pass_advice.dart b/app/lib/models/pass_advice.dart index aa1d9350..71c9f9f2 100644 --- a/app/lib/models/pass_advice.dart +++ b/app/lib/models/pass_advice.dart @@ -283,7 +283,8 @@ String _fps(double v) { /// The advice for one pass, or null when there is none. String? adviceFor(PassType pass, ProcessingPipeline pipeline, {VideoInfo? info}) { - final matches = - adviseOn(pipeline, info: info).where((a) => a.pass == pass).map((a) => a.message); + final matches = adviseOn(pipeline, info: info) + .where((a) => a.pass == pass) + .map((a) => a.message); return matches.isEmpty ? null : matches.join('\n\n'); }