Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Ensure even dimensions for H264 encoding

Richie McIlroyad8a6091c6ae
diff --git a/crates/enc-ffmpeg/src/video/h264.rs b/crates/enc-ffmpeg/src/video/h264.rs
index aba2f45f8..6c6896bc9 100644
--- a/crates/enc-ffmpeg/src/video/h264.rs
+++ b/crates/enc-ffmpeg/src/video/h264.rs
@@ -20,6 +20,11 @@ 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,
@@ -90,10 +95,23 @@ impl H264EncoderBuilder {
output: &mut format::context::Output,
) -> Result<H264Encoder, H264EncoderError> {
let input_config = self.input_config;
- let (output_width, output_height) = self
+ let (raw_width, raw_height) = self
.output_size
.unwrap_or((input_config.width, input_config.height));
+ let output_width = ensure_even(raw_width);
+ let output_height = ensure_even(raw_height);
+
+ if raw_width != output_width || raw_height != output_height {
+ warn!(
+ raw_width,
+ raw_height,
+ output_width,
+ output_height,
+ "Auto-adjusted odd dimensions to even for H264 encoding"
+ );
+ }
+
if output_width == 0 || output_height == 0 {
return Err(H264EncoderError::InvalidOutputDimensions {
width: output_width,