Skip to content

Commit 6f85456

Browse files
committed
feat: Update HLS time to 3 seconds
1 parent 0cf13bd commit 6f85456

File tree

1 file changed

+19
-27
lines changed
  • apps/desktop/src-tauri/src/media

1 file changed

+19
-27
lines changed

apps/desktop/src-tauri/src/media/mod.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
use std::{
2-
path::{Path, PathBuf},
2+
path::{ Path, PathBuf },
33
process::Stdio,
4-
sync::{
5-
atomic::{AtomicBool, Ordering},
6-
Arc,
7-
},
8-
time::{Duration, Instant},
4+
sync::{ atomic::{ AtomicBool, Ordering }, Arc },
5+
time::{ Duration, Instant },
96
};
10-
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
11-
use tokio::process::{Child, ChildStdin, Command};
7+
use tokio::io::{ AsyncBufReadExt, AsyncWriteExt, BufReader };
8+
use tokio::process::{ Child, ChildStdin, Command };
129
use tokio::sync::Mutex;
1310
use tokio::task::JoinHandle;
1411
use tracing::Level;
1512

1613
use crate::{
1714
app::config,
1815
recording::RecordingOptions,
19-
utils::{create_named_pipe, ffmpeg_path_as_str},
16+
utils::{ create_named_pipe, ffmpeg_path_as_str },
2017
};
2118

2219
mod audio;
@@ -83,7 +80,7 @@ impl MediaRecorder {
8380
recording_dir: &Path,
8481
custom_device: Option<&str>,
8582
max_screen_width: usize,
86-
max_screen_height: usize,
83+
max_screen_height: usize
8784
) -> Result<(), String> {
8885
if !scap::has_permission() {
8986
tracing::warn!("Screen capturing permission not granted. Requesting permission...");
@@ -107,7 +104,7 @@ impl MediaRecorder {
107104
let mut video_capturer = VideoCapturer::new(
108105
max_screen_width,
109106
max_screen_height,
110-
self.should_stop.clone(),
107+
self.should_stop.clone()
111108
);
112109
let adjusted_width = video_capturer.frame_width;
113110
let adjusted_height = video_capturer.frame_height;
@@ -116,7 +113,9 @@ impl MediaRecorder {
116113
audio_capturer.log_info();
117114

118115
match audio_capturer.start(audio_start_time.clone()) {
119-
Ok(_) => self.audio_enabled = true,
116+
Ok(_) => {
117+
self.audio_enabled = true;
118+
}
120119
Err(error) => tracing::error!(error),
121120
}
122121
}
@@ -189,7 +188,7 @@ impl MediaRecorder {
189188

190189
ffmpeg_command
191190
.args(["-f", "hls"])
192-
.args(["-hls_time", "5", "-hls_playlist_type", "vod"])
191+
.args(["-hls_time", "3", "-hls_playlist_type", "vod"])
193192
.args(["-hls_flags", "independent_segments"])
194193
.args(["-master_pl_name", "master.m3u8"])
195194
.args(["-hls_segment_type", "mpegts"])
@@ -200,19 +199,13 @@ impl MediaRecorder {
200199
.args(["-pix_fmt", "yuv420p", "-tune", "zerolatency"])
201200
.args(["-vsync", "1", "-force_key_frames", "expr:gte(t,n_forced*3)"])
202201
.args(["-movflags", "frag_keyframe+empty_moov"])
203-
.args([
204-
"-vf",
205-
&format!("fps={fps},scale=in_range=full:out_range=limited"),
206-
]);
202+
.args(["-vf", &format!("fps={fps},scale=in_range=full:out_range=limited")]);
207203

208204
if self.audio_enabled {
209205
ffmpeg_command
210206
// audio
211207
.args(["-codec:a", "aac", "-b:a", "128k", "-async", "1"])
212-
.args([
213-
"-af",
214-
"aresample=async=1:min_hard_comp=0.100000:first_pts=0",
215-
]);
208+
.args(["-af", "aresample=async=1:min_hard_comp=0.100000:first_pts=0"]);
216209
} else {
217210
ffmpeg_command.args(["-an"]);
218211
}
@@ -222,8 +215,7 @@ impl MediaRecorder {
222215
tracing::trace!("Starting FFmpeg process...");
223216

224217
let (ffmpeg_child, ffmpeg_stdin) = self
225-
.start_ffmpeg_process(ffmpeg_command)
226-
.await
218+
.start_ffmpeg_process(ffmpeg_command).await
227219
.map_err(|e| e.to_string())?;
228220
tracing::trace!("Ffmpeg process started");
229221

@@ -298,7 +290,7 @@ impl MediaRecorder {
298290

299291
async fn start_ffmpeg_process(
300292
&self,
301-
cmd: Command,
293+
cmd: Command
302294
) -> Result<(Child, ChildStdin), std::io::Error> {
303295
let mut video_process = start_recording_process(cmd).await.map_err(|e| {
304296
tracing::error!("Failed to start video recording process: {}", e);
@@ -325,7 +317,7 @@ pub fn enumerate_audio_devices() -> Vec<String> {
325317

326318
#[tracing::instrument]
327319
async fn start_recording_process(
328-
mut cmd: Command,
320+
mut cmd: Command
329321
) -> Result<tokio::process::Child, std::io::Error> {
330322
let mut process = cmd.stdin(Stdio::piped()).stderr(Stdio::piped()).spawn()?;
331323

@@ -345,7 +337,7 @@ async fn start_recording_process(
345337
#[tracing::instrument]
346338
async fn wait_for_start_times(
347339
audio_start_time: &Mutex<Option<Instant>>,
348-
video_start_time: &Mutex<Option<Instant>>,
340+
video_start_time: &Mutex<Option<Instant>>
349341
) -> (Instant, Instant) {
350342
loop {
351343
let audio_start_locked = audio_start_time.lock().await;
@@ -370,7 +362,7 @@ pub enum TimeOffsetTarget {
370362
#[tracing::instrument]
371363
async fn create_time_offset_args(
372364
audio_start_time: &Mutex<Option<Instant>>,
373-
video_start_time: &Mutex<Option<Instant>>,
365+
video_start_time: &Mutex<Option<Instant>>
374366
) -> Option<(TimeOffsetTarget, Vec<String>)> {
375367
let (audio_start, video_start) = wait_for_start_times(audio_start_time, video_start_time).await;
376368
let duration_difference = if audio_start > video_start {

0 commit comments

Comments
 (0)