diff --git a/MCP.md b/MCP.md index e84d386..69124c2 100644 --- a/MCP.md +++ b/MCP.md @@ -406,7 +406,7 @@ Piper's stderr is reported on failure. | tool | args | does | |---|---|---| -| `export_start` | **out**, preset (an `export_presets` id; explicit args override it), loudness (-30 to -5 LUFS, the integrated target; the true peak holds at the preset's ceiling or -1 dBTP, the gain is cut back and never a limiter), format (mp4, av1, av1-mp4, hevc, hevc-mp4, webm, wav, flac, mp3, ogg, m4a, opus, prores, png_sequence, still, gif), gif_width (320/480/640/720, default 480), gif_fps (1-60, default 15), gif_loop (default true), range, size, fit, bitrate_kbps, audio_kbps (128/192/256/320), bit_depth (8\|10; 10 is AV1 and HEVC only), prores_profile (proxy\|lt\|standard\|hq\|4444\|4444xq; format `prores`, a `.mov`), hdr (off\|pq\|hlg; HEVC only, implies 10-bit), hevc_speed (default\|fast\|faster; HEVC only: fast is about 1.2-1.6x quicker for 0-3% more bits, faster about 1.5-2x quicker for up to 27% more), audio_bit_depth (16\|24; ProRes sound), chapters (default true; `"markers"` writes the comment markers as the chapters), intra_only, seat (auto\|hardware\|software), subtitles, burn_captions, overwrite | starts an export; returns `job:` at once. The reply counts the chapters written (`3 chapters`) and, for an AV1 or HEVC file, its depth (`output 10-bit, from the source`) · `queue` (true: line the export up behind the others -- it keeps its own copy of the timeline as it is now, so later edits do not change it, and starts when every earlier export has finished, one encode at a time, polled or not; `export_status` shows it as `waiting`; default false starts at once beside any others) | +| `export_start` | **out**, preset (an `export_presets` id; explicit args override it), loudness (-30 to -5 LUFS, the integrated target; the true peak holds at the preset's ceiling or -1 dBTP, the gain is cut back and never a limiter), format (mp4, av1, av1-mp4, hevc, hevc-mp4, webm, wav, flac, mp3, ogg, m4a, opus, prores, png_sequence, still, gif), gif_width (320/480/640/720, default 480), gif_fps (1-60, default 15), gif_loop (default true), range, size, fit, bitrate_kbps, qp (0-51, a constant quantiser instead of a bitrate: the hardware seat for H.264, HEVC and AV1, and software HEVC; software H.264 and AV1 refuse it; not with bitrate_kbps), audio_kbps (128/192/256/320, and 384 for AAC only: mp4, av1, av1-mp4, hevc, hevc-mp4, m4a), bit_depth (8\|10; 10 is AV1 and HEVC only), prores_profile (proxy\|lt\|standard\|hq\|4444\|4444xq; format `prores`, a `.mov`), hdr (off\|pq\|hlg; HEVC only, implies 10-bit), hevc_speed (default\|fast\|faster; HEVC only: fast is about 1.2-1.6x quicker for 0-3% more bits, faster about 1.5-2x quicker for up to 27% more), audio_bit_depth (16\|24; ProRes sound), chapters (default true; `"markers"` writes the comment markers as the chapters), intra_only, seat (auto\|hardware\|software), subtitles, burn_captions, overwrite | starts an export; returns `job:` at once. The reply counts the chapters written (`3 chapters`) and, for an AV1 or HEVC file, its depth (`output 10-bit, from the source`) · `queue` (true: line the export up behind the others -- it keeps its own copy of the timeline as it is now, so later edits do not change it, and starts when every earlier export has finished, one encode at a time, polled or not; `export_status` shows it as `waiting`; default false starts at once beside any others) | | `export_presets` | – | lists the export presets (id, label, format, bitrate_kbps, audio_kbps, size, bit_depth, prores_profile, hdr, loudness): youtube_1080p/1080p60/1080p_hevc/4k/4k60/4k_hevc, shorts_reels, podcast, podcast_ogg and podcast_opus (-16 LUFS, -1 dBTP), archive (10-bit AV1 mkv), archive_prores (ProRes 422 HQ .mov), hdr10_hevc (10-bit HEVC mp4 tagged PQ), archive_flac, archive_wav | | `export_captions` | format (`srt` or `vtt`, required unless chapters), path, overwrite, chapters | writes the timeline's captions (every cue on the subtitle lanes, in start order) as SRT or WebVTT; picture and empty cues are left out. Without `path`: ` edit.` in the Videos folder. Refuses an existing file unless `overwrite` is true, and writes nothing when there are no captions. `chapters: true` writes nothing and returns the chapter markers as the YouTube description listing (`00:00 Intro`, one line each), the text File > Copy chapters copies, as the reply text and as JSON (`chapters` lines, `text`, `warnings`) | | `proxies` | action (`status`, the default, `make`, `cancel` or `delete`), source (`src:`, a list or `"all"`) | the editing copies (proxies) of sources. `status` shows each source's state (ready, making with its percent, off, not needed for a sound or still, or why a stand-in failed). `make` starts one in the background and turns that film's switch back on; a film that plays at speed on this machine needs none, and says so. `cancel` stops one being made and leaves the film off, as the Proxies switch on a library row does. `delete` removes the stand-in and keeps the film off. With `auto_proxies` on, each `media_import` starts its stand-ins the same way | diff --git a/crates/engine-hw/src/enc_ec.rs b/crates/engine-hw/src/enc_ec.rs index 4cf353b..b133543 100644 --- a/crates/engine-hw/src/enc_ec.rs +++ b/crates/engine-hw/src/enc_ec.rs @@ -16,6 +16,7 @@ use ec_hw::{Encoder, H264Profile, I420}; use ec_va::{PrimeLayer, PrimeObject, PrimeSurface}; use engine::hw::{DmaFrame, VhDma}; +use engine::hwproc::SeatRate; /// `DRM_FORMAT_NV12`, which is also `VA_FOURCC_NV12`: the four characters. const FOURCC_NV12: u32 = u32::from_le_bytes(*b"NV12"); @@ -44,7 +45,7 @@ pub(crate) struct EcOpen { pub height: u32, pub fps_num: u32, pub fps_den: u32, - pub bitrate: u64, + pub rate: SeatRate, /// Every picture an IDR: what a proxy is coded with (see `gop_limit`). pub intra_only: bool, /// Colour description for the VUI as `(primaries, transfer, matrix, full)`. @@ -59,7 +60,7 @@ impl EcEncSession { height, fps_num, fps_den, - bitrate, + rate, intra_only, colour, } = req; @@ -74,24 +75,22 @@ impl EcEncSession { if codec == EncCodec::H265 && (width < 384 || height < 384) { return None; } - if fps_num == 0 || fps_den == 0 || bitrate == 0 { + if fps_num == 0 || fps_den == 0 || rate == SeatRate::Bitrate(0) { return None; } let framerate = ((fps_num as f64 / fps_den as f64).round() as i64).clamp(1, 240) as u32; let mut config = EncoderConfig::new(codec, width, height); config.framerate = (framerate, 1); - config.bitrate = u32::try_from(bitrate).unwrap_or(u32::MAX); - config.gop_size = match codec { - // Every HEVC picture is an IDR: a GOP's P slices come out of this - // driver undecodable (measured 2026-08-13 on radeonsi), so the seat - // is intra-only exactly as the software one is. - EncCodec::H265 => 1, - _ => u32::from(crate::gop_limit(framerate, intra_only)), - }; - config.rate_control = match codec { + if let SeatRate::Bitrate(bitrate) = rate { + config.bitrate = u32::try_from(bitrate).unwrap_or(u32::MAX); + } + config.gop_size = u32::from(crate::gop_limit(framerate, intra_only)); + config.rate_control = match (codec, rate) { + (EncCodec::Av1, SeatRate::ConstantQp(qp)) => RateControlMode::ConstantQp { qp: qp.min(51) * 255 / 51 }, + (_, SeatRate::ConstantQp(qp)) => RateControlMode::ConstantQp { qp }, // Constant quality at 128 of 255, the AV1 rate control measured. - EncCodec::Av1 => RateControlMode::ConstantQp { qp: 128 }, - _ => RateControlMode::ConstantBitrate, + (EncCodec::Av1, SeatRate::Bitrate(_)) => RateControlMode::ConstantQp { qp: 128 }, + (_, SeatRate::Bitrate(_)) => RateControlMode::ConstantBitrate, }; if codec == EncCodec::H264 { // Main, not the High default: the seat's tests pin the profile. diff --git a/crates/engine-hw/src/lib.rs b/crates/engine-hw/src/lib.rs index 783883e..ae41004 100644 --- a/crates/engine-hw/src/lib.rs +++ b/crates/engine-hw/src/lib.rs @@ -802,12 +802,12 @@ pub(crate) fn open_encoder(open: &engine::hwproc::Open) -> Option Seat::H264 => (EcCodec::H264, false, None), Seat::Intra => (EcCodec::H264, true, None), Seat::Av1 => (EcCodec::Av1, false, None), - Seat::Hevc => { + Seat::Hevc | Seat::HevcIntra => { let (p, t, m) = open.colour.codes(); let narrow = |code: u16| u8::try_from(code).unwrap_or(u8::MAX); ( EcCodec::H265, - true, + open.seat == Seat::HevcIntra, Some((narrow(p), narrow(t), narrow(m), open.colour.full_range)), ) } @@ -818,7 +818,7 @@ pub(crate) fn open_encoder(open: &engine::hwproc::Open) -> Option height: open.height, fps_num: open.fps_num, fps_den: open.fps_den, - bitrate: open.bitrate, + rate: open.rate, intra_only, colour, }) @@ -827,6 +827,7 @@ pub(crate) fn open_encoder(open: &engine::hwproc::Open) -> Option #[cfg(test)] mod tests { use super::*; + use engine::hwproc::SeatRate; /// The one number that decides whether a hardware file is intra-only, and /// the one this seat got wrong: a proxy asks for a group of one picture, so @@ -865,7 +866,7 @@ mod tests { height: 240, fps_num: 30, fps_den: 1, - bitrate: 2_000_000, + rate: SeatRate::Bitrate(2_000_000), intra_only: true, colour: None, }; @@ -946,7 +947,7 @@ mod tests { height: 240, fps_num: 30, fps_den: 1, - bitrate: 2_000_000, + rate: SeatRate::Bitrate(2_000_000), intra_only: true, colour: None, }; diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index bf55cda..12abe05 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -7,7 +7,7 @@ //! them, rate-controlled when the settings carry a bitrate and at constant QP //! when they do not. [`ExportSettings::intra_only`] makes every picture an IDR //! instead -- an intraframe master in the family of ProRes and DNxHD, large -//! files and every frame a cut point. The hardware HEVC seat codes intra only. +//! files and every frame a cut point. //! //! Picture and sound are both **copied wherever a copy says exactly what the //! timeline says** — a copy is exact, free and never a generation of loss. For @@ -80,6 +80,7 @@ use crate::colorspace::{Chroma, ColorDescription, Matrix, Tags, Transfer}; use crate::decode::{I420, Pulled, Wide}; use crate::demux::{Codec, Demuxer, MkvDemuxer, Rotation, VideoMeta}; use crate::hw::{DmaFrame, DmaWant, HwEncoder, HwPicture, HwSession}; +use crate::hwproc::SeatRate; use crate::mux::{ AudioParams, Av1Params, CopyParams, HevcParams, MkvMuxer, Mp4Muxer, SubParams, VideoParams, }; @@ -142,6 +143,11 @@ const MAX_EXPLICIT_BITRATE: u64 = 50_000_000; /// was given rather than the nearest one `ec-mp3` snaps to. pub const AUDIO_KBPS: [u32; 4] = [128, 192, 256, 320]; +/// The sound rate AAC alone may be coded at, above the rows [`AUDIO_KBPS`] offers. +pub const AAC_MAX_KBPS: u32 = 384; + +const QP_SOFTWARE_REFUSAL: &str = "a constant QP (qp) is written by the hardware seat and the software HEVC encoders only: pass seat hardware for this format, or bitrate_kbps for a fixed rate"; + /// What the sound is coded at when nobody picked: the rate this project wrote /// before the choice existed. 256 and not the encoders' own 128, because an /// export is a master a person edits from again and this is a second lossy @@ -543,6 +549,8 @@ 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, + /// A constant quantiser (0..51 for H.264 and HEVC) instead of a bitrate. + pub qp: Option, /// 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 @@ -1247,13 +1255,20 @@ fn bitrate_of(meta: &VideoMeta, settings: &ExportSettings) -> u64 { ) } +fn rate_of(meta: &VideoMeta, settings: &ExportSettings) -> SeatRate { + match settings.qp { + Some(qp) => SeatRate::ConstantQp(qp), + None => SeatRate::Bitrate(bitrate_of(meta, settings)), + } +} + /// The rate the sound codes at: the caller's pick clamped into the offered /// range, [`DEFAULT_AUDIO_KBPS`] where there was none. Clamped and not refused, /// for [`bitrate_of`]'s reason -- a number out of range is a caller's slip and /// not a file worth failing. fn audio_kbps_of(settings: &ExportSettings) -> u32 { // 384 is above the offered rows, which a preset asks for (YouTube's AAC); MP3 has no such rate. - let ceiling = if settings.format == Format::Mp3 { AUDIO_KBPS[3] } else { 384 }; + let ceiling = if settings.format == Format::Mp3 { AUDIO_KBPS[3] } else { AAC_MAX_KBPS }; settings.audio_kbps.map_or(DEFAULT_AUDIO_KBPS, |k| k.clamp(AUDIO_KBPS[0], ceiling)) } @@ -1272,12 +1287,6 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result crate::Result Option { let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?; - let bitrate = bitrate_of(meta, settings); + let rate = rate_of(meta, settings); match settings.format { - // Both HEVC formats sit on the plugin's HEVC seat, and it is the - // default again: what it codes is intra-only, the very file the - // software seat writes, so preferring the GPU changes how long an - // export takes and not what comes out of it. What made that untrue for - // one day was the vendored encoder's parameter sets promising coding - // tools the driver was not using; the pictures are now measured against - // their sources rather than counted - // (`hevc_export::a_1080p_hardware_export_leaves_a_decoder_with_nothing_to_say`). - // `None` here is the plugin's own "no" -- no entrypoint, or a picture - // under the driver's 384x384 floor -- and the software seat takes it. - // The colour goes in at the open, from the same [`ColorDescription::output`] - // rule the software seat's VUI and both containers' tags come from, so - // the file cannot say one thing in its bitstream and another in its - // header. - // The GOP default is software: Auto takes `ec-h265` for an I+P file - // rather than the GPU's intra one, which is what the card says it is. - format if format.is_hevc() && !settings.intra_only => None, + // Both HEVC formats sit on the plugin's HEVC seat, GOP or intra as the + // export asks. `None` here is the plugin's own "no" -- no entrypoint, or + // a picture under the driver's 384x384 floor -- and the software seat + // takes it. The colour goes in at the open, from the same + // [`ColorDescription::output`] rule the software seat's VUI and both + // containers' tags come from, so the file cannot say one thing in its + // bitstream and another in its header. + format if format.is_hevc() && settings.intra_only => HwEncoder::open_hevc_intra( + meta.width, + meta.height, + fps_num, + fps_den, + rate, + ColorDescription::output_sized(meta.width, meta.height), + ), format if format.is_hevc() => HwEncoder::open_hevc( meta.width, meta.height, fps_num, fps_den, - bitrate, + rate, ColorDescription::output_sized(meta.width, meta.height), ), // Asked for by name only, for the reason [`Enc::open_av1`] states in @@ -1326,7 +1333,7 @@ fn open_hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option None, format if format.is_av1() => { - HwEncoder::open_av1(meta.width, meta.height, fps_num, fps_den, bitrate) + HwEncoder::open_av1(meta.width, meta.height, fps_num, fps_den, rate) } // An intra-only H.264 file is a *different seat*, not the same seat with // a flag on the pictures: asking this one for a key frame every time @@ -1337,15 +1344,20 @@ fn open_hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { - HwEncoder::open_intra(meta.width, meta.height, fps_num, fps_den, bitrate) + HwEncoder::open_intra(meta.width, meta.height, fps_num, fps_den, rate) } - _ => HwEncoder::open(meta.width, meta.height, fps_num, fps_den, bitrate), + _ => HwEncoder::open(meta.width, meta.height, fps_num, fps_den, rate), } } +/// True when an Annex B HEVC access unit holds an IRAP picture (NAL types 16..=23). +fn hevc_irap(au: &[u8]) -> bool { + au.windows(4) + .any(|w| w[0] == 0 && w[1] == 0 && w[2] == 1 && (16..=23).contains(&((w[3] >> 1) & 0x3F))) +} + /// 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)"; @@ -8161,7 +8173,7 @@ enum Enc { Av1Hw(HwEncoder), /// HEVC on the GPU, through that same plugin -- and intra-only there too, /// so this and [`Enc::Hevc`] write the same kind of file. - HevcHw(HwEncoder), + HevcHw(HwEncoder, bool), /// AV1 software at 10 bits: `rav1e`'s 16-bit context. A picture that passes /// through the span untouched arrives as 16-bit planes off the 10-bit decode /// ([`Enc::encode_wide`]); an 8-bit picture (one composed on the way) is shifted @@ -8253,7 +8265,7 @@ impl Enc { Self::Sw { .. } => video_label(Format::Mp4, false, false), Self::Av1Hw(_) => video_label(Format::Av1, true, false), Self::Av1Sw { .. } | Self::Av1Sw16 { .. } => video_label(Format::Av1, false, false), - Self::HevcHw(_) => video_label(Format::Hevc, true, true), + Self::HevcHw(_, intra) => video_label(Format::Hevc, true, *intra), Self::Hevc(_) => video_label(Format::Hevc, false, true), Self::HevcGop(_) => video_label(Format::Hevc, false, false), Self::ProRes { .. } => video_label(Format::ProRes, false, true), @@ -8301,6 +8313,9 @@ impl Enc { if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: hardware (VA-API plugin)"); } return Ok(Self::Hw(hw)); } + if settings.qp.is_some() { + return Err(QP_SOFTWARE_REFUSAL.into()); + } // H.264 codes 16x16 macroblocks, and ec-h264's floor is the // macroblock itself -- the old encoder took any positive even size. // Named here, where a card can show it, rather than let the encoder's @@ -8395,6 +8410,9 @@ impl Enc { if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: hardware AV1 (VA-API plugin)"); } return Ok(Self::Av1Hw(hw)); } + if settings.qp.is_some() { + return Err(QP_SOFTWARE_REFUSAL.into()); + } if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: software AV1 (rav1e)"); } // Seconds per frame, which is what `frame_timing` already has as an // exact rational -- 1001/24000 rather than a rounded 23.976. @@ -8478,11 +8496,12 @@ impl Enc { /// encode entrypoint. Silent either way, because both write the same kind /// of file. /// - /// The default is I+P GOPs on the software seat ([`Enc::open_hevc_gop`]). - /// With [`ExportSettings::intra_only`] it is intra: every picture an IDR, - /// on the hardware seat where there is one and on the lanes below where - /// there is not -- an intraframe master in the shape of ProRes or DNxHD, - /// large files, every frame a cut point. + /// The default is I+P GOPs, on the hardware seat where there is one and on + /// the software seat ([`Enc::open_hevc_gop`]) where there is not. With + /// [`ExportSettings::intra_only`] it is intra: every picture an IDR, on the + /// hardware seat where there is one and on the lanes below where there is + /// not -- an intraframe master in the shape of ProRes or DNxHD, large + /// files, every frame a cut point. /// /// The picture is coded at its own size and padded to whole minimum coding /// blocks *by the encoder*, which crops the padding back off with the SPS @@ -8516,8 +8535,8 @@ impl Enc { false => hw_seat(meta, settings)?, }; if let Some(hw) = hw { - if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: hardware HEVC intra (VA-API plugin)"); } - return Ok(Self::HevcHw(hw)); + if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: hardware HEVC (VA-API plugin)"); } + return Ok(Self::HevcHw(hw, settings.intra_only)); } if !settings.intra_only { if std::env::var_os("EDITH_DEBUG").is_some() { eprintln!("export encoder: software HEVC I+P (ec-h265)"); } @@ -8539,7 +8558,7 @@ impl Enc { // rate controller. The encoder's own per-picture target-bits mode // would chase the number with a correction pass -- named headroom, // not behaviour this seat takes silently. - cfg.rate_control = RateControl::ConstantQp(hevc_qp(meta, settings)); + cfg.rate_control = RateControl::ConstantQp(settings.qp.map_or_else(|| hevc_qp(meta, settings), |qp| qp as i32)); cfg.timing = Some((fps_den, fps_num)); cfg.video_signal_type = Some(video_signal_type(colour)); apply_hdr(&mut cfg, settings); @@ -8706,14 +8725,9 @@ impl Enc { collect_av1(context, ready)?; Ok(pop_av1(ready, au)) } - // Every unit this seat hands back is an IDR carrying its own - // parameter sets (the plugin codes HEVC intra-only), so every one of - // them is a sync point -- said as a constant rather than parsed back - // out of the bitstream, because it is this encoder's configuration - // and not a driver's choice. - Self::HevcHw(hw) => Ok(hw - .encode(y, u, v, width, height, true)? - .map(|au| (au, true))), + Self::HevcHw(hw, intra) => Ok(hw + .encode(y, u, v, width, height, *intra)? + .map(|au| (au, hevc_irap(au)))), Self::Hevc(hevc) => { // The display-size planes are kept as they came: `ec-h265` // pads to its own coded grid and crops back through the SPS @@ -8765,7 +8779,7 @@ impl Enc { /// ([`crate::hwproc`]), which is a round trip on its socket. fn dma_want(&mut self, meta: &VideoMeta) -> Option { match self { - Self::Hw(hw) | Self::HevcHw(hw) => hw.dma_want(meta.width, meta.height), + Self::Hw(hw) | Self::HevcHw(hw, _) => hw.dma_want(meta.width, meta.height), _ => None, } } @@ -8784,8 +8798,7 @@ impl Enc { fn encode_dma(&mut self, dma: &DmaFrame, intra: bool) -> crate::Result> { match self { Self::Hw(hw) => Ok(hw.encode_dma(dma, intra)?.map(|au| (au, intra))), - // Every picture an IDR here, exactly as in [`Enc::encode`]. - Self::HevcHw(hw) => Ok(hw.encode_dma(dma, true)?.map(|au| (au, true))), + Self::HevcHw(hw, intra) => Ok(hw.encode_dma(dma, *intra)?.map(|au| (au, hevc_irap(au)))), // Unreachable through [`Enc::dma_want`], which is the only thing // that puts a span's decoder on this path. _ => Err("this encoder takes pictures as bytes, not as buffers".into()), @@ -8826,7 +8839,7 @@ impl Enc { } Ok(pop_av1(ready, au)) } - Self::HevcHw(hw) => Ok(hw.drain()?.map(|au| (au, true))), + Self::HevcHw(hw, _) => Ok(hw.drain()?.map(|au| (au, hevc_irap(au)))), // The tail batch: fewer frames than lanes, coded on as many // encoders as there are frames left. Self::Hevc(hevc) => { @@ -8931,12 +8944,13 @@ impl Enc { let keyint = hevc_gop_keyint(meta.frame_rate); let mut cfg = HevcEncoderConfig::new(meta.width, meta.height); cfg.bit_depth = if ten_bit { 10 } else { 8 }; - cfg.rate_control = match settings.bitrate { - Some(_) => RateControl::Bitrate { + cfg.rate_control = match (settings.qp, settings.bitrate) { + (Some(qp), _) => RateControl::ConstantQp(qp as i32), + (None, Some(_)) => RateControl::Bitrate { kbps: (bitrate_of(meta, settings) / 1000).max(1) as u32, fps: meta.frame_rate, }, - None => RateControl::ConstantQp(HEVC_GOP_QP), + (None, None) => RateControl::ConstantQp(HEVC_GOP_QP), }; cfg.keyint = keyint; cfg.threads = ec_h265::encoder::default_threads(); @@ -9000,9 +9014,10 @@ pub fn hevc_mode_words(meta: &VideoMeta, settings: &ExportSettings) -> Option "intra-only".to_string(), - None => format!( + return Some(match (settings.qp, settings.bitrate) { + (Some(qp), _) => format!("intra-only, constant QP {qp}"), + (None, Some(_)) => "intra-only".to_string(), + (None, None) => format!( "intra-only, constant quality QP {} on the software seat (the GPU seat codes at the automatic rate); pass bitrate_kbps for a fixed rate", hevc_qp(meta, settings) ), @@ -9014,9 +9029,10 @@ pub fn hevc_mode_words(meta: &VideoMeta, settings: &ExportSettings) -> Option rate_words(bitrate_of(meta, settings) / 1000), - None => format!("constant quality QP {HEVC_GOP_QP}; pass bitrate_kbps for a fixed rate"), + let rate = match (settings.qp, settings.bitrate) { + (Some(qp), _) => format!("constant QP {qp}"), + (None, Some(_)) => rate_words(bitrate_of(meta, settings) / 1000), + (None, None) => format!("constant quality QP {HEVC_GOP_QP}; pass bitrate_kbps for a fixed rate"), }; Some(format!("I+P GOP ({every} keyframes), {rate}")) } @@ -9028,6 +9044,9 @@ pub fn av1_mode_words(meta: &VideoMeta, settings: &ExportSettings) -> Option format!("average bitrate {rate}"), diff --git a/crates/engine/src/hw.rs b/crates/engine/src/hw.rs index 38d7754..c82640d 100644 --- a/crates/engine/src/hw.rs +++ b/crates/engine/src/hw.rs @@ -24,8 +24,8 @@ use std::sync::OnceLock; use crate::colorspace::ColorDescription; use crate::hwproc::{ - DMA_BODY, HW_LOST, K_DMA, K_PIXELS, Lost, Open, R_AU, R_ERR, R_NONE, Remote, Seat, Shm, T_NEXT, - T_NEXT_DMA, T_SEEK, recv_reply, send_msg, spawn_child, + DMA_BODY, HW_LOST, K_DMA, K_PIXELS, Lost, Open, R_AU, R_ERR, R_NONE, Remote, Seat, SeatRate, Shm, + T_NEXT, T_NEXT_DMA, T_SEEK, recv_reply, send_msg, spawn_child, }; #[cfg(test)] @@ -491,18 +491,18 @@ pub struct HwEncoder(Remote); impl HwEncoder { /// H.264 at `width`x`height`, `fps_num / fps_den` frames per second, coded - /// at a constant `bitrate` bits per second. `None` whenever hardware encode + /// at a constant `rate` (a bitrate or a quantiser). `None` whenever hardware encode /// is unavailable -- no child binary, no driver, dimensions the driver /// refuses, *or a child that died opening any of it* -- and the caller falls /// back to the software encoder. - pub fn open(width: u32, height: u32, fps_num: u32, fps_den: u32, bitrate: u64) -> Option { + pub fn open(width: u32, height: u32, fps_num: u32, fps_den: u32, rate: SeatRate) -> Option { Self::seated( Seat::H264, width, height, fps_num, fps_den, - bitrate, + rate, ColorDescription::default(), ) } @@ -512,14 +512,14 @@ impl HwEncoder { /// [`crate::proxy`] codes a stand-in with. `None` on a child that cannot /// make that seat, and the caller must then take the software encoder rather /// than the ordinary hardware seat. - pub fn open_intra(width: u32, height: u32, fps_num: u32, fps_den: u32, bitrate: u64) -> Option { + pub fn open_intra(width: u32, height: u32, fps_num: u32, fps_den: u32, rate: SeatRate) -> Option { Self::seated( Seat::Intra, width, height, fps_num, fps_den, - bitrate, + rate, ColorDescription::default(), ) } @@ -527,14 +527,14 @@ impl HwEncoder { /// The same, coding AV1 instead. `None` on a child or a GPU with no AV1 /// encoder, and the caller's software AV1 encoder takes the export without /// saying anything about it. - pub fn open_av1(width: u32, height: u32, fps_num: u32, fps_den: u32, bitrate: u64) -> Option { + pub fn open_av1(width: u32, height: u32, fps_num: u32, fps_den: u32, rate: SeatRate) -> Option { Self::seated( Seat::Av1, width, height, fps_num, fps_den, - bitrate, + rate, ColorDescription::default(), ) } @@ -547,10 +547,23 @@ impl HwEncoder { height: u32, fps_num: u32, fps_den: u32, - bitrate: u64, + rate: SeatRate, colour: ColorDescription, ) -> Option { - Self::seated(Seat::Hevc, width, height, fps_num, fps_den, bitrate, colour) + Self::seated(Seat::Hevc, width, height, fps_num, fps_den, rate, colour) + } + + /// The HEVC seat, **intra-only**: every picture an IDR, as [`Self::open_intra`] + /// is for H.264. + pub fn open_hevc_intra( + width: u32, + height: u32, + fps_num: u32, + fps_den: u32, + rate: SeatRate, + colour: ColorDescription, + ) -> Option { + Self::seated(Seat::HevcIntra, width, height, fps_num, fps_den, rate, colour) } fn seated( @@ -559,7 +572,7 @@ impl HwEncoder { height: u32, fps_num: u32, fps_den: u32, - bitrate: u64, + rate: SeatRate, colour: ColorDescription, ) -> Option { let open = Open { @@ -568,7 +581,7 @@ impl HwEncoder { height, fps_num, fps_den, - bitrate, + rate, colour, }; // No child binary beside the executable means no hardware seat at all: diff --git a/crates/engine/src/hwproc.rs b/crates/engine/src/hwproc.rs index f35823d..c611906 100644 --- a/crates/engine/src/hwproc.rs +++ b/crates/engine/src/hwproc.rs @@ -88,6 +88,7 @@ pub enum Seat { Intra, Av1, Hevc, + HevcIntra, } impl Seat { @@ -97,6 +98,7 @@ impl Seat { Self::Intra => 1, Self::Av1 => 2, Self::Hevc => 3, + Self::HevcIntra => 4, } } @@ -106,11 +108,20 @@ impl Seat { 1 => Self::Intra, 2 => Self::Av1, 3 => Self::Hevc, + 4 => Self::HevcIntra, _ => return None, }) } } +/// How the encode seat spends bits: a constant bitrate in bits per second, or a +/// constant quantiser (H.264/HEVC 0..51, AV1 0..255 on the seat's own scale). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum SeatRate { + Bitrate(u64), + ConstantQp(u32), +} + /// Everything an open needs, in one place because it travels as argv and comes /// back as a struct on the other side. #[derive(Clone, Copy)] @@ -120,7 +131,7 @@ pub struct Open { pub height: u32, pub fps_num: u32, pub fps_den: u32, - pub bitrate: u64, + pub rate: SeatRate, /// What the sequence header will say the samples mean. Only the HEVC seat /// takes one; the others ignore it. pub colour: ColorDescription, @@ -152,7 +163,10 @@ impl Open { ] .iter() .map(u32::to_string) - .chain(std::iter::once(self.bitrate.to_string())) + .chain(match self.rate { + SeatRate::Bitrate(bps) => [0, bps], + SeatRate::ConstantQp(qp) => [1, u64::from(qp)], + }.map(|v| v.to_string())) .collect() } @@ -165,7 +179,14 @@ impl Open { height: n(2)?, fps_num: n(3)?, fps_den: n(4)?, - bitrate: args.get(8)?.parse().ok()?, + rate: { + let value = args.get(9)?.parse::().ok()?; + match n(8)? { + 0 => SeatRate::Bitrate(value), + 1 => SeatRate::ConstantQp(u32::try_from(value).ok()?), + _ => return None, + } + }, colour: ColorDescription { matrix: match n(5)? { 0 => Matrix::Bt709, @@ -783,7 +804,7 @@ mod tests { height: 1080, fps_num: 30000, fps_den: 1001, - bitrate: 12_345_678, + rate: SeatRate::Bitrate(12_345_678), colour: ColorDescription { matrix: Matrix::Bt2020Ncl, transfer: Transfer::Pq, @@ -793,9 +814,10 @@ mod tests { let back = Open::from_argv(&open.argv()).expect("parse"); assert!(back.seat == Seat::Hevc); assert_eq!( - (back.width, back.height, back.fps_num, back.fps_den, back.bitrate), - (1920, 1080, 30000, 1001, 12_345_678) + (back.width, back.height, back.fps_num, back.fps_den), + (1920, 1080, 30000, 1001) ); + assert!(back.rate == SeatRate::Bitrate(12_345_678)); assert_eq!(back.colour, open.colour); assert_eq!(back.frame_bytes(), 1920 * 1080 * 3 / 2); } diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index 00a6875..7bb4cc9 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -35,6 +35,7 @@ use ec_core::{Packet, TimeBase}; use ec_h264::H264Decoder; use engine::export::ExportSettings; use engine::hw::HwEncoder; +use engine::hwproc::SeatRate; use engine::mux::{parameter_sets, AudioParams, Mp4Muxer, VideoParams}; use engine::project::{Lane, Source, Speed}; use engine::scale::FitPolicy; @@ -771,7 +772,7 @@ fn exports_audio_alongside_the_video() { fn hardware_access_units_repack_into_mp4() { let (w, h) = (640u32, 480u32); let mut encoder = - HwEncoder::open(w, h, 30, 1, 4_000_000).expect("no hardware encode plugin/driver"); + HwEncoder::open(w, h, 30, 1, SeatRate::Bitrate(4_000_000)).expect("no hardware encode plugin/driver"); let out = out_path("hwmux"); let mut muxer: Option = None; let mut written = 0; @@ -1918,7 +1919,7 @@ fn a_wedged_child_is_waited_out_by_its_own_measure_not_the_ceiling() { // No `VE_HW_TIMEOUT_MS` at all: the wait is the one a person's export gets. injected_with(None, Some("10"), None, || { let mut encoder = - HwEncoder::open(width, height, 30, 1, 1_000_000).expect("the stand-in seat opened"); + HwEncoder::open(width, height, 30, 1, SeatRate::Bitrate(1_000_000)).expect("the stand-in seat opened"); let (y, u, v) = synthetic(0, width as usize, height as usize); for frame in 0..10 { assert!( @@ -2057,7 +2058,7 @@ fn a_dead_encoder_answers_every_later_call_the_same_way() { let (width, height) = (320u32, 240u32); injected(Some("1"), None, || { let mut encoder = - HwEncoder::open(width, height, 30, 1, 1_000_000).expect("the stand-in seat opened"); + HwEncoder::open(width, height, 30, 1, SeatRate::Bitrate(1_000_000)).expect("the stand-in seat opened"); let (y, u, v) = synthetic(0, width as usize, height as usize); assert!( encoder.encode(&y, &u, &v, width, height, false).is_ok(), diff --git a/crates/engine/tests/hw_encode.rs b/crates/engine/tests/hw_encode.rs index 3263401..6a9e2b5 100644 --- a/crates/engine/tests/hw_encode.rs +++ b/crates/engine/tests/hw_encode.rs @@ -19,6 +19,7 @@ mod hwchild; use std::time::{Duration, Instant}; use engine::hw::{HwEncoder, HwPicture, HwSession}; +use engine::hwproc::SeatRate; use ec_core::registry::{CodecId, CodecParameters, Decoder as _}; use ec_core::{Packet, TimeBase}; use ec_h264::H264Decoder; @@ -44,7 +45,7 @@ fn synthetic(index: u32, width: usize, height: usize) -> (Vec, Vec, Vec< /// Encodes `count` synthetic pictures and returns the whole Annex-B stream plus /// the number of access units the plugin handed back. fn encode(width: u32, height: u32, count: u32) -> Option<(Vec, u32)> { - let mut encoder = HwEncoder::open(width, height, FPS, 1, BITRATE)?; + let mut encoder = HwEncoder::open(width, height, FPS, 1, SeatRate::Bitrate(BITRATE))?; let mut stream = Vec::new(); let mut units = 0; // Timed around the plugin call only: building the synthetic picture is not @@ -248,7 +249,7 @@ fn a_decoded_buffer_is_encoded_without_ever_being_read_back() { let asset = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets/test_baseline.mp4"); let (width, height) = (1280u32, 720u32); - let Some(mut encoder) = HwEncoder::open(width, height, FPS, 1, BITRATE) else { + let Some(mut encoder) = HwEncoder::open(width, height, FPS, 1, SeatRate::Bitrate(BITRATE)) else { println!("no hardware encoder here -- skipping"); return; }; @@ -366,13 +367,13 @@ fn decode_and_encode_load_independently() { let asset = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets/test_baseline.mp4"); assert!( - HwEncoder::open(640, 480, FPS, 1, BITRATE).is_some(), + HwEncoder::open(640, 480, FPS, 1, SeatRate::Bitrate(BITRATE)).is_some(), "encode table" ); assert!(HwSession::open(&asset).is_some(), "decode table"); // Order reversed: neither table's `OnceLock` may have primed the other. assert!(HwSession::open(&asset).is_some()); - assert!(HwEncoder::open(640, 480, FPS, 1, BITRATE).is_some()); + assert!(HwEncoder::open(640, 480, FPS, 1, SeatRate::Bitrate(BITRATE)).is_some()); } /// Per slice: `(is_idr, frame_num, pic_order_cnt_lsb)`, read by [`slice_counters`]. diff --git a/crates/engine/tests/it/backends.rs b/crates/engine/tests/it/backends.rs index 9672362..2207bcf 100644 --- a/crates/engine/tests/it/backends.rs +++ b/crates/engine/tests/it/backends.rs @@ -214,15 +214,8 @@ fn the_planned_seat_follows_the_size_and_the_pin() { ); std::thread::sleep(Duration::from_millis(10)); }; - // An I+P HEVC export is refused for a different reason: the GPU - // has an HEVC seat, and it codes intra pictures only. - let intra_only_refusal = matches!( - settings.format, - engine::export::Format::Hevc | engine::export::Format::HevcMp4 - ) && !settings.intra_only; assert!( - err.contains("no VA-API seat") - || (intra_only_refusal && err.contains("codes intra pictures only")), + err.contains("no VA-API seat"), "{ext} {width}x{height}: the refusal names the missing seat, got {err}" ); assert!( diff --git a/crates/mcp/src/help.rs b/crates/mcp/src/help.rs index 71cd9f1..654d71c 100644 --- a/crates/mcp/src/help.rs +++ b/crates/mcp/src/help.rs @@ -226,7 +226,7 @@ LANES const EXPORT: &str = "\ EXPORT - export_start {out, preset?, loudness?, format?, range?, size?, fit?, bitrate_kbps?, audio_kbps?, bit_depth?, prores_profile?, hevc_speed?, hdr?, audio_bit_depth?, chapters?, intra_only?, seat?, subtitles?, burn_captions?, overwrite?} + export_start {out, preset?, loudness?, format?, range?, size?, fit?, bitrate_kbps?, qp?, audio_kbps?, bit_depth?, prores_profile?, hevc_speed?, hdr?, audio_bit_depth?, chapters?, intra_only?, seat?, subtitles?, burn_captions?, overwrite?} returns job: at once. Poll it with export_status {job?}; export_cancel {job} stops it and deletes the partial file. out: the file to write; ~/ is expanded and its folder must exist. The extension picks the format: .mp4 mp4 · .mkv av1 · .webm · .wav · .flac · .mp3 · .ogg · .m4a · .opus · .mov prores. Refuses an existing file unless overwrite:true. @@ -240,7 +240,7 @@ EXPORT size: this export's picture size, WIDTHxHEIGHT (1280x720) or a height with p (720p, 1080p, 2160p, 16:9 at that height); 1080x1920 is vertical. Both sides even. Omitted: the project's resolution, which stays as it is. fit: how every picture clip meets this export's canvas: keep (the default: each clip's own fit), fit (whole picture, bars) or fill (the canvas covered, the picture cropped). It changes this export's copy only; the project's clips keep their fit. Captions and titles keep their place on the canvas. A 16:9 timeline as 9:16: export_start {out, size:\"1080x1920\", fit:\"fill\"}. The reply names the size and the fit, and the clip count they applied to. - bitrate_kbps: video, chosen from the picture size and frame rate when omitted. audio_kbps: 128, 192, 256 or 320. + bitrate_kbps: video, chosen from the picture size and frame rate when omitted. qp: a constant quantiser 0..51 instead of a bitrate (not with bitrate_kbps): the hardware seat for H.264, HEVC and AV1, and the software HEVC encoder; the software H.264 and AV1 encoders refuse it. audio_kbps: 128, 192, 256 or 320, and 384 for AAC only. intra_only: hevc and hevc-mp4: true codes every picture as an IDR (intra only, large files, every frame a cut point). false, the default, codes I+P GOPs (an IDR a second, P pictures between). h264 mp4 uses it the same way. Captions: burn_captions draws one track into the picture, so every player and WebM show it. subtitles adds soft tracks a player can switch off (WebM has none). Both together: burned and soft. burn_captions alone: no soft track. diff --git a/crates/mcp/src/tools/export.rs b/crates/mcp/src/tools/export.rs index 0d39cad..8b9758d 100644 --- a/crates/mcp/src/tools/export.rs +++ b/crates/mcp/src/tools/export.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::time::Instant; use engine::demux::Demuxer; -use engine::export::{caption_title_clash, chroma_reduction_words, fit_picture_clips, planned_seats, planned_tone, EncoderSeat, ExportSettings, FitOutcome, Format, HdrOutput, HdrTransfer, GifSettings, HevcSpeed, ProResProfile, AUDIO_KBPS}; +use engine::export::{caption_title_clash, chroma_reduction_words, fit_picture_clips, planned_seats, planned_tone, EncoderSeat, NO_HW_SEAT, ExportSettings, FitOutcome, Format, HdrOutput, HdrTransfer, GifSettings, HevcSpeed, ProResProfile, AAC_MAX_KBPS, AUDIO_KBPS}; use engine::project::LaneKind; use engine::scale::FitPolicy; use engine::captionanim::{CaptionAnim, CaptionStyle, MAX_WORDS_PER_LINE}; @@ -312,12 +312,18 @@ fn start_schema() -> Value { "bitrate_kbps": { "type": "integer", "minimum": 1, - "description": "Video bitrate in kbps. Omitted: chosen from the picture size and frame rate. Ignored by audio-only formats." + "description": "Video bitrate in kbps. Omitted: chosen from the picture size and frame rate. Ignored by audio-only formats. Not with qp." + }, + "qp": { + "type": "integer", + "minimum": 0, + "maximum": 51, + "description": "Constant quantiser for the picture instead of a bitrate, 0 (best, largest) to 51. The hardware seat codes at it for H.264, HEVC and AV1 (AV1 scaled to its 0..255), and the software HEVC encoder too; the software H.264 and AV1 encoders refuse it. Video formats only (mp4, av1, av1-mp4, hevc, hevc-mp4, webm). Not with bitrate_kbps." }, "audio_kbps": { "type": "integer", - "enum": [128, 192, 256, 320], - "description": "Sound bitrate in kbps. Refused where the sound's rate is not a choice (wav, flac, a timeline with no sound, and similar)." + "enum": [128, 192, 256, 320, 384], + "description": "Sound bitrate in kbps: 128, 192, 256 or 320, and 384 for AAC only (mp4, av1, av1-mp4, hevc, hevc-mp4, m4a). Refused where the sound's rate is not a choice (wav, flac, a timeline with no sound, and similar)." }, "seat": { "type": "string", @@ -1132,6 +1138,8 @@ fn plain_video(format: Format, seat: &str) -> String { "hardware" } else if seat.starts_with("copy") { "copy" + } else if seat == NO_HW_SEAT { + "no hardware" } else { "software" }; @@ -1533,12 +1541,35 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { Some(k) => Some(k.saturating_mul(1000)), None => None, }; + let qp = match opt_u64(args, "qp") { + None => None, + Some(q) if q <= 51 => Some(q as u32), + Some(q) => return Reply::err(format!("qp {q} is not 0 to 51")), + }; + if qp.is_some() && bitrate.is_some() { + return Reply::err("qp and bitrate_kbps together: qp fixes the quantiser and bitrate_kbps the rate, so pass one"); + } + if qp.is_some() && sound_only { + return Reply::err("qp sets the picture's quantiser, and this export is the sound alone"); + } + if qp.is_some() && !matches!(format, Format::Mp4 | Format::Av1 | Format::Av1Mp4 | Format::Hevc | Format::HevcMp4 | Format::Webm) { + return Reply::err(format!( + "qp sets the picture's quantiser: it needs an mp4, av1, av1-mp4, hevc, hevc-mp4 or webm export, not {}", + format_name(format) + )); + } + if qp.is_some() && format.is_av1() && seat != EncoderSeat::Hardware { + return Reply::err("qp for AV1 needs seat hardware: auto and software code AV1 in software, which refuses a constant QP"); + } + if qp.is_some() && seat == EncoderSeat::Software && !format.is_hevc() { + return Reply::err("qp with seat software: only the software HEVC encoder writes a constant QP; use seat auto or hardware for H.264"); + } let audio_kbps = match opt_u64(args, "audio_kbps") { None => None, Some(k) => { - let Some(k32) = u32::try_from(k).ok().filter(|v| AUDIO_KBPS.contains(v)) else { + let Some(k32) = u32::try_from(k).ok().filter(|v| AUDIO_KBPS.contains(v) || *v == AAC_MAX_KBPS) else { return Reply::err(format!( - "audio_kbps {k} is not one of {}", + "audio_kbps {k} is not one of {}, or {AAC_MAX_KBPS} for AAC", AUDIO_KBPS.map(|v| v.to_string()).join(", ") )); }; @@ -1548,6 +1579,12 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { format_name(format) )); } + if k32 == AAC_MAX_KBPS && !codes_aac(format) { + return Reply::err(format!( + "audio_kbps {k} is AAC only (mp4, av1, av1-mp4, hevc, hevc-mp4, m4a); {} codes at 320 at most", + format_name(format) + )); + } Some(k32) } }; @@ -1560,7 +1597,7 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { }; // The preset fills what the arguments left out; an explicit argument wins. let preset_settings = preset.map(|p| engine::export_presets::apply(p, ExportSettings::default())); - let bitrate = bitrate.or(preset_settings.as_ref().and_then(|a| a.bitrate)); + let bitrate = bitrate.or(preset_settings.as_ref().filter(|_| qp.is_none()).and_then(|a| a.bitrate)); let audio_kbps = audio_kbps.or(preset_settings.as_ref().and_then(|a| a.audio_kbps)); let size = size.or(preset_settings.as_ref().and_then(|a| a.size)); let video_bit_depth = video_bit_depth.or(preset_settings.as_ref().and_then(|a| a.video_bit_depth)); @@ -1685,6 +1722,7 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { let chapters_written = chapters.len(); let settings = ExportSettings { bitrate, + qp, seat, format, intra_only: opt_bool(args, "intra_only").unwrap_or(false), @@ -1806,13 +1844,20 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { )); } // An HEVC or AV1 export says in one line which encoder codes it and at what rate or quality. - let seat = if picture.starts_with("HW") { "hardware" } else { "software" }; + let seat = match picture.as_str() { + p if p.starts_with("HW") => "hardware", + NO_HW_SEAT => "no hardware", + _ => "software", + }; if let Some(mode) = &hevc_mode { text.push_str(&format!("\nHEVC: {seat} encoder, {mode}")); } if let Some(mode) = &av1_mode { text.push_str(&format!("\nAV1: {seat} encoder, {mode}")); } + if let (Some(q), false) = (qp, format.is_hevc() || format.is_av1()) { + text.push_str(&format!("\nH.264: {seat} encoder, constant QP {q}")); + } if !waiting { text.push_str("\nThe export keeps running while you do other things; if the client only closes this server's input it finishes before the server exits, but if the server is stopped by a signal (as most clients do when they quit) it is cancelled and its partial file removed — poll export_status until it finishes."); } if !sub_note.is_empty() { text.push('\n'); @@ -1852,6 +1897,11 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { })) } +/// Whether the format's sound is AAC, the only one that codes above 320 kbps. +fn codes_aac(format: Format) -> bool { + matches!(format, Format::Mp4 | Format::Av1 | Format::Av1Mp4 | Format::Hevc | Format::HevcMp4 | Format::M4a) +} + /// Whether any picture source the timeline reads is 10-bit: the same test the engine's AV1 /// seat makes ([`engine::export`]'s `av1_ten_bit`). Still images have no bit depth to read. fn source_ten_bit(s: &PlaybackSession) -> bool { @@ -2348,7 +2398,8 @@ mod tests { })); assert!(!at_rate.is_error, "{}", at_rate.text); assert!( - at_rate.text.contains("\nHEVC: software encoder, I+P GOP (1 s keyframes), 4 Mb/s"), + at_rate.text.contains("\nHEVC: software encoder, I+P GOP (1 s keyframes), 4 Mb/s") + || at_rate.text.contains("\nHEVC: hardware encoder, I+P GOP (1 s keyframes), 4 Mb/s"), "the I+P line names the seat, the GOP and the rate: {}", at_rate.text ); @@ -2358,7 +2409,8 @@ mod tests { })); assert!(!quality.is_error, "{}", quality.text); assert!( - quality.text.contains("\nHEVC: software encoder, I+P GOP (1 s keyframes), constant quality"), + quality.text.contains("\nHEVC: software encoder, I+P GOP (1 s keyframes), constant quality") + || quality.text.contains("\nHEVC: hardware encoder, I+P GOP (1 s keyframes), constant quality"), "the automatic row says constant quality: {}", quality.text );