diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 1a78923..af7e9bf 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -369,15 +369,20 @@ struct Picker { #[derive(Clone, Copy, PartialEq, Eq, Debug)] enum Pick { Resolution, + Fps, Fit(Lane, usize), } /// One value a list offers, carrying everything picking it needs -- so a click /// goes straight to the value rather than to a position in a list that was /// built somewhere else. -#[derive(Clone, Copy, PartialEq, Eq, Debug)] +/// `Eq` is off it for the rate: a frame rate is the `f64` the engine is told, +/// bit for bit (23.976023976... is not 23.976), and nothing here keys a map on a +/// choice -- comparing two is all a list row ever does. +#[derive(Clone, Copy, PartialEq, Debug)] enum Choice { Size(u32, u32), + Fps(f64), Fit(Lane, usize, FitPolicy), } @@ -498,6 +503,23 @@ fn keys_rows() -> Vec { /// them, which is what makes the trip round come back to where it started. const RESOLUTIONS: [(u32, u32); 4] = [(3840, 2160), (1920, 1080), (1280, 720), (854, 480)]; +/// The project frame rates the list offers, slowest first: the rates footage is +/// actually shot and delivered at, the NTSC ones written as the ratios they are +/// (`24000/1001`, not `23.976`) -- the engine conforms the timeline to the very +/// number it is handed, so a rate rounded here would be a rate no timescale can +/// name. The media's own is cycled in beside them +/// ([`frame_rate_ladder`]), which is what keeps the way back on the list. +const FRAME_RATES: [f64; 8] = [ + 24_000. / 1001., + 24., + 25., + 30_000. / 1001., + 30., + 50., + 60_000. / 1001., + 60., +]; + /// How far a band may be pushed either way, in dB. The engine clamps nothing /// here -- it will filter whatever it is given -- so this is a UI decision: /// past about this a peaking band stops sounding like tone and starts sounding @@ -1455,6 +1477,23 @@ impl Player { cx.notify(); } + /// The project cut at another rate: the list names one and this is where it + /// happens, the way [`apply_resolution`](Self::apply_resolution) is for a + /// size. The whole timeline is conformed to it by the engine + /// ([`PlaybackSession::set_frame_rate`]) -- same seconds, same footage -- + /// and the rate the app itself counts frames in follows, since every + /// timecode, ruler mark and step key here is measured in it. + fn apply_frame_rate(&mut self, fps: f64, cx: &mut Context) { + if let Some(session) = &mut self.session + && session.set_frame_rate(fps) + { + self.fps = session.meta().frame_rate; + self.notice = Some(format!("PROJECT: {} fps", fps_label(fps)).into()); + self.reset_after_reseek(); + } + cx.notify(); + } + /// Opens a choice list on a setting, where it was asked for. One floating /// thing at a time: the click that opens it is the click that closes /// whatever menu it was opened from. @@ -1472,6 +1511,7 @@ impl Player { self.picker = None; match choice { Choice::Size(w, h) => self.apply_resolution(w, h, cx), + Choice::Fps(fps) => self.apply_frame_rate(fps, cx), Choice::Fit(lane, idx, fit) => self.apply_fit(lane, idx, fit, cx), } } @@ -1487,6 +1527,7 @@ impl Player { Pick::Resolution => { resolution_choices(session.resolution(), session.native_resolution()) } + Pick::Fps => fps_choices(session.meta().frame_rate, session.native_frame_rate()), Pick::Fit(lane, idx) => { fit_choices(lane, idx, session.fit_of(lane, idx), session.resolution()) } @@ -4886,6 +4927,30 @@ impl Player { this.open_picker(Pick::Resolution, event.position(), cx) }), )) + // The rate every clip is counted in, which is also the rate + // the export is written at -- the other half of "the project + // is not the media", and the one the panel could only ever + // read out before. A click opens the rates with this one + // marked; picking one conforms the whole timeline to it. + .child(control( + "fps", + None, + match self.session.is_some() { + true => format!("{} fps", fps_label(self.fps)), + false => "Rate".to_string(), + }, + match self.session.is_some() { + true => format!( + "click to pick a frame rate — the project is cut at {} fps", + fps_label(self.fps) + ), + false => "the project's frame rate — open a file first".to_string(), + }, + live, + cx.listener(|this, event: &ClickEvent, _, cx| { + this.open_picker(Pick::Fps, event.position(), cx) + }), + )) // How much of the timeline the panel below is showing -- // beside the resolution, since neither of them edits // anything: they are both what is being looked at. The @@ -8909,6 +8974,53 @@ fn resolution_choices(current: (u32, u32), native: (u32, u32)) -> Vec .collect() } +/// Every project frame rate on offer, slowest first: [`FRAME_RATES`] with the +/// media's own cycled in at its place by speed, so a project already cut at a +/// listed rate does not see it twice and the media's own rate -- the one a +/// project moved off it has no other way back to -- is always there. +/// [`resolution_ladder`]'s rule, for the other setting the project has of its +/// own. +fn frame_rate_ladder(native: f64) -> Vec { + let mut rates = FRAME_RATES.to_vec(); + // Bit for bit: 23.976023976... is not 23.976, and a rate that read as + // "already listed" when it is not would take the media's own off the list. + if !rates.contains(&native) { + let at = rates + .iter() + .position(|&fps| fps > native) + .unwrap_or(rates.len()); + rates.insert(at, native); + } + rates +} + +/// The rate list's rows: every rung of the ladder, the media's own said so, and +/// the one in force marked. Named as a person writes a rate ([`fps_label`]), +/// with what it is for beside it -- short, or the row loses its tail to the +/// truncation the resolution list already met. +fn fps_choices(current: f64, native: f64) -> Vec { + frame_rate_ladder(native) + .into_iter() + .map(|fps| { + ( + Choice::Fps(fps), + format!("{} fps", fps_label(fps)).into(), + match fps == native { + true => "the media's own".to_string(), + // The rates that are a ratio are the ones nobody can tell + // from their neighbour by the label alone. + false => match (fps - fps.round()).abs() < 0.001 { + true => String::new(), + false => "NTSC".to_string(), + }, + } + .into(), + fps == current, + ) + }) + .collect() +} + /// The fit list's rows: all four policies against the canvas they place a /// picture on, since the word alone ("fill") says nothing about the size it is /// filling -- which is the very thing the notice says after a stroke. @@ -10272,7 +10384,8 @@ mod tests { bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, containers, enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, estimated_mb, export_path, export_settings, format_key, - format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, + format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, + frame_rate_ladder, histogram, inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, @@ -10281,7 +10394,7 @@ mod tests { whole_take, window_title, }; use super::{ - Choice, Edge, FITS, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, + Choice, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, fit_choices, library_rows, live_idx, next_fit, next_resolution, px_along, repeats, resolution_choices, resolution_ladder, span_label, trimmed_clip, unscannable, visible_slice, @@ -12948,10 +13061,35 @@ mod tests { assert!(fits[2].3, "the clip's own policy is not marked"); assert!(fits[0].2.contains("1920x1080"), "{}", fits[0].2); + // The rate list, the other setting the project has of its own: every + // rate on offer, the media's own cycled in at its place by speed and + // said so, and the one the timeline is cut at marked. The value carried + // is the `f64` the engine conforms to, not the rounded label -- 23.976 + // is not 24000/1001, and a rate the timescales cannot name is refused. + let ntsc = 24_000. / 1001.; + let rates = frame_rate_ladder(25.); + assert_eq!(rates.len(), FRAME_RATES.len(), "25 is already on the list"); + let odd = frame_rate_ladder(48.); + assert_eq!(odd[5], 48., "the media's own, in its place by speed"); + assert_eq!(odd.len(), FRAME_RATES.len() + 1); + let fps = fps_choices(ntsc, 48.); + assert_eq!(fps.len(), odd.len()); + assert_eq!(fps.iter().filter(|(.., picked)| *picked).count(), 1); + assert_eq!(fps[0].0, Choice::Fps(ntsc), "the ratio, not 23.976"); + assert_eq!(fps[0].1.as_ref(), "23.976 fps"); + assert!(fps[0].3, "the rate in force is not marked"); + assert!(fps[5].2.contains("the media's own"), "{}", fps[5].2); + for (.., detail, _) in &fps { + assert!(detail.chars().count() < 26, "{detail} loses its tail"); + } + // The open list fits the floor the menus are measured against: the - // longest of them is the resolution ladder, and it hangs at the pointer - // with every row on screen. Rows are click targets (WCAG 2.5.8). + // longest of them is the rate ladder with an odd rate cycled in, and it + // hangs at the pointer with every row on screen. Rows are click targets + // (WCAG 2.5.8). assert!(MENU_ROW_H >= HIT_MIN); + assert!(odd.len() > ladder.len(), "the longest list moved"); + assert!(MENU_PAD * 2. + odd.len() as f32 * MENU_ROW_H <= 360.); let tall = MENU_PAD * 2. + ladder.len() as f32 * MENU_ROW_H; assert!(tall <= 360., "the list is taller than the floor"); assert_eq!( diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index 0a8890c..9b3927a 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -19,10 +19,13 @@ //! gain audio 1 -3.0 //! ``` //! -//! The `fps` line is the rate the timeline was cut at, printed so it reads back -//! bit-exactly. A file without one (every dialect before v9) means "whatever -//! the scaffolding source runs at", which is what such a project always was and -//! is an answer only a project holding a video has +//! The `fps` line is the rate the timeline was cut at -- the scaffolding +//! source's own unless a rate was picked +//! ([`crate::PlaybackSession::set_frame_rate`]), and the *only* thing that says +//! so once one was, since every clip number in the file is counted in it. +//! Printed so it reads back bit-exactly. A file without one (every dialect +//! before v9) means "whatever the scaffolding source runs at", which is what +//! such a project always was and is an answer only a project holding a video has //! ([`crate::PlaybackSession::open_project`]). //! //! A `subtitle` line is `subtitle `: which track of that file the diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index d6b06cd..cd1ad4e 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -158,6 +158,11 @@ pub struct PlaybackSession { /// starts here, and a caller offering sizes to pick from needs the media's /// own among them or a project moved off it could never come back. native: (u32, u32), + /// ...and the scaffolding source's own frame rate, kept for exactly that + /// reason: the project rate starts here, and the list a caller offers rates + /// from needs the media's own on it or a project moved off it has no way + /// back ([`PlaybackSession::set_frame_rate`] is not an undo step either). + native_fps: f64, frames: Receiver, /// The current decode worker. worker: Worker, @@ -277,6 +282,7 @@ impl PlaybackSession { Ok(Self { meta, native: (meta.width, meta.height), + native_fps: meta.frame_rate, frames: stream.frames, worker: stream.worker, backend: stream.backend, @@ -375,6 +381,7 @@ impl PlaybackSession { Ok(Self { meta, native: (width, height), + native_fps: frame_rate, frames: stream.frames, worker: stream.worker, backend: stream.backend, @@ -451,6 +458,7 @@ impl PlaybackSession { Ok(Self { meta, native: (meta.width, meta.height), + native_fps: IMAGE_ONLY_RATE, frames: stream.frames, worker: stream.worker, backend: stream.backend, @@ -585,6 +593,32 @@ impl PlaybackSession { meta.width = width; meta.height = height; } + // ...and the project's own *rate*, which is the scaffold's unless the + // file says otherwise. The two made-up rates above already took the + // saved one (their counts are computed from it); a scaffold with a + // picture keeps its own here, so a project cut at a rate nobody picked + // is the file it always was -- and one where a rate *was* picked + // ([`set_frame_rate`](Self::set_frame_rate)) comes back at it rather + // than at the media's, which would leave every clip number counted in + // frames the timeline no longer has. + let native_fps = match crate::is_audio(&first.path) { + true => AUDIO_ONLY_CANVAS.2, + false if crate::is_image(&first.path) => IMAGE_ONLY_RATE, + false => meta.frame_rate, + }; + if let Some(fps) = saved_fps { + meta.frame_rate = fps; + } + // A song and a still have no rate of their own to be conformed from: + // their length above was counted in the timeline's frames already, + // whatever those are. A file with pictures is read through [`Rate`] like + // any other source when the project is cut at another rate. + let made_up = crate::is_audio(&first.path) || crate::is_image(&first.path); + let scaffold_rate = match made_up || native_fps == meta.frame_rate { + true => Rate::REAL_TIME, + false => Rate::from_fps(native_fps, meta.frame_rate) + .map_err(|e| format!("source {}: {e}", first.path.display()))?, + }; let first_audio = first_audio_of(&doc.sources)?; // In source order, with the scaffold's own count in its own slot: the @@ -599,8 +633,8 @@ impl PlaybackSession { let mut rates = Vec::with_capacity(doc.sources.len()); for (i, source) in doc.sources.iter().enumerate() { if i == scaffold { - counts.push(meta.frame_count); - rates.push(Rate::REAL_TIME); + counts.push(scaffold_rate.timeline_at(meta.frame_count)); + rates.push(scaffold_rate); continue; } // A still has neither a rate to match nor a track to match with: @@ -704,6 +738,7 @@ impl PlaybackSession { let mut session = Self { meta, native, + native_fps, frames: stream.frames, worker: stream.worker, backend: stream.backend, @@ -1442,6 +1477,62 @@ impl PlaybackSession { true } + /// The scaffolding source's own frame rate -- what the project rate started + /// as, and the one rate a caller offering a list of them must not leave out + /// ([`native_resolution`](Self::native_resolution)'s reason). + pub fn native_frame_rate(&self) -> f64 { + self.native_fps + } + + /// Cuts this timeline at `fps` from here on: every clip is *conformed* to + /// the new rate ([`Project::retime`]), every source is read through a + /// [`Rate`] against it, and an export written from this session comes out at + /// it. The edit survives as the same seconds of the same footage on a finer + /// or coarser grid -- a 30 fps take on a timeline moved to 24 keeps its + /// length and its sync, it is simply counted in 24ths now. + /// + /// Reseeks like [`set_resolution`](Self::set_resolution), so the picture and + /// the sound under the playhead are already the new rate's when this + /// returns. `false` -- changing nothing -- for a rate that is not a rate, for + /// the one already in force, and for one no timescale can name + /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate + /// is refused at). + /// + /// ponytail: not an undo step, exactly as the project resolution is not -- + /// and this one *moves the frame numbers*, so the way back is picking the + /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate)) + /// rather than a `z`, and it lands within a frame of where it started rather + /// than on it (see [`Project::retime`]). Upgrade path is the same one: the + /// project's settings snapshotted beside the lanes. + pub fn set_frame_rate(&mut self, fps: f64) -> bool { + if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate { + return false; + } + // Old timeline frames per new one, exactly -- the one map every frame + // number on every lane goes through. Built before anything is touched, + // since a rate no timescale can name is a refusal and not a half-retimed + // project. + let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else { + return false; + }; + // Lengths first: the retime holds every clip inside its source's *new* + // length, so a clip that played to the last frame of its file still + // does rather than naming one past the end. + for count in &mut self.counts { + *count = k.timeline_at(*count).max(1); + } + self.project.retime(k, &self.counts); + // A file's own rate has not changed; what it is *against* has. + for rate in &mut self.rates { + *rate = rate.then(k); + } + self.meta.frame_rate = fps; + self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1); + let now = self.now(); + self.seek(now); + true + } + /// How the clip at `idx` of `lane` meets a project canvas of another shape. pub fn fit_of(&self, lane: Lane, idx: usize) -> FitPolicy { self.project.fit_of(lane, idx) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index b9e6774..4580676 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -289,6 +289,11 @@ impl Rate { // fps is scale/ticks, so the ratio is (src_scale/src_ticks) / (tl_scale/tl_ticks). let num = u64::from(src_scale) * u64::from(tl_ticks); let den = u64::from(src_ticks) * u64::from(tl_scale); + Ok(Self::reduced(num, den)) + } + + /// `num` frames of a file per `den` frames of a timeline, in lowest terms. + fn reduced(num: u64, den: u64) -> Self { let g = gcd(num, den); let (mut num, mut den) = (num / g, den / g); // A ratio no pair of real frame rates produces, but the fields are `u32` @@ -296,10 +301,22 @@ impl Rate { while num > u64::from(u32::MAX) || den > u64::from(u32::MAX) { (num, den) = (num.div_ceil(2), den.div_ceil(2)); } - Ok(Self { + Self { source: num.max(1) as u32, timeline: den.max(1) as u32, - }) + } + } + + /// The same file against a timeline that has itself been retimed: `self` is + /// its frames per frame of the old timeline and `k` is old frames per new + /// one, so this is its frames per frame of the *new* one -- exactly, without + /// going back through an `f64` fps that names neither rate + /// ([`crate::PlaybackSession::set_frame_rate`]). + pub fn then(self, k: Rate) -> Self { + Self::reduced( + u64::from(self.source) * u64::from(k.source), + u64::from(self.timeline) * u64::from(k.timeline), + ) } pub fn is_real_time(self) -> bool { @@ -1423,6 +1440,52 @@ impl Project { true } + /// Every frame number on every lane rewritten onto a timeline counted at + /// another rate: `k` is old timeline frames per new one, `counts` is how + /// long each source is on the *new* timeline (indexed as + /// [`Project::sources`] is), and the edit survives as the same seconds of + /// the same footage. What [`crate::PlaybackSession::set_frame_rate`] does to + /// the edit list, and the only thing that touches the frame numbers without + /// being an edit anyone made. + /// + /// Every position -- a clip's start and its end alike -- goes through the + /// one map [`Rate::timeline_at`], so two clips that met still meet, a gap + /// stays a gap, and a take's picture and its sound land on the same frame on + /// their two lanes: no lane can drift against another. A clip is then only + /// ever made to *fit* the room its own start and end mapped to, never to + /// outgrow it, which is what keeps the lane sorted and disjoint (the cursor + /// below is the backstop for the one case that could: a slow clip so short + /// that no source range fits its new room at all). + /// + /// ponytail: not exact both ways. Each rate change re-rounds every boundary + /// onto the new grid, so a rate picked, unpicked and picked again is within + /// a frame of where it started rather than back at it. Upgrade path is + /// keeping the edit list at one reference rate and conforming on the way + /// out, which every frame number in this module would then be measured in. + pub fn retime(&mut self, k: Rate, counts: &[u32]) { + for lane in &mut self.lanes { + let mut cursor = 0; + for clip in &mut lane.clips { + let start = k.timeline_at(clip.start).max(cursor); + // The room its own end mapped to -- never zero, since a clip is + // never empty even on a grid too coarse to hold it. + let room = k.timeline_at(clip.end()).saturating_sub(start).max(1); + let count = counts.get(clip.source).copied().unwrap_or(u32::MAX).max(1); + // Its footage, held inside the file's new length: a clip whose + // out-point was the last frame of its source must not come out + // of this naming a frame past the end -- that is a project that + // would not open again ([`crate::PlaybackSession::open_project`] + // refuses one by name). + let in_frame = k.timeline_at(clip.in_frame).min(count - 1); + let len = clip.speed.fit(room).unwrap_or(1).clamp(1, count - in_frame); + clip.start = start; + clip.in_frame = in_frame; + clip.out_frame = in_frame + len; + cursor = clip.end(); + } + } + } + /// Length of the timeline in frames: where the *last* lane runs out. A lane /// that ends early is a trailing gap in that lane, not a shorter timeline. pub fn timeline_frames(&self) -> u32 { diff --git a/crates/engine/tests/mixed_fps.rs b/crates/engine/tests/mixed_fps.rs index 68d8156..f0f02c6 100644 --- a/crates/engine/tests/mixed_fps.rs +++ b/crates/engine/tests/mixed_fps.rs @@ -323,6 +323,115 @@ fn a_mixed_rate_project_reloads_unchanged() { std::fs::remove_file(&path).ok(); } +/// The project's rate is the user's to pick, exactly as its resolution is. The +/// timeline is *conformed* to it -- the same seconds of the same footage, +/// counted on a new grid -- every source is read through a [`Rate`] against it, +/// the media's own rate stays reachable, and a save comes back at the rate it +/// was cut at rather than at the media's. +#[test] +fn the_project_rate_is_picked_and_the_timeline_is_conformed_to_it() { + let pal = asset("test_25fps.mp4"); + let mut session = open(asset("test_av.mp4")); + import_and_place(&mut session, &pal); + let duration = session.timeline_duration(); + assert_eq!(session.native_frame_rate(), FPS, "the media's own rate"); + assert!(!session.set_frame_rate(FPS), "the rate already in force"); + assert!(!session.set_frame_rate(0.0), "not a rate at all"); + + assert!( + session.set_frame_rate(24.0), + "24 is a rate a timescale can name" + ); + assert_eq!(session.meta().frame_rate, 24.0); + assert!( + (session.timeline_duration() - duration).abs() < 1.0 / 24.0, + "the timeline is {} s where it was {duration} s", + session.timeline_duration() + ); + // Both files are read through a rate against the new grid now: 5 s and 2 s, + // in 24ths. + assert_eq!(session.file_frames(&asset("test_av.mp4")), 120, "5 s at 24"); + assert_eq!(session.file_frames(&pal), 48, "2 s at 24"); + // ...and each take is still one take on both lanes: every frame number goes + // through one map, so a picture cannot drift off its sound. + let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)); + assert_eq!(video.len(), 2, "the 30 fps take and the 25 fps one"); + for (v, a) in video.iter().zip(audio) { + assert_eq!((v.start, v.len()), (a.start, a.len()), "{v:?} vs {a:?}"); + } + + let path = std::env::temp_dir().join(format!("edith-rate-{}.edith", std::process::id())); + session.save_project(&path).expect("save"); + let reloaded = PlaybackSession::open_project(&path).expect("a retimed project reopens"); + assert_eq!(reloaded.meta().frame_rate, 24.0, "the rate it was cut at"); + assert_eq!( + reloaded.clip_spans(), + session.clip_spans(), + "the same clips" + ); + assert_eq!(reloaded.file_frames(&pal), 48, "recomputed against 24"); + assert_eq!( + reloaded.native_frame_rate(), + FPS, + "the way back is still there" + ); + std::fs::remove_file(&path).ok(); + + // ...and that way back is a pick like any other: the media's own rate. + let native = session.native_frame_rate(); + assert!(session.set_frame_rate(native), "back to the media's own"); + assert_eq!(session.file_frames(&pal), 60, "2 s at 30 again"); + assert!( + (session.timeline_duration() - duration).abs() < 1.0 / 24.0, + "{} s after the round trip, {duration} s before", + session.timeline_duration() + ); +} + +/// ...and an export of it comes out at that rate: the file is written at 24 fps, +/// as many frames as the conformed timeline has, with its sound as long as its +/// picture. +#[test] +fn an_export_runs_at_the_rate_the_project_was_cut_at() { + let mut session = open(asset("test_av.mp4")); + assert!( + session.trim_clip(Lane::V1, 0, Edge::End, 30), + "one second of the 30 fps take" + ); + assert!(session.set_frame_rate(24.0), "cut it at 24 instead"); + let total = (session.timeline_duration() * 24.0).round() as u32; + assert_eq!(total, 24, "one second, in 24ths"); + + let out = std::env::temp_dir().join(format!("edith-rate-{}.mp4", std::process::id())); + wait(&session.export_to_with( + &out, + &ExportSettings { + format: Format::Mp4, + ..ExportSettings::default() + }, + )) + .expect("the export"); + + let (meta, _rx, _cancel) = DecodeSession::open_range(&out, 0, u32::MAX).expect("reopen"); + assert!( + (meta.frame_rate - 24.0).abs() < 0.01, + "the export runs at the picked rate: {}", + meta.frame_rate + ); + assert_eq!( + meta.frame_count, total, + "the export is the timeline's length" + ); + let secs = engine::AudioSession::duration_secs(&out) + .expect("probe the export") + .expect("the export has sound"); + assert!( + (secs - f64::from(total) / 24.0).abs() < 0.05, + "sound is {secs} s under a second of picture" + ); + std::fs::remove_file(&out).ok(); +} + /// The export is what was watched: as many frames as the timeline has, and the /// 25 fps clip walked through its file at 25 fps -- 25 pictures over 30 frames, /// not 30 of them and not 25 held to the end.