Skip to content

Commit 9315a12

Browse files
committed
[*] update normally
1 parent ede3beb commit 9315a12

File tree

11 files changed

+210
-33
lines changed

11 files changed

+210
-33
lines changed

lib/recorder/examples/recording_5s_demo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3737
// .with_disable_save_file(true)
3838
.with_audio_device_name(Some(default_input.name))
3939
.with_enable_recording_speaker(true)
40+
// .with_convert_input_wav_to_mono(true)
4041
.with_resolution(recorder::Resolution::Original((
4142
screen_infos[0].logical_size.width as u32,
4243
screen_infos[0].logical_size.height as u32,

lib/recorder/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,6 @@ pub struct MergeTracksConfig {
211211
pub fps: FPS,
212212
/// Signal to stop the combining process if requested by user
213213
pub stop_sig: Arc<AtomicBool>,
214+
215+
pub convert_input_wav_to_mono: bool,
214216
}

lib/recorder/src/mp4_ffmpeg.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ pub fn is_ffmpeg_installed() -> bool {
8181
/// Err(e) => eprintln!("Error: {}", e),
8282
/// }
8383
/// ```
84-
// ffmpeg \
85-
// -i input.h264 \
86-
// -i input.wav \
87-
// -i speaker.wav \
88-
// -c:v copy \
89-
// -c:a aac \
90-
// -b:a:0 128k \
91-
// -b:a:1 128k \
92-
// -map 0:v \
93-
// -map 1:a \
94-
// -map 2:a \
95-
// -y output.mp4
9684
pub fn merge_tracks(
9785
config: MergeTracksConfig,
9886
mut progress_cb: impl FnMut(f32),
@@ -131,31 +119,49 @@ pub fn merge_tracks(
131119

132120
cmd.args(&["-c:v", "copy"]);
133121

134-
if config.input_wav_path.is_some() || config.speaker_wav_path.is_some() {
135-
cmd.args(&["-c:a", "aac"]);
136-
}
137-
138-
if config.input_wav_path.is_some() {
139-
cmd.args(&["-b:a:0", "128k"]);
140-
}
141-
142-
if config.speaker_wav_path.is_some() {
143-
cmd.args(&["-b:a:1", "128k"]);
144-
}
145-
146-
cmd.args(&["-map", "0:v"]);
147-
148-
if config.input_wav_path.is_some() {
149-
cmd.args(&["-map", "1:a"]);
150-
}
151-
152-
if config.speaker_wav_path.is_some() {
153-
cmd.args(&["-map", "2:a"]);
122+
if config.input_wav_path.is_some() && config.speaker_wav_path.is_some() {
123+
cmd.args(&[
124+
"-filter_complex",
125+
if config.convert_input_wav_to_mono {
126+
"[1:a]pan=mono|c0=0.5*FL+0.5*FR[a1];[a1][2:a]amix=inputs=2:duration=longest[a]"
127+
} else {
128+
"[1:a][2:a]amix=inputs=2:duration=longest[a]"
129+
},
130+
"-map",
131+
"0:v",
132+
"-map",
133+
"[a]",
134+
"-c:a",
135+
"aac",
136+
"-b:a",
137+
"128k",
138+
]);
139+
} else if config.input_wav_path.is_some() {
140+
if config.convert_input_wav_to_mono {
141+
cmd.args(&[
142+
"-filter_complex",
143+
"[1:a]pan=mono|c0=0.5*FL+0.5*FR[a]",
144+
"-map",
145+
"0:v",
146+
"-map",
147+
"[a]",
148+
"-c:a",
149+
"aac",
150+
"-b:a",
151+
"128k",
152+
]);
153+
} else {
154+
cmd.args(&["-map", "0:v", "-map", "1:a", "-c:a", "aac", "-b:a", "128k"]);
155+
}
156+
} else if config.speaker_wav_path.is_some() {
157+
cmd.args(&["-map", "0:v", "-map", "1:a", "-c:a", "aac", "-b:a", "128k"]);
158+
} else {
159+
unimplemented!();
154160
}
155161

156162
let mut child_process = cmd
157-
.output(config.output_path.display().to_string())
158163
.overwrite()
164+
.output(config.output_path.display().to_string())
159165
.print_command()
160166
.spawn()
161167
.map_err(|e| RecorderError::Ffmpeg(format!("ffmpeg spawn child process failed. {e}")))?;

lib/recorder/src/recorder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ impl RecordingSession {
848848
output_path: tmp_output_file.clone(),
849849
fps: self.config.fps,
850850
stop_sig: self.stop_sig_combine,
851+
convert_input_wav_to_mono: self.config.convert_input_wav_to_mono,
851852
};
852853

853854
let combine_tracks_state = merge_tracks(combine_config, combine_progress_cb)?;

lib/recorder/src/recorder_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ pub struct RecorderConfig {
140140

141141
#[setters(strip_option)]
142142
pub speaker_amplification: Option<Arc<AtomicI32>>,
143+
144+
pub convert_input_wav_to_mono: bool,
143145
}
144146

145147
impl RecorderConfig {
@@ -195,6 +197,7 @@ impl RecorderConfig {
195197
disable_save_file: false,
196198
audio_amplification: None,
197199
speaker_amplification: None,
200+
convert_input_wav_to_mono: false,
198201
}
199202
}
200203

wayshot/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ pub struct Recorder {
128128
#[derivative(Default(value = "true"))]
129129
pub enable_preview: bool,
130130

131+
pub convert_input_wav_to_mono: bool,
132+
131133
#[derivative(Default(value = "fps_default()"))]
132134
pub fps: UIFps,
133135

wayshot/src/logic/recorder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ fn inner_start_recording(ui_weak: Weak<AppWindow>) -> Result<()> {
497497
)
498498
.with_enable_frame_channel_user(true)
499499
.with_enable_preview_mode(all_config.recorder.enable_preview)
500+
.with_convert_input_wav_to_mono(all_config.recorder.convert_input_wav_to_mono)
500501
.with_enable_recording_speaker(all_config.control.enable_desktop_speaker)
501502
.with_include_cursor(all_config.recorder.include_cursor)
502503
.with_remove_cache_files(all_config.recorder.remove_temporary_files)

0 commit comments

Comments
 (0)