Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Refactor ensure_even to shared module and remove duplicates
Richie McIlroy22af33745959
diff --git a/crates/enc-ffmpeg/src/video/h264.rs b/crates/enc-ffmpeg/src/video/h264.rsindex 6c6896bc9..b6fb1fcf9 100644--- a/crates/enc-ffmpeg/src/video/h264.rs+++ b/crates/enc-ffmpeg/src/video/h264.rs@@ -1,6 +1,6 @@use std::{thread, time::Duration};-use cap_media_info::{Pixel, VideoInfo};+use cap_media_info::{Pixel, VideoInfo, ensure_even};use ffmpeg::{Dictionary,codec::{codec::Codec, context, encoder},@@ -20,11 +20,6 @@ fn is_420(format: ffmpeg::format::Pixel) -> bool {.unwrap_or(false)}-fn ensure_even(value: u32) -> u32 {- let adjusted = value - (value % 2);- if adjusted == 0 { 2 } else { adjusted }-}-pub struct H264EncoderBuilder {bpp: f32,input_config: VideoInfo,@@ -112,13 +107,6 @@ impl H264EncoderBuilder {);}- if output_width == 0 || output_height == 0 {- return Err(H264EncoderError::InvalidOutputDimensions {- width: output_width,- height: output_height,- });- }-let candidates = get_codec_and_options(&input_config, self.preset);if candidates.is_empty() {return Err(H264EncoderError::CodecNotFound);diff --git a/crates/enc-ffmpeg/src/video/hevc.rs b/crates/enc-ffmpeg/src/video/hevc.rsindex 276340195..37b555592 100644--- a/crates/enc-ffmpeg/src/video/hevc.rs+++ b/crates/enc-ffmpeg/src/video/hevc.rs@@ -1,6 +1,6 @@use std::{thread, time::Duration};-use cap_media_info::{Pixel, VideoInfo};+use cap_media_info::{Pixel, VideoInfo, ensure_even};use ffmpeg::{Dictionary,codec::{codec::Codec, context, encoder},@@ -20,11 +20,6 @@ fn is_420(format: ffmpeg::format::Pixel) -> bool {.unwrap_or(false)}-fn ensure_even(value: u32) -> u32 {- let adjusted = value - (value % 2);- if adjusted == 0 { 2 } else { adjusted }-}-pub struct HevcEncoderBuilder {bpp: f32,input_config: VideoInfo,@@ -111,13 +106,6 @@ impl HevcEncoderBuilder {);}- if output_width == 0 || output_height == 0 {- return Err(HevcEncoderError::InvalidOutputDimensions {- width: output_width,- height: output_height,- });- }-let candidates = get_codec_and_options(&input_config, self.preset);if candidates.is_empty() {return Err(HevcEncoderError::CodecNotFound);diff --git a/crates/media-info/src/lib.rs b/crates/media-info/src/lib.rsindex 71b168299..76d6fb950 100644--- a/crates/media-info/src/lib.rs+++ b/crates/media-info/src/lib.rs@@ -325,6 +325,11 @@ impl VideoInfo {}}+pub fn ensure_even(value: u32) -> u32 {+ let adjusted = value - (value % 2);+ if adjusted == 0 { 2 } else { adjusted }+}+pub fn ffmpeg_sample_format_for(sample_format: SampleFormat) -> Option<Sample> {match sample_format {SampleFormat::U8 => Some(Sample::U8(Type::Planar)),diff --git a/crates/recording/src/instant_recording.rs b/crates/recording/src/instant_recording.rsindex e9b8fd375..527af4ac8 100644--- a/crates/recording/src/instant_recording.rs+++ b/crates/recording/src/instant_recording.rs@@ -5,6 +5,7 @@ use crate::{},feeds::microphone::MicrophoneFeedLock,output_pipeline::{self, OutputPipeline},+ resolution_limits::ensure_even,sources::screen_capture::{ScreenCaptureConfig, ScreenCaptureTarget},};use anyhow::Context as _;@@ -418,11 +419,6 @@ fn current_time_f64() -> f64 {.as_secs_f64()}-fn ensure_even(value: u32) -> u32 {- let adjusted = value - (value % 2);- if adjusted == 0 { 2 } else { adjusted }-}-fn clamp_size(input: (u32, u32), max: (u32, u32)) -> (u32, u32) {// 16/9-ishif input.0 >= input.1 && (input.0 as f64 / input.1 as f64) <= 16.0 / 9.0 {diff --git a/crates/recording/src/resolution_limits.rs b/crates/recording/src/resolution_limits.rsindex b1668cef7..c052de2a2 100644--- a/crates/recording/src/resolution_limits.rs+++ b/crates/recording/src/resolution_limits.rs@@ -1,3 +1,5 @@+pub use cap_media_info::ensure_even;+pub const H264_MAX_DIMENSION: u32 = 4096;pub fn calculate_gpu_compatible_size(@@ -57,11 +59,6 @@ pub fn calculate_gpu_compatible_size(Some((final_width, final_height))}-fn ensure_even(value: u32) -> u32 {- let adjusted = value - (value % 2);- if adjusted == 0 { 2 } else { adjusted }-}-#[cfg(test)]mod tests {use super::*;