Address code-review findings across export, decode, and data model
Export correctness: - Honor the user's color-range (Limited/Full) on the software encode path: thread full_range through gpu_yuv (new shader range uniform), the CPU swscale fallback (sws_setColorspaceDetails → BT.709 + range, fixing the BT.601 hue/level shift on odd-width exports), and the encoder color tags. - Reject HDR + WebM up front with a clear message and log the forced HEVC override instead of producing an unplayable file. - Delete dead render_frame_to_rgba_hdr (hardcoded Stretch; live HDR path already honors the fit mode). Decode/playback (video.rs): - Drain the decoder at EOF (send_eof + flush) so the final B-frame-delayed frames render instead of erroring; per-frame logic extracted to a helper. - Missing-PTS frames continue monotonically rather than snapping to ts=0. - Force exact thumbnail width so sub-128px sources aren't shown stretched. Resource leaks (gpu-video-encoder): - dmabuf import_raw: RAII guard frees the duped fd + partial VkImages/memory on every error path. - vaapi alloc: free device/frames-ctx/AVFrames on the unexpected-DRM path. Data model / robustness: - collapse_boundary_spikes requires a full curve reversal (all control points) so it no longer deletes a real lens/sliver and drops the fill. - Export audio spin-wait ignores a stale `finished` flag when a forward seek is pending (was rendering silence over real audio). - RasterDiff apply_before/after take current dims and skip on a post-resize mismatch. - beam_archive read_media_full caps the preallocation from untrusted total_len. UI/visual: - SVG export skips hidden layers/empty groups; import folds fill-opacity into gradients and surfaces failures as a notification. - Active raster-layer border uses playback_time + overlay_transform. - gpu_brush remove_layer_texture also evicts the stale low-res proxy. - ensure_raster_resident_for_undo registers faulted frames in the LRU so resident RAM stays bounded. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
1fa4d744be
commit
b301c63387
@@ -57,6 +57,9 @@ pub struct VideoExportState {
|
||||
hdr: lightningbeam_core::export::HdrExportMode,
|
||||
/// How the document is fit into the export frame (stretch/letterbox/crop).
|
||||
fit: lightningbeam_core::export::ExportFitMode,
|
||||
/// SDR color range: true = full (PC, 0–255), false = limited (TV, 16–235). The YUV
|
||||
/// converters and the encoder color tag must agree on this.
|
||||
full_range: bool,
|
||||
/// Channel to send rendered frames to encoder thread
|
||||
frame_tx: Option<Sender<VideoFrameMessage>>,
|
||||
/// HDR GPU resources for compositing pipeline (effects, color conversion)
|
||||
@@ -868,6 +871,7 @@ impl ExportOrchestrator {
|
||||
) -> (std::thread::JoinHandle<()>, VideoExportState) {
|
||||
let hdr = settings.hdr;
|
||||
let fit = settings.fit;
|
||||
let full_range = settings.color_range.is_full();
|
||||
let handle = std::thread::spawn(move || {
|
||||
Self::run_video_encoder(settings, output_path, frame_rx, progress_tx, cancel_flag, total_frames);
|
||||
});
|
||||
@@ -882,6 +886,7 @@ impl ExportOrchestrator {
|
||||
height,
|
||||
hdr,
|
||||
fit,
|
||||
full_range,
|
||||
frame_tx: Some(frame_tx),
|
||||
gpu_resources: None,
|
||||
readback_pipeline: None,
|
||||
@@ -1333,8 +1338,8 @@ impl ExportOrchestrator {
|
||||
if !gpu_yuv_tight {
|
||||
println!("🎬 [VIDEO EXPORT] YUV planes are padded at {width}x{height}; using CPU YUV path");
|
||||
}
|
||||
state.readback_pipeline = Some(readback_pipeline::ReadbackPipeline::new(device, queue, width, height, gpu_yuv_tight));
|
||||
state.cpu_yuv_converter = Some(cpu_yuv_converter::CpuYuvConverter::new(width, height)?);
|
||||
state.readback_pipeline = Some(readback_pipeline::ReadbackPipeline::new(device, queue, width, height, gpu_yuv_tight, state.full_range));
|
||||
state.cpu_yuv_converter = Some(cpu_yuv_converter::CpuYuvConverter::new(width, height, state.full_range)?);
|
||||
println!("🚀 [ASYNC PIPELINE] Triple-buffered pipeline initialized");
|
||||
println!("🚀 [CPU YUV] swscale converter initialized");
|
||||
}
|
||||
@@ -1638,6 +1643,21 @@ impl ExportOrchestrator {
|
||||
// Convert codec enum to FFmpeg codec ID. HDR requires 10-bit HEVC (Main10), so force HEVC
|
||||
// regardless of the chosen codec when an HDR mode is selected.
|
||||
let codec_id = if settings.hdr.is_hdr() {
|
||||
// HEVC can only be muxed into MP4/MOV, not WebM — reject the incompatible combo up
|
||||
// front with a clear message instead of letting the muxer fail cryptically.
|
||||
if settings.codec.container_format() == "webm" {
|
||||
return Err(format!(
|
||||
"HDR export needs H.265/HEVC in an MP4 container, but {} uses WebM. \
|
||||
Pick H.265 (or H.264) for HDR.",
|
||||
settings.codec.name()
|
||||
));
|
||||
}
|
||||
if !matches!(settings.codec, VideoCodec::H265) {
|
||||
println!(
|
||||
"⚠️ [ENCODER] HDR selected: overriding codec {} → H.265/HEVC (Main10)",
|
||||
settings.codec.name()
|
||||
);
|
||||
}
|
||||
ffmpeg_next::codec::Id::HEVC
|
||||
} else {
|
||||
match settings.codec {
|
||||
@@ -1690,6 +1710,7 @@ impl ExportOrchestrator {
|
||||
framerate,
|
||||
bitrate_kbps,
|
||||
settings.hdr,
|
||||
settings.color_range.is_full(),
|
||||
)?;
|
||||
|
||||
// Pixel format the encoder frames are built in (matches setup_video_encoder).
|
||||
|
||||
Reference in New Issue
Block a user