export: H.264 color range toggle (fix dark/oversaturated output)

The zero-copy VAAPI encoder emitted full-range BT.709 NV12 but wrote no color
tags, so players assumed limited range and stretched it — the H.264 output
looked dark and oversaturated (preview and VP9/software were fine).

- Rgba2Nv12 takes `full_range` and applies the matching Y/chroma scale+offset
  (limited 16-235 / full 0-255) via a uniform; the encoder sets color_range +
  bt709 colorspace/primaries/transfer tags to match. ffprobe-confirmed.
- New ColorRange { Limited, Full } on VideoExportSettings (default Limited, the
  universally-correct choice; serde(default) so saved settings still load),
  surfaced as a "Color range" dropdown in advanced export settings for H.264.

The swscale software fallback still emits Limited regardless of the toggle
(Full only affects the VAAPI zero-copy path).
This commit is contained in:
Skyler Lehmkuhl
2026-06-26 00:38:19 -04:00
parent f1fba186c1
commit 9411145ce9
7 changed files with 122 additions and 22 deletions
@@ -265,6 +265,29 @@ impl VideoCodec {
}
}
/// YUV color range for the encoded video (currently H.264). Limited/TV (16–235) is what nearly
/// every player assumes; Full/PC (0–255) keeps a bit more precision but only looks right in players
/// that honor the full-range tag — so Limited is the safe default.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ColorRange {
Limited,
Full,
}
impl Default for ColorRange {
fn default() -> Self { ColorRange::Limited }
}
impl ColorRange {
pub fn is_full(&self) -> bool { matches!(self, ColorRange::Full) }
pub fn name(&self) -> &'static str {
match self {
ColorRange::Limited => "Limited (TV, 16–235)",
ColorRange::Full => "Full (PC, 0–255)",
}
}
}
/// Video quality presets
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum VideoQuality {
@@ -322,6 +345,10 @@ pub struct VideoExportSettings {
/// Video quality
pub quality: VideoQuality,
/// YUV color range (H.264 only; ignored by other codecs).
#[serde(default)]
pub color_range: ColorRange,
/// Audio settings (None = no audio)
pub audio: Option<AudioExportSettings>,
@@ -340,6 +367,7 @@ impl Default for VideoExportSettings {
height: None,
framerate: 60.0,
quality: VideoQuality::High,
color_range: ColorRange::Limited,
audio: Some(AudioExportSettings::high_quality_aac()),
start_time: 0.0,
end_time: 60.0,