diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index 34b027f..588cdb4 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -71,7 +71,7 @@ impl Quality { } other => format!( "{} Mbps", - export_settings(other, 0, Format::Mp4, DEFAULT_AUDIO_KBPS) + export_settings(other, 0, Format::Mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto) .bitrate .unwrap_or_default() / 1_000_000 @@ -459,6 +459,52 @@ pub(crate) fn audio_rate_choices(current: u32) -> Vec { .collect() } +/// How a seat is named where a person reads it: the card row, the notice and +/// the list row all say the same word ([`engine::export::EncoderSeat`]). +pub(crate) fn encoder_label(seat: EncoderSeat) -> &'static str { + match seat { + EncoderSeat::Auto => "Auto", + EncoderSeat::Hardware => "Hardware", + EncoderSeat::Software => "Software", + } +} + +/// The encoder list's rows: all three seats, the one in force marked, and what +/// each one *does* beside it -- in the fewest words that fit inside `MENU_W`, +/// the truncation every list above already met. Always offered, whatever this +/// machine has: a row that vanished with the plugin would be a setting nobody +/// could find, and the answer to "is there a seat here?" is the planned line +/// under the rows ([`engine::export::planned_video`]), which is measured. +pub(crate) fn encoder_choices(current: EncoderSeat) -> Vec { + EncoderSeat::ALL + .into_iter() + .map(|seat| { + ( + Choice::Encoder(seat), + encoder_label(seat).into(), + match seat { + EncoderSeat::Auto => "the GPU if there is one", + EncoderSeat::Hardware => "the GPU or a refusal", + EncoderSeat::Software => "the CPU, always", + } + .into(), + seat == current, + ) + }) + .collect() +} + +/// The row under the encoder one where -- and only where -- a person has asked +/// for the GPU on an AV1 export: this project's own driver reset the GPU on the +/// vendored AV1 encoder (2026-08-10), so the pick is theirs to make and the +/// risk is theirs to be told about. `None` for every other pair, which is what +/// keeps this from becoming a row nobody reads. +pub(crate) fn av1_hw_warning(format: Format, seat: EncoderSeat) -> Option<&'static str> { + (seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4)).then_some( + "AV1 on the GPU reset this machine's driver once — Software is the safe seat", + ) +} + /// How a rendition is named where a person reads it: the panel button, the /// notice and the list row all say the same word ([`engine::tonemap::Preset`]). pub(crate) fn tone_label(preset: Preset) -> &'static str { @@ -623,6 +669,7 @@ pub(crate) fn export_settings( custom_mbps: u32, format: Format, audio_kbps: u32, + seat: EncoderSeat, ) -> ExportSettings { ExportSettings { format, @@ -637,10 +684,10 @@ pub(crate) fn export_settings( Quality::High => Some(12_000_000), Quality::Custom => Some(u64::from(custom_mbps) * 1_000_000), }, - // No row of its own: the software pin is for a driver that encodes - // badly, which is a thing about the machine and not about the output -- - // `VE_SW_ENC` already says it, and to the whole run rather than once. - force_sw: false, + // The card's own row now ([`encoder_choices`]), kept with the project: + // it was a `VE_SW_ENC` env pin and nothing else, which is a switch + // nobody exporting a film would ever find. + seat, // The picked track is put on by `start_export`, which is the only // caller that writes a file; the rest of them are asking about the // bitrate and the format. diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 457c9e0..57f2880 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -420,7 +420,7 @@ fn codec_chord() -> String { .join(" / ") } -pub static FIXED: std::sync::LazyLock<[Fixed; 29]> = std::sync::LazyLock::new(|| { +pub static FIXED: std::sync::LazyLock<[Fixed; 30]> = std::sync::LazyLock::new(|| { [ // Not a chord at all but a way of pressing one, and the only place the // editor can say so: holding a key that moves a *value* runs it, and @@ -487,6 +487,12 @@ pub static FIXED: std::sync::LazyLock<[Fixed; 29]> = std::sync::LazyLock::new(|| category: Category::File, reach: Reach::Click("sound"), }, + Fixed { + chord: "e".into(), + label: "Step the export encoder seat: Auto, Hardware or Software", + category: Category::File, + reach: Reach::Click("encoder"), + }, Fixed { chord: "d".into(), label: "Choose where the export is written", diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 22752b5..690a86d 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -56,7 +56,7 @@ use engine::audio::StreamInfo; use engine::color::ColorParams; use engine::decode::Backend; use engine::eq::{Band, BandKind, EqParams}; -use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, ExportSettings, Format}; +use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, EncoderSeat, ExportSettings, Format}; use engine::limiter::Limiter; use engine::project::{Edge, Lane, LaneKind, Source, Speed}; use engine::scale::FitPolicy; diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index 3e19ccb..1e26fb7 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -61,6 +61,10 @@ pub(crate) enum Pick { /// here that is nobody's project: it is the person's, so it outlives the /// timeline and every file opened in it. Theme, + /// Which encoder an export writes the picture with + /// ([`engine::export::EncoderSeat`]). Opened from the card's Encoder row, + /// which is the only place it means anything. + Encoder, } /// One value a list offers, carrying everything picking it needs -- so a click @@ -77,6 +81,7 @@ pub(crate) enum Choice { AudioRate(u32), Tone(Preset), Theme(ui::theme::PaletteId), + Encoder(EncoderSeat), } /// One row of an open list: the value, its name, the small print beside it, and diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 7f429ba..01906ea 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -94,6 +94,10 @@ impl Player { Choice::Fps(fps) => self.apply_frame_rate(fps, cx), Choice::Fit(lane, idx, fit) => self.apply_fit(lane, idx, fit, cx), Choice::Tone(preset) => self.apply_tone(preset, cx), + // The project's, like the tone map above and unlike the palette + // below: kept in the `.edith` and read straight back out of the + // session by the card and by the export. + Choice::Encoder(seat) => self.apply_encoder(seat, cx), // In force for the next paint -- every token is read through // [`ui::theme::palette`], so one store repaints the whole window -- // and kept for the next launch. A file that could not be written is @@ -151,6 +155,7 @@ impl Player { } Pick::AudioRate => audio_rate_choices(self.audio_kbps), Pick::Tone => tone_choices(session.tone()), + Pick::Encoder => encoder_choices(session.encoder_seat()), // Answered above, with or without a timeline. Pick::Theme => Vec::new(), } diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 191e214..9666185 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -219,7 +219,13 @@ impl Player { return; }; let settings = - export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); + export_settings( + self.quality, + self.custom_mbps, + self.format, + self.audio_kbps, + self.encoder_seat(), + ); if !self.export_open { return; } @@ -380,6 +386,44 @@ impl Player { self.audio_kbps = next_audio_kbps(self.audio_kbps); } + /// Which encoder an export of this project would write the picture with + /// ([`engine::export::EncoderSeat`]). The session's, because it is saved + /// with the project -- there is no card-local copy to drift from it -- and + /// the default with no timeline open, where the card shows nothing anyway. + pub(crate) fn encoder_seat(&self) -> EncoderSeat { + self.session + .as_ref() + .map_or_else(EncoderSeat::default, PlaybackSession::encoder_seat) + } + + /// Pick the seat. Said out loud like every other pick that changes what a + /// file will be written by -- and the card's planned line re-probes by + /// itself, since the settings it is keyed on have changed + /// ([`Self::cache_export_seat`]). + pub(crate) fn apply_encoder(&mut self, seat: EncoderSeat, cx: &mut Context) { + if let Some(session) = &mut self.session { + session.set_encoder_seat(seat); + self.notify_user(format!("Encoder: {}", encoder_label(seat)).into()); + } + cx.notify(); + } + + /// The seat by keyboard, wrapping through the three -- the Sound row's + /// rule, for the row beside it. Refused by name with no timeline: a key + /// that silently does nothing is the card looking broken. + pub(crate) fn cycle_encoder(&mut self, cx: &mut Context) { + let Some(session) = &self.session else { + self.notify_user("no timeline to export — open a file first".into()); + cx.notify(); + return; + }; + let at = EncoderSeat::ALL + .iter() + .position(|&s| s == session.encoder_seat()) + .unwrap_or(0); + self.apply_encoder(EncoderSeat::ALL[(at + 1) % EncoderSeat::ALL.len()], cx); + } + /// Why the sound row is not a choice right now, the engine answering about /// the very project it would export. No session is the same answer as no /// sound: there is nothing to write either way. @@ -517,7 +561,13 @@ impl Player { return; } let mut settings = - export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); + export_settings( + self.quality, + self.custom_mbps, + self.format, + self.audio_kbps, + self.encoder_seat(), + ); // Whatever is on the timeline travels -- every track with a cue in the // exported range, not the one row the overlay happens to be drawing. // Set here rather than inside `export_settings`, which the card also diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 6187a76..db07b7e 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -246,6 +246,11 @@ impl Render for Player { // The sound's rate, `q`'s pair for the other half of // the file. Not a digit: those are the picture's. this.cycle_audio_kbps(); + } else if key == "e" { + // Which encoder writes the picture, `b`'s neighbour for + // the other thing about the file a person picks rather + // than types. Card-local like the rest of these. + this.cycle_encoder(cx); } else if key == "d" { // The save dialog, which was the one row here a // keyboard could not open. diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index ae76269..c162562 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -815,24 +815,24 @@ fn a_quality_row_is_the_bitrate_it_promises() { // a number typed against the custom row must not leak into it. let mp4 = Format::Mp4; assert_eq!( - export_settings(Quality::Auto, 7, mp4, DEFAULT_AUDIO_KBPS).bitrate, + export_settings(Quality::Auto, 7, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, None ); assert_eq!( - export_settings(Quality::Low, 0, mp4, DEFAULT_AUDIO_KBPS).bitrate, + export_settings(Quality::Low, 0, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, Some(2_000_000) ); assert_eq!( - export_settings(Quality::Medium, 0, mp4, DEFAULT_AUDIO_KBPS).bitrate, + export_settings(Quality::Medium, 0, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, Some(6_000_000) ); assert_eq!( - export_settings(Quality::High, 0, mp4, DEFAULT_AUDIO_KBPS).bitrate, + export_settings(Quality::High, 0, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, Some(12_000_000) ); // Megabits as typed, and as the row says it back. assert_eq!( - export_settings(Quality::Custom, 7, mp4, DEFAULT_AUDIO_KBPS).bitrate, + export_settings(Quality::Custom, 7, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, Some(7_000_000) ); assert_eq!(Quality::Low.detail(0), "2 Mbps"); @@ -840,7 +840,7 @@ fn a_quality_row_is_the_bitrate_it_promises() { // choice the engine never hears about. for format in [Format::Mp4, Format::Wav, Format::Flac] { assert_eq!( - export_settings(Quality::Auto, 0, format, DEFAULT_AUDIO_KBPS).format, + export_settings(Quality::Auto, 0, format, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).format, format ); } @@ -849,7 +849,7 @@ fn a_quality_row_is_the_bitrate_it_promises() { // silently changes -- the ceiling row included, which is the one a // raised cap could have walked out past. for quality in Quality::ALL { - let settings = export_settings(quality, MBPS_MAX, mp4, DEFAULT_AUDIO_KBPS); + let settings = export_settings(quality, MBPS_MAX, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto); if let Some(bitrate) = settings.bitrate { assert!( (u64::from(MBPS_MIN) * 1_000_000..=u64::from(MBPS_MAX) * 1_000_000) @@ -857,8 +857,9 @@ fn a_quality_row_is_the_bitrate_it_promises() { "{quality:?} outside the engine clamp" ); } - // The software pin is the environment's to set, never a row's. - assert!(!settings.force_sw); + // The seat travels exactly as it was picked, and an unpicked project + // exports on the seat this machine has. + assert_eq!(settings.seat, EncoderSeat::Auto); } } @@ -879,7 +880,7 @@ fn the_sound_row_carries_its_rate_into_both_kinds_of_file() { for format in [Format::Mp4, Format::Av1, Format::Hevc, Format::Mp3] { for kbps in AUDIO_KBPS { assert_eq!( - export_settings(Quality::Auto, 0, format, kbps).audio_kbps, + export_settings(Quality::Auto, 0, format, kbps, EncoderSeat::Auto).audio_kbps, Some(kbps), "{format:?} at {kbps} kbps" ); @@ -1198,6 +1199,34 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { } assert!(tones[1].3, "the rendition in force is not marked"); + // The encoder list, the export card's own: all three seats, the one in + // force marked, and a row each saying what it does. The AV1 warning + // belongs to exactly one pair -- the GPU on an AV1 file -- so it cannot + // become a line nobody reads. + let seats = encoder_choices(EncoderSeat::Software); + assert_eq!(seats.len(), EncoderSeat::ALL.len()); + assert_eq!(seats.iter().filter(|(.., picked)| *picked).count(), 1); + for (row, seat) in seats.iter().zip(EncoderSeat::ALL) { + assert_eq!(row.0, Choice::Encoder(seat)); + assert_eq!(row.1.as_ref(), encoder_label(seat)); + assert!(!row.2.is_empty(), "{seat:?} says nothing about itself"); + assert!(row.2.chars().count() < 26, "{} loses its tail", row.2); + } + assert!(seats[2].3, "the seat in force is not marked"); + for format in [Format::Av1, Format::Av1Mp4] { + assert!(av1_hw_warning(format, EncoderSeat::Hardware).is_some()); + for seat in [EncoderSeat::Auto, EncoderSeat::Software] { + assert_eq!(av1_hw_warning(format, seat), None, "{seat:?} is the safe seat"); + } + } + for format in [Format::Mp4, Format::Hevc, Format::HevcMp4, Format::Wav] { + assert_eq!( + av1_hw_warning(format, EncoderSeat::Hardware), + None, + "{format:?} is not the encoder that reset the driver" + ); + } + // The open list fits the floor the menus are measured against: the // 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 diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 3714af5..b1939ad 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -13,7 +13,7 @@ use super::{ ACCENT_PRIMARY, AUDIO_KBPS, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, - EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, FORMATS, + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, FG_PRIMARY, FG_SECONDARY, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, BG_CANVAS, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, @@ -41,7 +41,8 @@ use super::{ use super::{ Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, Scale, View, - ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, + ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, av1_hw_warning, clock, + encoder_choices, encoder_label, eta_secs, file_name, file_uri, fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, note_progress, px_along, IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line, diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 4d343e4..740012e 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -286,6 +286,39 @@ impl Player { })); } list.push(r.into_any_element()); + // Which encoder writes the picture, which was an env pin and therefore + // no choice at all. Three seats, so the pointer gets the *list* of them + // ([`Pick::Encoder`]) and never a button clicked round -- the Sound + // row's rule, one row above. Only where there is a picture to encode: + // a WAV has no seat to pick and the row would be a question about + // nothing. + if self.format.has_video() { + let seat = self.encoder_seat(); + list.push( + entry( + ("encoder", 0), + "e", + "Encoder".into(), + format!("{} — e steps", encoder_label(seat)).into(), + false, + true, + ) + .on_click(cx.listener(|this, event: &ClickEvent, _, cx| { + this.open_picker(Pick::Encoder, event.position(), cx) + })) + .into_any_element(), + ); + // ...and, under it, the one thing about that pick a person cannot + // know from the words in the list: this box's driver reset itself + // on the vendored AV1 encoder. A dimmed row and not a modal -- the + // pick is theirs, and the export runs. + if let Some(warning) = av1_hw_warning(self.format, seat) { + list.push( + entry(("encoder-av1", 0), "", "".into(), warning.into(), false, false) + .into_any_element(), + ); + } + } // What happens to the subtitles on this timeline, in one line: how many // are written into the file and under what names, or the reason each one // is not. Which tracks travel is not a pick -- everything with a cue on @@ -431,7 +464,13 @@ impl Player { |(_, audio)| audio, ); let settings = - export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); + export_settings( + self.quality, + self.custom_mbps, + self.format, + self.audio_kbps, + self.encoder_seat(), + ); let size = estimated_bytes( settings.bitrate.filter(|_| self.format.has_video()), self.session diff --git a/crates/engine/examples/bench.rs b/crates/engine/examples/bench.rs index 3e2b536..f7e2b44 100644 --- a/crates/engine/examples/bench.rs +++ b/crates/engine/examples/bench.rs @@ -44,7 +44,7 @@ use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; -use engine::export::{ExportSettings, Format}; +use engine::export::{EncoderSeat, ExportSettings, Format}; use engine::project::{Clip, LaneKind, Project, Source, Speed}; // `posix_fadvise(2)`, straight from libc, which std already links: dropping @@ -617,15 +617,15 @@ fn scrub_bench(path: &Path) { /// The rate is frames the worker reported written over wall seconds, so a run /// stopped at the cap still reports a rate; the row says `CAPPED` when it was. fn export_bench(path: &Path, seat: &str, out_dir: &Path) { - let (format, force_sw) = match seat { - "h264sw" => (Format::Mp4, true), - "h264hw" => (Format::Mp4, false), - "av1" => (Format::Av1, true), + let (format, pick) = match seat { + "h264sw" => (Format::Mp4, EncoderSeat::Software), + "h264hw" => (Format::Mp4, EncoderSeat::Auto), + "av1" => (Format::Av1, EncoderSeat::Software), // `hevc` keeps meaning the software intra seat, so a row measured // against an older baseline still compares with the one beside it; the // GPU seat is the new name. - "hevc" => (Format::Hevc, true), - "hevchw" => (Format::Hevc, false), + "hevc" => (Format::Hevc, EncoderSeat::Software), + "hevchw" => (Format::Hevc, EncoderSeat::Auto), _ => usage(), }; // The sound is opt-in and named in the row, so an `_av` number is never @@ -675,7 +675,7 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { } }; let settings = ExportSettings { - force_sw, + seat: pick, format, ..ExportSettings::default() }; diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index a6ce225..7f39920 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -1,13 +1,14 @@ //! The project file: a line of text per thing, and nothing else. //! //! ```text -//! edith 13 +//! edith 14 //! playhead 90 //! resolution 1920 1080 //! fps 30.0 //! tonemap vivid //! proxy on //! autoproxy off +//! encoder hardware //! limiter -1.0 on //! source 0 test_av.mp4 //! source 1 /elsewhere/test_av2.mp4 @@ -61,6 +62,15 @@ //! stand-ins this project is missing -- which is the only way to ask, so a //! project that never wants them never spends a minute of encode on one. //! +//! The `encoder` line is which seat an export of this project writes its +//! picture with ([`crate::export::EncoderSeat`]), spelled `auto`, `hardware` or +//! `software`. Left out when it is `auto` -- hardware where this machine has a +//! seat and software everywhere else -- which is what every dialect before v14 +//! did and could not be told otherwise. It is the project's and not the +//! machine's for the reason the tone map is: a person who picked the software +//! encoder for *this* delivery picked it for every export of it, and a pick +//! that vanished on a reload is a pick nobody could keep. +//! //! The `limiter` line is the master limiter over the whole mix //! ([`crate::limiter`]): its ceiling in dBFS and whether it is in circuit, //! spelled `on` or `off`. Left out when it is the default, which is off. @@ -117,7 +127,10 @@ //! is the only way an empty lane could still be there on the way back. A lane //! number may not skip one of its kind. //! -//! **Version 12** was this without the `autoproxy` line: such a project makes a +//! **Version 13** was this without the `encoder` line: an export of such a +//! project takes the hardware seat where there is one and the software encoder +//! everywhere else, which is the only choice those projects had. +//! **Version 12** was that without the `autoproxy` line: such a project makes a //! stand-in for every film that wants one the moment it arrives, which is all //! any project could do. //! **Version 11** was that without the `proxy` line: such a project is cut on @@ -145,7 +158,7 @@ //! what a v1 timeline meant, and an older file simply equalizes and grades //! nothing, and an older one plays everything at real time, and an older one //! mixes flat, and an older one shows no subtitles, and an older one is shown -//! in the reference rendition -- and saving any of them writes v13. An older +//! in the reference rendition -- and saving any of them writes v14. An older //! reader refuses a newer file by name. //! //! Text because an edit list is a few integers and a path, and a path is @@ -181,7 +194,8 @@ use crate::subtitle::SubtitleTrack; /// What [`save`] writes. Read support goes back to `edith 1`; see the module /// docs for what those dialects looked like. -const MAGIC: &[u8] = b"edith 13"; +const MAGIC: &[u8] = b"edith 14"; +const MAGIC_V13: &[u8] = b"edith 13"; const MAGIC_V12: &[u8] = b"edith 12"; const MAGIC_V11: &[u8] = b"edith 11"; const MAGIC_V10: &[u8] = b"edith 10"; @@ -248,6 +262,11 @@ pub struct Document { /// file that leaves the line out, which both mean by itself -- the only /// thing those projects did. pub auto_proxy: bool, + /// Which encoder an export writes the picture with + /// ([`crate::export::EncoderSeat`]). `Auto` for every dialect before v14 and + /// for a v14 file that leaves the line out, which both mean the seat this + /// machine has -- the only choice those projects offered. + pub encoder: crate::export::EncoderSeat, pub playhead: u32, } @@ -269,6 +288,7 @@ pub fn save( tone: crate::tonemap::Preset, proxy: bool, auto_proxy: bool, + encoder: crate::export::EncoderSeat, limiter: Limiter, playhead: u32, ) -> crate::Result<()> { @@ -284,7 +304,7 @@ pub fn save( .and_then(|mut f| { f.write_all(&emit( &dir, sources, lanes, gains, subtitles, eq, color, resolution, fps, tone, proxy, - auto_proxy, limiter, playhead, + auto_proxy, encoder, limiter, playhead, ))?; f.sync_all() }) @@ -329,6 +349,7 @@ fn emit( tone: crate::tonemap::Preset, proxy: bool, auto_proxy: bool, + encoder: crate::export::EncoderSeat, limiter: Limiter, playhead: u32, ) -> Vec { @@ -359,6 +380,12 @@ fn emit( if !auto_proxy { out.extend_from_slice(b"autoproxy off\n"); } + // ...and which encoder writes the picture, by the same rule again: `auto` + // is what every project before this line did, so only a project whose owner + // picked a seat says anything here. + if encoder != crate::export::EncoderSeat::default() { + out.extend_from_slice(format!("encoder {}\n", encoder.name()).as_bytes()); + } // Written only when it is not the default, so a project nobody has limited // is the same bytes it was in v8 bar the version line. if limiter != Limiter::default() { @@ -497,8 +524,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { // The dialects that wrote a source line without its stream field. Reading // one is the whole of what "an old project still opens" means here. let streamless = v1 || first == MAGIC_V2; - // The one that says whether the stand-ins are made by themselves... - let v13 = first == MAGIC; + // The one that says which encoder an export takes... + let v14 = first == MAGIC; + // ...the ones that say whether the stand-ins are made by themselves... + let v13 = v14 || first == MAGIC_V13; // ...the ones that say whether it is cut on stand-ins... let v12 = v13 || first == MAGIC_V12; // ...the ones that carry an HDR rendition... @@ -554,6 +583,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { // that wanted a stand-in got one, which is what leaving the line out // still means. auto_proxy: true, + // ...and nothing before v14 could be told *which* encoder: an export + // took the seat this machine had, which is what leaving the line out + // still means. + encoder: crate::export::EncoderSeat::default(), fps: None, playhead: 0, }; @@ -662,6 +695,20 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { } }; } + b"encoder" if v14 => { + if !doc.sources.is_empty() { + return Err( + format!("line {n}: encoder belongs once, before the sources").into() + ); + } + let f = fields(rest, 1, "encoder", n)?; + doc.encoder = crate::export::EncoderSeat::from_name(f[0]).ok_or_else(|| { + format!( + "line {n}: encoder is auto, hardware or software, not {:?}", + String::from_utf8_lossy(f[0]) + ) + })?; + } b"limiter" if v9 => { if !doc.sources.is_empty() { return Err( @@ -1183,6 +1230,7 @@ mod tests { crate::tonemap::Preset::default(), false, true, + crate::export::EncoderSeat::default(), Limiter::default(), playhead, ) @@ -1228,6 +1276,7 @@ mod tests { crate::tonemap::Preset::default(), false, true, + crate::export::EncoderSeat::default(), Limiter::default(), 0, ); @@ -1256,7 +1305,7 @@ mod tests { video 1 0 0 30 0 - - - fit 1000\n"; let old = parse(v9, &dir).expect("v9 still loads"); assert_eq!(old.subtitles, Vec::new()); - assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 13\n")); + assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 14\n")); // ...and the line itself is not a v9 line: a dialect may not be mixed. let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir) .unwrap_err() @@ -1293,6 +1342,7 @@ mod tests { crate::tonemap::Preset::default(), proxy, true, + crate::export::EncoderSeat::default(), Limiter::default(), 0, ) @@ -1354,6 +1404,7 @@ mod tests { crate::tonemap::Preset::default(), proxy, auto, + crate::export::EncoderSeat::default(), Limiter::default(), 0, ) @@ -1395,6 +1446,78 @@ mod tests { } } + /// The v14 line: which encoder an export writes the picture with, by name, + /// read back as the very seat -- and the dialect before it, which had no + /// way to say one and took whatever this machine had. + #[test] + fn the_encoder_seat_round_trips_by_name_and_a_v13_file_takes_the_machines() { + use crate::export::EncoderSeat; + let dir = PathBuf::from("/proj"); + let (_, sources, lanes) = doc(); + let bytes = |seat| { + super::emit( + &dir, + &sources, + &lanes, + &[], + &[], + &[], + &[], + (1280, 720), + None, + crate::tonemap::Preset::default(), + false, + true, + seat, + Limiter::default(), + 0, + ) + }; + // The default is the line left out, so a project nobody has picked a + // seat for is the bytes a v13 file was bar the version line. + let auto = bytes(EncoderSeat::Auto); + assert!( + !String::from_utf8_lossy(&auto).contains("encoder"), + "auto is the line left out: {}", + String::from_utf8_lossy(&auto) + ); + assert_eq!( + parse(&auto, &dir).expect("v14 parses").encoder, + EncoderSeat::Auto + ); + for seat in [EncoderSeat::Hardware, EncoderSeat::Software] { + let written = bytes(seat); + let text = String::from_utf8_lossy(&written).to_string(); + assert!(text.contains(&format!("encoder {}\n", seat.name())), "{text}"); + assert_eq!(parse(&written, &dir).expect("v14 parses").encoder, seat); + } + + // A v13 project took the seat this machine had and could not be told + // otherwise. + let v13 = b"edith 13\nplayhead 0\nresolution 1280 720\nautoproxy off\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000\n"; + let old = parse(v13, &dir).expect("v13 still loads"); + assert_eq!( + old.encoder, + EncoderSeat::Auto, + "a v13 project exported on whatever seat there was" + ); + assert!(!old.auto_proxy, "the rest of it came back too"); + // ...and the line is not a v13 line: a dialect may not be mixed. + let mixed = parse(b"edith 13\nsource 0 a.mp4\nencoder software\n", &dir) + .unwrap_err() + .to_string(); + assert_eq!(mixed, "line 3: unknown keyword \"encoder\""); + // Anything but the three names is a corrupt line, by name. + for line in ["encoder\n", "encoder gpu\n", "encoder Hardware\n"] { + let file = format!("edith 14\nsource 0 a.mp4\n{line}"); + assert!( + parse(file.as_bytes(), &dir).is_err(), + "{line:?} is not an encoder line" + ); + } + } + /// The v11 line: the HDR rendition, written by name, read back as the very /// preset -- and the dialect before it, which had no way to say one and /// meant the published conversion. @@ -1416,6 +1539,7 @@ mod tests { preset, false, true, + crate::export::EncoderSeat::default(), Limiter::default(), 0, ); @@ -1510,7 +1634,7 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 12); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n", @@ -1547,7 +1671,7 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 7); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\ video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n", "an empty lane is a line of its own; everything else is its clips" @@ -1655,7 +1779,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 16777215.0:-0.1:3.918315e-39:hs\n\ eq\n\ @@ -1759,7 +1883,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ color 0.1:1.2:0.9:-0.3\n\ color -1e-7:16777215.0:3.918315e-39:-0.0\n\ color 0.0:1.0:1.0:0.0\n\ @@ -1824,7 +1948,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" ); @@ -1862,7 +1986,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\ audio 1 0 0 30 0 - - - fit 2000\n", "the rate is the clip line's last field, in thousandths" @@ -1891,7 +2015,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" ); // A rate outside what the editor can set is a corrupt line, by name. @@ -1934,12 +2058,13 @@ mod tests { crate::tonemap::Preset::default(), false, true, + crate::export::EncoderSeat::default(), limiter, 0, ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ limiter -1.5 on\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\ audio 2 0 0 30 0 - - - fit 1000\n\ @@ -1971,7 +2096,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" ); @@ -2135,7 +2260,7 @@ mod tests { assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); assert_eq!( String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), - "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n" @@ -2188,7 +2313,7 @@ mod tests { let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); assert_eq!( String::from_utf8_lossy(&v5), - "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 0 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n", @@ -2220,7 +2345,7 @@ mod tests { // Saved again it is the current version, which round-trips to the // same document. let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); - assert!(v5.starts_with(b"edith 13\n")); + assert!(v5.starts_with(b"edith 14\n")); let again = parse(&v5, &dir).expect("v5 parses"); assert_eq!(again.lanes, back.lanes); // A dialect may not be mixed: lane lines under v1, `clip` under v2. @@ -2320,6 +2445,7 @@ mod tests { crate::tonemap::Preset::default(), false, true, + crate::export::EncoderSeat::default(), Limiter::default(), 0, ) @@ -2327,7 +2453,7 @@ mod tests { let bytes = std::fs::read(&path).expect("read back"); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 13\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" ); // Loading rejoins the *given* directory, so the file is reached by the @@ -2372,10 +2498,10 @@ mod tests { #[test] fn a_wrong_first_line_is_refused_by_name() { let dir = PathBuf::from("/proj"); - let err = parse(b"edith 14\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) + let err = parse(b"edith 15\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) .unwrap_err() .to_string(); - assert_eq!(err, "line 1: unsupported version 14"); + assert_eq!(err, "line 1: unsupported version 15"); for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { assert_eq!( parse(junk, &dir).unwrap_err().to_string(), diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 3de12cb..310a09b 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -263,6 +263,48 @@ impl Format { } } +/// Which encoder writes the picture, as a person picks it on a card. Three +/// discrete choices and not a switch, because "whatever is best" and "the GPU, +/// and say so if there is none" are different answers: a driver that encodes +/// badly wants [`Software`](Self::Software), and a person who *needs* the GPU +/// (a long delivery, a machine whose CPU is doing something else) wants to be +/// told when it is not there rather than to wait out a silent fallback. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub enum EncoderSeat { + /// Hardware where this machine has a seat for the picked codec, software + /// everywhere else -- what every export did before there was a choice, and + /// still what an unpicked project does. + #[default] + Auto, + /// The GPU or nothing: no silent fallback, and [`Enc::open`] refuses in + /// words before a byte is written. The only way to the plugin's AV1 seat, + /// which [`Auto`](Self::Auto) will not enter (see [`Enc::open_av1`]). + Hardware, + /// The software encoder even where a seat exists -- for a driver that + /// encodes badly, and for the AV1 pair, where it is what `Auto` picks too. + Software, +} + +impl EncoderSeat { + pub const ALL: [EncoderSeat; 3] = [Self::Auto, Self::Hardware, Self::Software]; + + /// What a card row and a project file call it. The file's keyword too, so + /// the two can never drift ([`crate::edith`]). + pub fn name(self) -> &'static str { + match self { + Self::Auto => "auto", + Self::Hardware => "hardware", + Self::Software => "software", + } + } + + /// Reads one back. `None` for anything else, which a project file refuses + /// by name rather than silently exporting on another seat. + pub fn from_name(name: &[u8]) -> Option { + Self::ALL.into_iter().find(|s| s.name().as_bytes() == name) + } +} + /// What the caller gets to decide about the output. The codec is not among it: /// [`Format`] names a container *and* what goes in it, because every pair we /// can write is a pair we can also read back. @@ -271,9 +313,11 @@ pub struct ExportSettings { /// Bits per second, clamped to the same sane range the automatic value uses. /// `None` picks it from the picture size and frame rate. Video only. pub bitrate: Option, - /// Skip the hardware encoder even where it is available -- an escape hatch - /// for a driver that encodes badly, matching the `VE_SW_ENC` env pin. - pub force_sw: bool, + /// Which encoder writes the picture ([`EncoderSeat`]). Was a `force_sw` + /// flag, which could say "not the GPU" and never "the GPU or say so". + /// [`EncoderSeat::Software`] is what the `VE_SW_ENC` env pin still forces + /// on every export of a run. + pub seat: EncoderSeat, /// The file to write. Defaults to [`Format::Mp4`], which is what every /// caller wrote before there was a choice. pub format: Format, @@ -528,14 +572,35 @@ fn audio_kbps_of(settings: &ExportSettings) -> u32 { } /// The hardware seat for these settings, opened exactly as the export opens it -/// -- the same pins, the same AV1 opt-in, the same dimensions a driver may -/// refuse -- or `None` where the software encoder takes the file. The single -/// place that choice is made, which is what lets [`planned_video`] *measure* it -/// instead of promising it. -fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { - if settings.force_sw || forced("VE_SW_ENC") { - return None; +/// -- the same pins, the same dimensions a driver may refuse -- or `None` where +/// the software encoder takes the file. The single place that choice is made, +/// which is what lets [`planned_video`] *measure* it instead of promising it. +/// +/// `Err` is the one answer the software encoder does **not** take over from: +/// [`EncoderSeat::Hardware`] asked for the GPU by name and this machine has no +/// seat for the codec, so the export refuses in words rather than falling back +/// to an encoder nobody picked. Every caller is before a file exists +/// ([`Enc::open`] runs ahead of the muxer), which is what makes the refusal +/// free. +fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result> { + if settings.seat == EncoderSeat::Software || forced("VE_SW_ENC") { + return Ok(None); + } + let opened = open_hw_seat(meta, settings); + if opened.is_none() && settings.seat == EncoderSeat::Hardware { + return Err(format!( + "hardware encoding was asked for and this machine has no VA-API seat for {}: \ + pick Auto or Software on the export card", + settings.format.name() + ) + .into()); } + Ok(opened) +} + +/// The plugin half of [`hw_seat`]: what the driver gives for this codec and +/// this picture, with no policy in it but the AV1 one. +fn open_hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?; let bitrate = bitrate_of(meta, settings); match settings.format { @@ -561,9 +626,10 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { bitrate, ColorDescription::output(meta.height), ), - // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both + // Asked for by name only, for the reason [`Enc::open_av1`] states in + // full: `Auto` takes the software encoder here and nowhere else. Both // AV1 formats sit on it: the container is not the encoder's business. - format if format.is_av1() && !forced("VE_HW_AV1") => None, + format if format.is_av1() && settings.seat != EncoderSeat::Hardware => None, format if format.is_av1() => { HwEncoder::open_av1(meta.width, meta.height, fps_num, fps_den, bitrate) } @@ -585,6 +651,15 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { } } +/// What a hardware encode is called wherever one is named -- the card's line +/// before the export and the progress line during it. +const HW_LABEL: &str = "HW encode (VA-API)"; + +/// ...and what a card says instead where [`EncoderSeat::Hardware`] was picked +/// and there is no seat: the export's own refusal in the width of a card row, +/// shown *before* the button is pressed rather than a minute into a file. +pub const NO_HW_SEAT: &str = "no HW seat here — pick Auto or Software"; + /// How a front-end names a video seat: which of the two encoders has the file, /// and which library that is. Not the codec -- a caller shows this beside the /// format it picked, and `rav1e` names AV1 as `rusty_h264` names H.264. One @@ -592,7 +667,7 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { /// during one cannot drift apart. fn video_label(format: Format, hw: bool) -> &'static str { match (format, hw) { - (_, true) => "HW encode (VA-API)", + (_, true) => HW_LABEL, (Format::Hevc | Format::HevcMp4, false) => "SW encode (oxideav-h265 intra)", (Format::Av1 | Format::Av1Mp4, false) => "SW encode (rav1e)", (_, false) => "SW encode (rusty_h264)", @@ -925,10 +1000,12 @@ pub fn planned_subtitles( /// Costs that open (~100 ms here): ask it off a render thread and keep the /// answer until the format, the resolution or the bitrate changes. pub fn planned_video(meta: &VideoMeta, settings: &ExportSettings) -> Option<&'static str> { - settings - .format - .has_video() - .then(|| video_label(settings.format, hw_seat(meta, settings).is_some())) + settings.format.has_video().then(|| match hw_seat(meta, settings) { + Ok(hw) => video_label(settings.format, hw.is_some()), + // The seat the settings demand and this machine has not: the very + // refusal [`start`] would settle with, said on the card instead. + Err(_) => NO_HW_SEAT, + }) } /// What [`start`] would open for *this* timeline: the picture's seat -- or the @@ -954,7 +1031,7 @@ pub fn planned_seats( let video = settings.format.has_video().then(|| { match CopyPlan::of(project, meta, settings).is_some() { true => "copy (source packets)", - false => video_label(settings.format, hw_seat(meta, settings).is_some()), + false => planned_video(meta, settings).unwrap_or(NO_HW_SEAT), } }); // The half [`audio_label`] cannot know from the format: a copy is a *sample @@ -3041,7 +3118,7 @@ impl Enc { // hand 24000/1001 over as a rounded 23.976, which is the same // truncation the container timing had. crate::mux::frame_timing(meta.frame_rate)?; - if let Some(hw) = hw_seat(meta, settings) { + if let Some(hw) = hw_seat(meta, settings)? { eprintln!("export encoder: hardware (VA-API plugin)"); return Ok(Self::Hw(hw)); } @@ -3074,25 +3151,28 @@ impl Enc { /// simply has none and this falls through -- the same "no" a GPU without an /// AV1 encode entrypoint gives, and the same silent fallback either way. /// - /// It is **opt-in**, which is the one place this pair does not mirror the - /// H.264 one: the vendored cros-codecs AV1 encoder hung the GPU on this - /// project's own radeonsi box -- `engine_hw: operation failed`, then an - /// amdgpu hard recovery and a lost context, measured 2026-08-10 exporting - /// the 720p fixture. A software encoder that takes half a minute is a worse - /// export than a hardware one; a driver reset is not an export at all. So - /// the plugin's AV1 seat is wired, kept and only entered when `VE_HW_AV1=1` - /// asks for it by name. + /// It is **asked for by name**, which is the one place this pair does not + /// mirror the H.264 one: the vendored cros-codecs AV1 encoder hung the GPU + /// on this project's own radeonsi box -- `engine_hw: operation failed`, + /// then an amdgpu hard recovery and a lost context, measured 2026-08-10 + /// exporting the 720p fixture. A software encoder that takes half a minute + /// is a worse export than a hardware one; a driver reset is not an export + /// at all. So [`EncoderSeat::Auto`] takes `rav1e` here and only + /// [`EncoderSeat::Hardware`] -- a person picking the GPU for AV1 on the + /// card, under a row that names the risk -- enters the plugin's seat. It + /// was an env pin (`VE_HW_AV1=1`) until the card could ask, which is a + /// switch nobody exporting a film would ever find. /// /// corner-cut: the upgrade path is a driver this was reproduced against (or a /// cros-codecs release that fixes it) plus a probe encode of one frame at - /// open, after which this can prefer hardware the way H.264 does. + /// open, after which `Auto` can prefer hardware the way H.264 does. fn open_av1(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result { let bitrate = bitrate_of(meta, settings); let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate)?; // Two seconds between keyframes, as the H.264 seat does: a seek may only // land on one, and this is what a cluster of the Matroska file is. let gop = (meta.frame_rate * 2.0).round().max(1.0) as u64; - if let Some(hw) = hw_seat(meta, settings) { + if let Some(hw) = hw_seat(meta, settings)? { eprintln!("export encoder: hardware AV1 (VA-API plugin)"); return Ok(Self::Av1Hw(hw)); } @@ -3179,7 +3259,7 @@ impl Enc { ) .into()); } - if let Some(hw) = hw_seat(meta, settings) { + if let Some(hw) = hw_seat(meta, settings)? { eprintln!("export encoder: hardware HEVC intra (VA-API plugin)"); return Ok(Self::HevcHw(hw)); } @@ -3295,8 +3375,8 @@ impl Enc { /// being read back -- `None` for every seat that reads bytes, which is both /// software encoders and the intra HEVC one. /// - /// The AV1 hardware seat is left out on purpose: it is opt-in behind - /// `VE_HW_AV1` because the vendored encoder reset this project's GPU + /// The AV1 hardware seat is left out on purpose: it is entered only when a + /// person picks it by name because the vendored encoder reset this project's GPU /// ([`Enc::open_av1`]), and a path that cannot be measured is not one to /// widen. fn dma_want(&self, meta: &VideoMeta) -> Option { diff --git a/crates/engine/src/hw.rs b/crates/engine/src/hw.rs index 2c35bf7..cbed496 100644 --- a/crates/engine/src/hw.rs +++ b/crates/engine/src/hw.rs @@ -556,9 +556,10 @@ impl HwEncoder { /// really fires, and the caller's software AV1 encoder takes the export /// without saying anything about it. /// - /// The caller only reaches this behind `VE_HW_AV1=1`: the vendored encoder - /// reset this project's own GPU, which [`crate::export::Enc::open_av1`] - /// states in full. + /// The caller only reaches this when a person picked + /// [`crate::export::EncoderSeat::Hardware`] for an AV1 export: the vendored + /// encoder reset this project's own GPU, which + /// [`crate::export::Enc::open_av1`] states in full. pub fn open_av1( width: u32, height: u32, diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 06b4845..3e5225b 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -394,6 +394,11 @@ pub struct PlaybackSession { /// the project like the one above it, and read by the front end: the engine /// starts no encode of its own. auto_proxies: bool, + /// Which encoder an export of this project writes its picture with + /// ([`crate::export::EncoderSeat`]). The project's, saved with it like the + /// two switches above, and read by the front end: the engine starts no + /// export of its own. + encoder_seat: crate::export::EncoderSeat, } /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the @@ -512,6 +517,7 @@ impl PlaybackSession { // A file just opened is a project nobody has picked stand-ins for. proxies: false, auto_proxies: true, + encoder_seat: crate::export::EncoderSeat::default(), }) } @@ -628,6 +634,7 @@ impl PlaybackSession { // A file just opened is a project nobody has picked stand-ins for. proxies: false, auto_proxies: true, + encoder_seat: crate::export::EncoderSeat::default(), }) } @@ -708,6 +715,7 @@ impl PlaybackSession { // A file just opened is a project nobody has picked stand-ins for. proxies: false, auto_proxies: true, + encoder_seat: crate::export::EncoderSeat::default(), }) } @@ -1008,6 +1016,9 @@ impl PlaybackSession { // ...and what it says about making them, which is "yes" for every // dialect before v13 and for one that leaves the line out. auto_proxies: doc.auto_proxy, + // ...and which encoder it exports with, which is the seat this + // machine has for every dialect before v14. + encoder_seat: doc.encoder, }; // The scaffolding above opened source 0 from its first frame and the // whole of its audio; this puts both onto the clip the playhead is @@ -1271,6 +1282,10 @@ impl PlaybackSession { // question from whether it cuts on them and the only one an import // asks ([`Self::auto_proxies`]). self.auto_proxies, + // ...and which encoder an export of it opens, for the same reason: + // a project delivered on the software encoder is delivered on it + // again after a reload. + self.encoder_seat, self.project.limiter(), playhead, ) @@ -2087,6 +2102,21 @@ impl PlaybackSession { self.seek(now); } + /// Which encoder an export of this project would open its picture on + /// ([`crate::export::EncoderSeat`]). What a front-end puts into the + /// [`ExportSettings`](crate::export::ExportSettings) it starts an export + /// with -- and what the export card shows -- so the pick, the prediction + /// and the file are one answer. + pub fn encoder_seat(&self) -> crate::export::EncoderSeat { + self.encoder_seat + } + + /// Pick the seat. Nothing to reseek and nothing to re-probe here: this + /// decides what an *export* opens, never what plays. + pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) { + self.encoder_seat = seat; + } + /// Whether an imported film that wants a stand-in gets one made for it /// there and then ([`Self::set_auto_proxies`]). pub fn auto_proxies(&self) -> bool { diff --git a/crates/engine/tests/av1.rs b/crates/engine/tests/av1.rs index 7dfda7f..0b7487f 100644 --- a/crates/engine/tests/av1.rs +++ b/crates/engine/tests/av1.rs @@ -371,7 +371,7 @@ fn av1_settings() -> ExportSettings { format: engine::export::Format::Av1, // The software encoder, on every machine: the hardware twin below is // where the plugin's AV1 seat is exercised. - force_sw: true, + seat: engine::export::EncoderSeat::Software, ..Default::default() } } @@ -466,7 +466,7 @@ fn an_av1_export_carries_the_timelines_sound_in_either_container() { let out = Scratch::file("ve_av1_sound", ext); let settings = ExportSettings { format, - force_sw: true, + seat: engine::export::EncoderSeat::Software, ..Default::default() }; let handle = session.export_to_with(&out, &settings); diff --git a/crates/engine/tests/backends.rs b/crates/engine/tests/backends.rs index 4239fb8..6eaec09 100644 --- a/crates/engine/tests/backends.rs +++ b/crates/engine/tests/backends.rs @@ -13,7 +13,7 @@ use std::time::{Duration, Instant}; use engine::Codec; use engine::decode::{Backend, probe}; -use engine::export::{ExportSettings, Format}; +use engine::export::{EncoderSeat, ExportSettings, Format}; use engine::scratch::Scratch; use engine::{ExportHandle, PlaybackSession}; @@ -144,15 +144,18 @@ fn the_planned_encoders_are_the_ones_the_job_opens() { /// The same pin, swept over the two things that *move* the seat under a user's /// hand: the picture size (the plugin refuses HEVC below the driver's 384x384 -/// floor and the software intra encoder takes the file) and the software pin on -/// the card. The export card reads [`engine::export::planned_video`] for every -/// one of these combinations, so a size that flips the seat and a card that kept -/// the old line is the exact lie this sweep exists to catch. +/// floor and the software intra encoder takes the file) and the seat picked on +/// the card ([`engine::export::EncoderSeat`]). The export card reads +/// [`engine::export::planned_video`] for every one of these combinations, so a +/// size that flips the seat and a card that kept the old line is the exact lie +/// this sweep exists to catch. /// -/// Not swept: the hardware AV1 seat. It is `VE_HW_AV1=1` opt-in because opening -/// it hung this box's GPU into a driver reset (2026-08-10), and a test suite is -/// not the place to find out whether that is fixed -- `av1.rs` keeps that one -/// `#[ignore]`d and by name. +/// Not swept: the hardware AV1 seat, which is what `Hardware` means for the two +/// AV1 rows. Opening it hung this box's GPU into a driver reset (2026-08-10) and +/// a test suite is not the place to find out whether that is fixed -- `av1.rs` +/// keeps that one `#[ignore]`d and by name -- so `Hardware` is swept over the +/// formats whose seat is safe to open, and the AV1 pair only over the seats that +/// open no plugin at all. #[test] fn the_planned_seat_follows_the_size_and_the_pin() { for (format, ext) in [ @@ -163,10 +166,13 @@ fn the_planned_seat_follows_the_size_and_the_pin() { (Format::HevcMp4, "mp4"), ] { for (width, height) in [(320, 180), (1280, 720), (1920, 1080)] { - for force_sw in [false, true] { + for seat in EncoderSeat::ALL { + if seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4) { + continue; + } let settings = ExportSettings { format, - force_sw, + seat, ..ExportSettings::default() }; let mut session = @@ -178,7 +184,7 @@ fn the_planned_seat_follows_the_size_and_the_pin() { .expect("these formats carry picture"); // A pinned job is software by definition, whatever the machine // has -- the one seat this file may assert outright. - if force_sw { + if seat == EncoderSeat::Software { assert!( planned.starts_with("SW encode"), "{ext} {width}x{height}: a pinned job is software, got {planned}" @@ -186,13 +192,52 @@ fn the_planned_seat_follows_the_size_and_the_pin() { } let out = out_path("seat", ext); let handle = session.export_to_with(&out, &settings); + // `Hardware` on a box with no seat for this size is the one + // combination that opens nothing: the job refuses in words and + // the card said the same before the button ([`NO_HW_SEAT`]), + // which is the claim -- a refusal that fires while a seat *is* + // there would be caught by the branch below, where the export + // then has to open one. + if planned == engine::export::NO_HW_SEAT { + // The verdict is read here rather than through `wind_down`, + // which takes it out of the handle on its way past. + let started = Instant::now(); + let err = loop { + if let Some(result) = handle.result() { + break result + .expect_err("hardware was demanded and refused") + .to_string(); + } + assert!( + started.elapsed() < Duration::from_secs(60), + "{ext}: a refused export never settled" + ); + std::thread::sleep(Duration::from_millis(10)); + }; + assert!( + err.contains("no VA-API seat"), + "{ext} {width}x{height}: the refusal names the missing seat, got {err}" + ); + assert!( + !out.exists(), + "{ext} {width}x{height}: a refused export wrote a file" + ); + continue; + } let opened = published_encoders(&handle, &format!("{ext} {width}x{height}")); handle.cancel(); wind_down(&handle); assert!( opened.starts_with(planned), - "{ext} {width}x{height} force_sw={force_sw}: the card said {planned}, the job opened {opened}" + "{ext} {width}x{height} seat={seat:?}: the card said {planned}, the job opened {opened}" ); + if seat == EncoderSeat::Hardware { + assert!( + opened.starts_with("HW encode"), + "{ext} {width}x{height}: hardware was demanded and not refused, so the \ + job runs on it -- got {opened}" + ); + } } } } diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index 676beca..8290c10 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -481,7 +481,7 @@ fn a_higher_bitrate_writes_a_bigger_file() { let out = out_path(&format!("bitrate_{bitrate}")); let settings = ExportSettings { bitrate: Some(bitrate), - force_sw: true, + seat: engine::export::EncoderSeat::Software, ..Default::default() }; let handle = session.export_to_with(&out, &settings); @@ -985,7 +985,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { session.set_proxies(true); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 13\n"), "{text}"); + assert!(text.starts_with("edith 14\n"), "{text}"); assert!(text.contains("\nproxy on\n"), "{text}"); let reopened = PlaybackSession::open_project(&project).expect("load"); assert!(reopened.proxies(), "the switch came back on"); diff --git a/crates/engine/tests/saveload.rs b/crates/engine/tests/saveload.rs index c008d74..cd6d6cd 100644 --- a/crates/engine/tests/saveload.rs +++ b/crates/engine/tests/saveload.rs @@ -134,6 +134,52 @@ fn both_proxy_switches_survive_a_save_and_a_reopen() { std::fs::remove_dir_all(&dir).expect("cleanup"); } +/// The export card's encoder pick through the same front door: which seat a +/// delivery is written on is the project's, so it survives a save and a reopen +/// -- and a project nobody picked for exports on whatever this machine has, +/// which is what every project did before the row existed. +#[test] +fn the_encoder_seat_survives_a_save_and_a_reopen() { + use engine::export::EncoderSeat; + + let dir = scratch("encoderseat"); + let media = copy_in(&dir, "test_av.mp4"); + let mut session = PlaybackSession::open(&media).expect("open the fixture"); + session.set_gain(0.0); + assert_eq!( + session.encoder_seat(), + EncoderSeat::Auto, + "a fresh project takes the seat this machine has" + ); + + let path = dir.join("seat.edith"); + for seat in [EncoderSeat::Software, EncoderSeat::Hardware] { + session.set_encoder_seat(seat); + session.save_project(&path).expect("save"); + let text = std::fs::read_to_string(&path).expect("read back"); + assert!(text.contains(&format!("encoder {}\n", seat.name())), "{text}"); + assert_eq!( + PlaybackSession::open_project(&path) + .expect("reopen") + .encoder_seat(), + seat + ); + } + + // ...and the default is the line left out, which is what a v13 file is. + session.set_encoder_seat(EncoderSeat::Auto); + session.save_project(&path).expect("save"); + let text = std::fs::read_to_string(&path).expect("read back"); + assert!(!text.contains("encoder"), "auto is written by saying nothing"); + assert_eq!( + PlaybackSession::open_project(&path) + .expect("reopen") + .encoder_seat(), + EncoderSeat::Auto + ); + std::fs::remove_dir_all(&dir).expect("cleanup"); +} + /// Why a trim's tail stops where the file ends: a clip reaching past the last /// frame of its source is a project that will not open again (`open_project` /// refuses it by name). Pulled in on both ends and then dragged out as far as @@ -245,7 +291,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() { let v2 = dir.join("new.edith"); loaded.save_project(&v2).expect("save"); let text = std::fs::read_to_string(&v2).expect("read back"); - assert!(text.starts_with("edith 13\n"), "{text}"); + assert!(text.starts_with("edith 14\n"), "{text}"); assert!( text.contains("\nresolution 1280 720\n"), "a project with no resolution of its own is saved at source 0's: {text}" @@ -333,7 +379,7 @@ fn a_version_4_project_holds_more_than_two_lanes() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\ video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n", "a four-lane project is written as it was read, three versions on" @@ -363,7 +409,7 @@ fn a_version_5_project_carries_per_clip_equalizers() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 12000.0:6.25:0.5:hs\n\ video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\ @@ -398,7 +444,7 @@ fn a_version_6_project_carries_per_clip_colours() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ color 0.1:1.2:0.9:-0.3\n\ color -0.25:1.0:0.0:0.5\n\ @@ -448,7 +494,7 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 13\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 14\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\ audio 1 0 0 60 0 - - - fit 1000\n", "a v7 project is written back as the v8 it now is: the same clips, each \ @@ -706,7 +752,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() { for (text, want) in [ ( - "edith 14\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", + "edith 15\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", "line 1", ), // An eq index the table does not hold, and a band shape there is none. diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index d207604..d61285c 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -378,6 +378,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() { p.tone(), false, true, + engine::export::EncoderSeat::default(), p.limiter(), 0, ) diff --git a/crates/engine/tests/subtitles.rs b/crates/engine/tests/subtitles.rs index b1c78b9..69c0177 100644 --- a/crates/engine/tests/subtitles.rs +++ b/crates/engine/tests/subtitles.rs @@ -260,7 +260,7 @@ fn a_project_keeps_its_subtitles_across_a_save() { let project = dir.join("cut.edith"); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 13\n"), "{text}"); + assert!(text.starts_with("edith 14\n"), "{text}"); assert!( text.contains("\nsubtitle - test_subs.srt\n"), "the reference is written relative, and no cue is: {text}"