Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

export: estimate RGB TIFF sequence size from written channels

Nigel Ihza Firdausy8859e98fb7ba
diff --git a/crates/export/src/settings.rs b/crates/export/src/settings.rs
index be8271825..1a427302d 100644
--- a/crates/export/src/settings.rs
+++ b/crates/export/src/settings.rs
@@ -486,7 +486,8 @@ impl ExportSettings {
}
Format::Mjpeg | Format::JpegSequence => px * 8.0 * (0.4 + self.quality as f64 / 100.0 * 2.0) * fps / 8.0,
Format::PngSequence => px * 4.0 * 0.45 * 8.0 * fps,
- Format::TiffSequence | Format::BmpSequence => px * if self.format == Format::BmpSequence { 3.0 } else { 4.0 } * 8.0 * fps,
+ Format::BmpSequence => px * 3.0 * 8.0 * fps,
+ Format::TiffSequence => px * if self.keeps_alpha() { 4.0 } else { 3.0 } * 8.0 * fps,
Format::TgaSequence => px * if self.keeps_alpha() { 4.0 } else { 3.0 } * 8.0 * fps,
// 10-bit RGB in one 32-bit word per pixel
Format::DpxSequence => px * 4.0 * 8.0 * fps,
diff --git a/crates/export/src/settings_tests.rs b/crates/export/src/settings_tests.rs
index fb68289ec..e9b49495d 100644
--- a/crates/export/src/settings_tests.rs
+++ b/crates/export/src/settings_tests.rs
@@ -861,6 +861,44 @@ fn extreme_bitrates_do_not_overflow_encoder_setup() {
}
}
+#[test]
+fn tiff_size_estimate_tracks_alpha_and_real_output() {
+ let (project, sequence, sources) = matte([0.0, 0.0, 1.0, 0.5], 320, 180, None);
+ let rate = FrameRate::FPS_24;
+ let duration = rate.tick_of(1);
+ for alpha in [false, true] {
+ let dir = Scratch::new(&format!("tiff-size-{alpha}"));
+ let mut settings = ExportSettings {
+ format: Format::TiffSequence,
+ path: dir.path("frame.tif"),
+ alpha,
+ ..Default::default()
+ };
+ settings.range = Some(TimeRange::new(Tick::ZERO, duration));
+ settings.validate().unwrap();
+
+ let expected = 320_u64 * 180 * if alpha { 4 } else { 3 };
+ let summary = settings.summary(320, 180, rate, 48_000, duration);
+ assert_eq!(summary.estimated_bytes, expected, "alpha={alpha}");
+ assert_eq!(settings.estimate_bytes(320, 180, rate, 48_000, duration), expected);
+ let result = export(&project, sequence, &settings, &sources, &Progress::default()).unwrap();
+ assert_eq!(result.frames, 1);
+ let paths = files_in(&dir.0);
+ assert_eq!(paths.len(), 1, "{paths:?}");
+ let actual_bytes = std::fs::metadata(dir.0.join(&paths[0])).unwrap().len();
+ assert!(actual_bytes.abs_diff(summary.estimated_bytes) < 1024, "alpha={alpha}: estimate={} actual={actual_bytes}", summary.estimated_bytes);
+ }
+
+ // Other uncompressed formats already have the correct channel policy.
+ for format in [Format::BmpSequence, Format::TgaSequence] {
+ let rgb = ExportSettings { format, alpha: false, ..Default::default() };
+ let rgba = ExportSettings { format, alpha: true, ..Default::default() };
+ assert_eq!(rgb.estimate_bytes(320, 180, rate, 48_000, duration), 320 * 180 * 3);
+ let expected = if format == Format::BmpSequence { 3 } else { 4 };
+ assert_eq!(rgba.estimate_bytes(320, 180, rate, 48_000, duration), 320 * 180 * expected);
+ }
+}
+
#[test]
fn gpu_rendering_is_off_by_default() {
assert_eq!(ExportSettings::default().gpu_rendering, crate::GpuRendering::Off);