Skip to content

Commit 192e335

Browse files
committed
[*] update normally
1 parent 7a65340 commit 192e335

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

lib/recorder/src/recorder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const INPUT_AUDIO_EXTENSION: &str = "input.wav";
2929
const SPEAKER_AUDIO_EXTENSION: &str = "speaker.wav";
3030
const TMP_OUTPUT_VIDEO_EXTENSION: &str = "tmp.mp4";
3131

32-
const USER_CHANNEL_SIZE: usize = 3;
33-
const RESIZE_WORKER_CHANNEL_SIZE: usize = 8;
34-
const ENCODER_WORKER_CHANNEL_SIZE: usize = 64;
32+
const USER_CHANNEL_SIZE: usize = 8;
33+
const RESIZE_WORKER_CHANNEL_SIZE: usize = 32;
34+
const ENCODER_WORKER_CHANNEL_SIZE: usize = 128;
3535

3636
static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::new(None));
3737

lib/recorder/src/video_encoder.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{FPS, recorder::ResizedImageBuffer, recorder_error::RecorderError};
2-
use x264::{Colorspace, Data, Encoder, Image};
2+
use x264::{Colorspace, Data, Encoder, Image, Preset, Setup, Tune};
33

44
/// Represents the result of video encoding operations.
55
///
@@ -186,15 +186,19 @@ impl VideoEncoder {
186186
assert!(width > 0 && height > 0);
187187

188188
// Create x264 encoder with optimized settings for screen recording
189-
let encoder = Encoder::builder()
190-
.fps(fps.to_u32(), 1)
191-
.build(Colorspace::RGB, width as i32, height as i32)
192-
.map_err(|e| {
193-
RecorderError::VideoEncodingFailed(format!(
194-
"Failed to create x264 encoder: {:?}",
195-
e
196-
))
197-
})?;
189+
// Using ultrafast preset with stillimage tune for minimal memory usage
190+
let encoder = Setup::preset(
191+
Preset::Ultrafast, // Minimal memory usage and fastest encoding
192+
Tune::StillImage, // Optimized for screen content (static images)
193+
true, // fast_decode: Enable fast decoding
194+
true, // zero_latency: Minimal internal buffering
195+
)
196+
.fps(fps.to_u32(), 1)
197+
.baseline() // Ensure maximum compatibility
198+
.build(Colorspace::RGB, width as i32, height as i32)
199+
.map_err(|e| {
200+
RecorderError::VideoEncodingFailed(format!("Failed to create x264 encoder: {:?}", e))
201+
})?;
198202

199203
Ok(Self {
200204
encoder,
@@ -252,7 +256,6 @@ impl VideoEncoder {
252256
// Calculate timestamp in milliseconds (frame_index * 1000 / fps)
253257
let timestamp_ms = (self.frame_index * 1000) / self.fps.to_u32() as u64;
254258

255-
// NOTE: It will eat your memory (about 1G)
256259
let (data, _) = self
257260
.encoder
258261
.encode(timestamp_ms as i64, image)

0 commit comments

Comments
 (0)