Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: write
pull-requests: read

jobs:
native:
Expand Down Expand Up @@ -88,6 +89,20 @@ jobs:
needs: [native, web]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Release text from the changelog
env:
GH_TOKEN: ${{ github.token }}
run: |
v="${GITHUB_REF_NAME#v}"
awk -v v="$v" 'index($0, "## [" v "]") == 1 { p = 1; next } /^## \[/ { p = 0 } p' CHANGELOG.md > body.md
test -s body.md
pr=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq '.[0].html_url' 2>/dev/null || true)
if [ -n "$pr" ]; then { echo; echo "Pull request: $pr"; } >> body.md; fi
prev=$(git describe --tags --abbrev=0 "$GITHUB_REF_NAME^" 2>/dev/null || true)
if [ -n "$prev" ]; then { echo; echo "**Full Changelog**: https://github.com/$GITHUB_REPOSITORY/compare/$prev...$GITHUB_REF_NAME"; } >> body.md; fi
- uses: actions/download-artifact@v4
with:
path: assets
Expand All @@ -96,4 +111,4 @@ jobs:
- uses: softprops/action-gh-release@v2
with:
files: assets/*
generate_release_notes: true
body_path: body.md
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ follow semantic versioning as described in [CONTRIBUTING.md](CONTRIBUTING.md).

## [Unreleased]

## [0.5.2] - 2026-11-26

### Changed

- Auto's motion ceiling works from the motion of the last three seconds instead of the last few frames. Over game
footage the ceiling was crossed at every camera move and Auto went between x2 and x4 of a 60 fps video all the time:
on a 240 Hz display consecutive seconds showed 92 to 228 pictures (median 161), an unsteady rate with a hitch at
every change. Now a run of camera moves keeps one factor (132 to 237, median 228, on the same clip). Footage that
stays fast is still capped, about three seconds after it turns fast instead of 0.3. The recorded 24 fps anime
sessions no longer fall to x2 for a second or two at a fast moment: the Chrome session presents 3274 pictures in
30 s (3226 before), the Firefox one 3222 (3030); the native player's session replays unchanged.

## [0.5.1] - 2026-11-20

### Added
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = ["crates/flyhigh-options", "crates/flyhigh-engine", "crates/flyhigh-ca
default-members = ["crates/flyhigh-options", "crates/flyhigh-engine", "crates/flyhigh-capi", "crates/flyhigh-cli", "examples/player"]

[workspace.package]
version = "0.5.1"
version = "0.5.2"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/getflyhigh/flyhigh-engine"
Expand Down
32 changes: 28 additions & 4 deletions crates/flyhigh-engine/src/pacer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ const AUTO_GRID_VOTES: u32 = 4;
/// not: 60 fps on a 75 Hz display shows every fourth frame twice, and 75 pictures at their own media time are even.
const AUTO_GRID_MIN_RATIO: f64 = 1.15;
const AUTO_HOLD_MS: f64 = 1000.0;
/// The time constant of the motion the ceiling works from. The ceiling used to follow the last few frames, and game
/// footage crosses its thresholds every second or two: Auto then moved between x2 and x4 of a 60 fps video all the
/// time (measured on a 240 Hz display: 92 to 228 pictures in consecutive seconds, an unsteady rate with hitches at
/// every change). Averaged over a few seconds the ceiling describes the scene, not one camera move: a run of moves
/// keeps one factor, and only footage that stays fast is capped.
const MOTION_CEILING_MS: f64 = 3000.0;
/// The motion levels of the ceiling (mean cell difference): above them Auto's factor is capped at 4, 3 and 2.
const MOTION_LEVELS: [f64; 3] = [16.0, 28.0, 45.0];

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Counters {
Expand Down Expand Up @@ -460,6 +468,9 @@ pub struct Pacer {
late_tail_ms: f64,
late_tail_t: f64,
motion_avg: f64,
/// The motion the ceiling works from: the average over `MOTION_CEILING_MS`, and when it was last updated.
motion_ceiling: f64,
motion_ceiling_at: f64,
factor: u32,
/// Since when Auto has asked for a higher (true) or a lower factor than the one in use.
auto_candidate: Option<(bool, f64)>,
Expand Down Expand Up @@ -509,6 +520,8 @@ impl Pacer {
late_tail_ms: 0.0,
late_tail_t: 0.0,
motion_avg: 0.0,
motion_ceiling: 0.0,
motion_ceiling_at: f64::NEG_INFINITY,
factor: 2,
auto_candidate: None,
auto_changed_at: f64::NEG_INFINITY,
Expand Down Expand Up @@ -561,6 +574,8 @@ impl Pacer {
self.late_avg = 0.0;
self.late_tail_ms = 0.0;
self.motion_avg = 0.0;
self.motion_ceiling = 0.0;
self.motion_ceiling_at = f64::NEG_INFINITY;
self.auto_candidate = None;
self.auto_changed_at = f64::NEG_INFINITY;
self.last_pts = None;
Expand Down Expand Up @@ -1070,11 +1085,11 @@ impl Pacer {
let by_gpu = 1.0 + ((0.85 * interval - self.pair_cost()) / self.mid_cost().max(0.01)).max(0.0);
let by_motion = if !self.opts.motion_adaptive {
f64::INFINITY
} else if self.motion_avg > 45.0 {
} else if self.motion_ceiling > MOTION_LEVELS[2] {
2.5
} else if self.motion_avg > 28.0 {
} else if self.motion_ceiling > MOTION_LEVELS[1] {
3.75
} else if self.motion_avg > 16.0 {
} else if self.motion_ceiling > MOTION_LEVELS[0] {
5.0
} else {
f64::INFINITY
Expand Down Expand Up @@ -1161,7 +1176,7 @@ impl Pacer {
limit_to_display: self.opts.limit_to_display,
queue_capacity_hz: self.queue.capacity_hz(self.delay_ms),
headroom: self.opts.display_headroom,
motion_avg: self.motion_avg,
motion_avg: self.motion_ceiling,
motion_adaptive,
penalty: self.control.penalty(),
})
Expand Down Expand Up @@ -1291,6 +1306,15 @@ impl Pacer {
self.motion_avg = self.motion_avg * 0.7 + m * 0.3;
}
}
if let Some(m) = frame.motion.filter(|m| *m < 90.0) {
if self.motion_ceiling_at == f64::NEG_INFINITY {
self.motion_ceiling = m;
} else {
let k = 1.0 - (-(now - self.motion_ceiling_at).max(0.0) / MOTION_CEILING_MS).exp();
self.motion_ceiling += (m - self.motion_ceiling) * k;
}
self.motion_ceiling_at = now;
}
match frame.kind {
IntervalKind::Cut => {
self.counters.cuts += 1;
Expand Down
30 changes: 30 additions & 0 deletions crates/flyhigh-engine/tests/pacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ fn synth(duration_ms: f64, source_fps: f64, mid_ms: f64, pair_ms: f64, gap: impl
Trace { version: 1, host: "synthetic".into(), notes: String::new(), options: None, events }
}

fn with_motion(mut trace: Trace, motion_at: impl Fn(f64) -> f64) -> Trace {
for e in &mut trace.events {
if let TraceEvent::Source { t, motion, .. } = e {
*motion = Some(motion_at(*t));
}
}
trace
}

#[test]
fn auto_keeps_its_factor_through_a_run_of_camera_moves() {
// 60 fps game footage on a 240 Hz display: a 0.3 s camera move every second and a half. The ceiling that followed
// the last few frames sent Auto from x4 to x2 and back at every move.
let flicks =
with_motion(
synth(14_000.0, 60.0, 0.4, 2.0, |_| 1000.0 / 240.0),
|t| if t % 1500.0 < 300.0 { 70.0 } else { 8.0 },
);
let r = run(&flicks, &PacerOptions::default());
let factors: Vec<u32> = r.seconds[3..13].iter().map(|s| s.factor).collect();
assert!(factors.iter().all(|f| *f == 4), "one factor through the moves: {factors:?}");
let presents = presents_per_second(&r, 3);
assert!(presents.iter().all(|p| *p >= 230), "every second at the display's rate: {presents:?}");
// footage that stays fast is still capped
let fast = with_motion(synth(14_000.0, 60.0, 0.4, 2.0, |_| 1000.0 / 240.0), |_| 70.0);
let r = run(&fast, &PacerOptions::default());
let factors: Vec<u32> = r.seconds[8..13].iter().map(|s| s.factor).collect();
assert!(factors.iter().all(|f| *f == 2), "lasting fast motion keeps the low factor: {factors:?}");
}

fn run(trace: &Trace, opts: &PacerOptions) -> Replay {
replay(trace, opts).expect("valid options")
}
Expand Down
Loading