record: size recordings from the screen, not the quality preset

The quality preset chose the OBS canvas while the capture ran at the
game's real size, and the scene item carries no transform, so picking
1080p on a 1440p screen recorded only the top-left 1920x1080 crop of
the game.

Recordings now always run at the primary monitor's resolution, queried
in device pixels so display scaling cannot skew them, and a recording
start re-checks the screen so a display change mid-session cannot
bring the crop back. Quality presets keep their bitrate meaning and
nothing else; they never reached the encoder before, so High, Ultra
and friends now actually change what a recording costs on disk.
This commit is contained in:
vhaudiquet committed 2026-11-21 18:15:52 +01:00
1 parent 1d7f87f71d
commit b1cde7e783
5 files changed
+106 -75

No files matched your search

+5 -4
View File
@@ -171,12 +171,13 @@ impl Quality {
} }
} }
/// What a quality level records at: the screen's resolution, at this bitrate.
pub fn detail(self) -> &'static str { pub fn detail(self) -> &'static str {
match self { match self {
Quality::Low => "720p @ 30fps", Quality::Low => "Your screen's resolution at 4.5 Mbps",
Quality::Medium => "1080p @ 30fps", Quality::Medium => "Your screen's resolution at 6 Mbps",
Quality::High => "1080p @ 60fps", Quality::High => "Your screen's resolution at 8 Mbps",
Quality::Ultra => "1440p @ 60fps", Quality::Ultra => "Your screen's resolution at 12 Mbps",
} }
} }
} }
+6 -4
View File
@@ -201,11 +201,13 @@ enum EncoderPreset {
} }
enum QualityLevel { enum QualityLevel {
Low, // 720p30, lower bitrate Low, // 4.5 Mbps bitrate tier
Medium, // 1080p30, moderate bitrate Medium, // 6 Mbps
High, // 1080p60, high bitrate High, // 8 Mbps
Ultra, // 1440p60, max quality Ultra, // 12 Mbps
} }
// Recordings always run at the screen resolution: the daemon sizes the OBS
// canvas from the primary monitor, and quality only trades bitrate.
``` ```
### 2. LQP Client ### 2. LQP Client
+21 -40
View File
@@ -89,43 +89,26 @@ pub enum AmfQuality {
Quality, Quality,
} }
/// Quality level presets that configure resolution and other parameters. /// Quality level presets as bitrate tiers.
///
/// Recordings always run at the screen's resolution; these only trade file size
/// against detail. Frame rate comes from `VideoSettings::frame_rate`.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)] #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum QualityLevel { pub enum QualityLevel {
/// 720p @ 30fps, lower bitrate. /// 4500 kbps, smaller files.
Low, Low,
/// 1080p @ 30fps, moderate bitrate. /// 6000 kbps.
Medium, Medium,
/// 1080p @ 60fps, high bitrate. /// 8000 kbps.
#[default] #[default]
High, High,
/// 1440p @ 60fps, maximum quality. /// 12000 kbps, largest files.
Ultra, Ultra,
} }
impl QualityLevel { impl QualityLevel {
/// Get the target resolution for this quality level. /// Get the bitrate in kbps this quality level records at.
pub fn resolution(&self) -> (u32, u32) {
match self {
QualityLevel::Low => (1280, 720),
QualityLevel::Medium => (1920, 1080),
QualityLevel::High => (1920, 1080),
QualityLevel::Ultra => (2560, 1440),
}
}
/// Get the recommended frame rate for this quality level.
pub fn frame_rate(&self) -> u32 {
match self {
QualityLevel::Low => 30,
QualityLevel::Medium => 30,
QualityLevel::High => 60,
QualityLevel::Ultra => 60,
}
}
/// Get the recommended bitrate in kbps for this quality level.
pub fn recommended_bitrate(&self) -> u32 { pub fn recommended_bitrate(&self) -> u32 {
match self { match self {
QualityLevel::Low => 4500, QualityLevel::Low => 4500,
@@ -342,15 +325,6 @@ impl EncoderPreset {
} }
} }
/// Get the effective bitrate for this preset.
pub fn effective_bitrate(&self) -> u32 {
match self {
EncoderPreset::Nvenc { bitrate, .. } => *bitrate,
EncoderPreset::Amf { bitrate, .. } => *bitrate,
EncoderPreset::X264 { bitrate, .. } => *bitrate,
}
}
/// Create a preset optimized for the given quality level. /// Create a preset optimized for the given quality level.
pub fn for_quality(quality: QualityLevel, capability: EncoderCapability) -> Self { pub fn for_quality(quality: QualityLevel, capability: EncoderCapability) -> Self {
let bitrate = quality.recommended_bitrate(); let bitrate = quality.recommended_bitrate();
@@ -384,10 +358,10 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_quality_level_resolution() { fn test_quality_level_bitrate() {
assert_eq!(QualityLevel::Low.resolution(), (1280, 720)); assert_eq!(QualityLevel::Low.recommended_bitrate(), 4500);
assert_eq!(QualityLevel::High.resolution(), (1920, 1080)); assert_eq!(QualityLevel::High.recommended_bitrate(), 8000);
assert_eq!(QualityLevel::Ultra.resolution(), (2560, 1440)); assert_eq!(QualityLevel::Ultra.recommended_bitrate(), 12000);
} }
#[test] #[test]
@@ -410,7 +384,14 @@ mod tests {
#[test] #[test]
fn test_preset_for_quality() { fn test_preset_for_quality() {
let preset = EncoderPreset::for_quality(QualityLevel::High, EncoderCapability::Nvenc); let preset = EncoderPreset::for_quality(QualityLevel::High, EncoderCapability::Nvenc);
assert_eq!(preset.effective_bitrate(), 8000); assert_eq!(
preset,
EncoderPreset::Nvenc {
bitrate: 8000,
cq_level: 20,
two_pass: true
}
);
assert!(preset.is_hardware()); assert!(preset.is_hardware());
} }
} }
+7
View File
@@ -46,6 +46,13 @@ pub struct VideoSettings {
pub hardware_acceleration: bool, pub hardware_acceleration: bool,
} }
impl VideoSettings {
/// The bitrate a recording runs at: the quality tier's.
pub fn video_bitrate(&self) -> u32 {
self.quality.recommended_bitrate()
}
}
impl Default for VideoSettings { impl Default for VideoSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
+67 -27
View File
@@ -127,6 +127,7 @@ impl ObsContextBuilder {
recording: false, recording: false,
pending_audio: None, pending_audio: None,
encoder_capability: None, encoder_capability: None,
canvas: (0, 0),
tracks: Vec::new(), tracks: Vec::new(),
}) })
} }
@@ -157,6 +158,9 @@ pub struct ObsContext {
/// Settings that arrived while a recording was running, applied once it stops. /// Settings that arrived while a recording was running, applied once it stops.
pending_audio: Option<(VideoSettings, AudioSettings)>, pending_audio: Option<(VideoSettings, AudioSettings)>,
encoder_capability: Option<EncoderCapability>, encoder_capability: Option<EncoderCapability>,
/// The canvas the video pipeline currently runs at, so a settings change or
/// a new recording can tell whether the screen resolution moved under it.
canvas: (u32, u32),
/// What each audio track of the running recording carries, in file order. /// What each audio track of the running recording carries, in file order.
tracks: Vec<String>, tracks: Vec<String>,
} }
@@ -191,7 +195,7 @@ impl ObsContext {
self.encoder_capability = Some(encoder); self.encoder_capability = Some(encoder);
info!("OBS encoder: {:?}", encoder); info!("OBS encoder: {:?}", encoder);
let (width, height) = self.video_settings.quality.resolution(); let (width, height) = canvas_resolution();
let fps = self.video_settings.frame_rate; let fps = self.video_settings.frame_rate;
let video_info = ObsVideoInfoBuilder::new() let video_info = ObsVideoInfoBuilder::new()
@@ -232,6 +236,7 @@ impl ObsContext {
)); ));
self.scene = Some(scene); self.scene = Some(scene);
self.context = Some(context); self.context = Some(context);
self.canvas = (width, height);
info!( info!(
"OBS context initialized ({}x{} @ {}fps)", "OBS context initialized ({}x{} @ {}fps)",
@@ -260,31 +265,7 @@ impl ObsContext {
return self.start(); return self.start();
} }
if video.frame_rate != self.video_settings.frame_rate self.reset_video_if_changed(video.frame_rate)?;
|| video.quality != self.video_settings.quality
{
let encoder = self
.encoder_capability
.unwrap_or_else(best_available_encoder);
let (width, height) = video.quality.resolution();
let video_info = ObsVideoInfoBuilder::new()
.fps_num(video.frame_rate)
.fps_den(1)
.base_width(width)
.base_height(height)
.output_width(width)
.output_height(height)
.build();
if let Some(context) = self.context.as_mut() {
context.reset_video(video_info).map_err(|e| {
RecordingError::StartError(format!("failed to reset video: {:?}", e))
})?;
}
info!(
"video reset to {}x{} @ {}fps ({:?})",
width, height, video.frame_rate, encoder
);
}
if audio != self.audio_settings { if audio != self.audio_settings {
let context = self let context = self
@@ -319,6 +300,7 @@ impl ObsContext {
self.apply_now(video, audio)?; self.apply_now(video, audio)?;
} }
self.start()?; self.start()?;
self.reset_video_if_changed(self.video_settings.frame_rate)?;
let context = self let context = self
.context .context
@@ -332,7 +314,7 @@ impl ObsContext {
let encoder = self let encoder = self
.encoder_capability .encoder_capability
.unwrap_or_else(best_available_encoder); .unwrap_or_else(best_available_encoder);
let bitrate = self.video_settings.encoder_preset.effective_bitrate(); let bitrate = self.video_settings.video_bitrate();
let obs_path = ObsPath::new(&output_path.to_string_lossy()); let obs_path = ObsPath::new(&output_path.to_string_lossy());
let mut builder = let mut builder =
@@ -447,6 +429,39 @@ impl ObsContext {
self.context = None; self.context = None;
Ok(()) Ok(())
} }
/// Rebuild the video pipeline when the frame rate or the screen moved.
///
/// Both a settings change and a recording start go through here, so the canvas
/// always matches the capture and the recording never crops the game.
fn reset_video_if_changed(&mut self, fps: u32) -> Result<()> {
let (width, height) = canvas_resolution();
if fps == self.video_settings.frame_rate && (width, height) == self.canvas {
return Ok(());
}
let encoder = self
.encoder_capability
.unwrap_or_else(best_available_encoder);
let video_info = ObsVideoInfoBuilder::new()
.fps_num(fps)
.fps_den(1)
.base_width(width)
.base_height(height)
.output_width(width)
.output_height(height)
.build();
if let Some(context) = self.context.as_mut() {
context.reset_video(video_info).map_err(|e| {
RecordingError::StartError(format!("failed to reset video: {:?}", e))
})?;
}
self.canvas = (width, height);
info!(
"video reset to {}x{} @ {}fps ({:?})",
width, height, fps, encoder
);
Ok(())
}
} }
impl Drop for ObsContext { impl Drop for ObsContext {
@@ -479,6 +494,31 @@ fn audio_source(
Ok(source) Ok(source)
} }
/// The resolution to record at: the primary monitor's, in device pixels.
///
/// The capture fills the canvas one to one, so a recording never crops or rescales
/// the game, whatever preset is set. Falls back to 1080p if the display query fails.
fn canvas_resolution() -> (u32, u32) {
const FALLBACK: (u32, u32) = (1920, 1080);
let displays = match display_info::DisplayInfo::all() {
Ok(displays) if !displays.is_empty() => displays,
_ => {
warn!(
"could not list displays, recording at {}x{}",
FALLBACK.0, FALLBACK.1
);
return FALLBACK;
}
};
let screen = displays
.iter()
.find(|d| d.is_primary)
.unwrap_or_else(|| displays.iter().max_by_key(|d| d.width * d.height).unwrap());
// H.264 encoders want even dimensions.
let even = |v: u32| v & !1;
(even(screen.width), even(screen.height))
}
/// Audio that comes from a device: the microphone and any configured second device. /// Audio that comes from a device: the microphone and any configured second device.
/// ///
/// These live in the scene for the whole session. Process captures are in the scene as well, /// These live in the scene for the whole session. Process captures are in the scene as well,