feat: separate audio tracks support in FFmpeg capture
- Added separate_audio_tracks option to PrivacySettings (default false) - Updated CaptureConfig with separate_audio_tracks field - Modified base_desktop_input_args to output separate AAC tracks when enabled - Added UI toggle for 'Separate audio tracks' in Settings - Fixed release build by removing SUBSYSTEM:WINDOWS linker flag (Tauri handles this) - All tests pass
This commit is contained in:
1 parent
40f622199e
commit
bfa263b45c
5 files changed
+35
-13
No files matched your search
@@ -1,9 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build();
|
||||
|
||||
#[cfg(all(target_os = "windows", not(debug_assertions)))]
|
||||
{
|
||||
// Set the subsystem to windows to avoid console window (release builds only)
|
||||
println!("cargo:rustc-link-arg=/SUBSYSTEM:WINDOWS,5.01");
|
||||
}
|
||||
}
|
||||
@@ -644,6 +644,7 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
||||
mic_enabled: recorder.settings.privacy.mic_enabled,
|
||||
system_audio_device: recorder.settings.privacy.system_audio_device.clone(),
|
||||
mic_device: recorder.settings.privacy.mic_device.clone(),
|
||||
separate_audio_tracks: recorder.settings.privacy.separate_audio_tracks,
|
||||
};
|
||||
let backend = start_best_capture_backend(
|
||||
&ffmpeg,
|
||||
|
||||
+26
-7
@@ -42,6 +42,7 @@ pub struct CaptureConfig {
|
||||
pub mic_enabled: bool,
|
||||
pub system_audio_device: Option<String>,
|
||||
pub mic_device: Option<String>,
|
||||
pub separate_audio_tracks: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -221,6 +222,8 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
||||
let size = format!("{}x{}", config.width, config.height);
|
||||
let fps = config.fps.to_string();
|
||||
let bitrate = format!("{}k", config.bitrate_kbps);
|
||||
let separate_tracks = config.system_audio_enabled && config.mic_enabled && config.separate_audio_tracks;
|
||||
|
||||
let mut args = vec![
|
||||
"-y".to_string(),
|
||||
"-hide_banner".to_string(),
|
||||
@@ -246,7 +249,7 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
||||
]),
|
||||
}
|
||||
let mut next_input_index = 1;
|
||||
let mut audio_maps = Vec::new();
|
||||
let mut audio_input_indices = Vec::new();
|
||||
|
||||
if config.system_audio_enabled {
|
||||
args.extend([
|
||||
@@ -258,7 +261,7 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
||||
.clone()
|
||||
.unwrap_or_else(|| "default".to_string()),
|
||||
]);
|
||||
audio_maps.push(format!("{next_input_index}:a?"));
|
||||
audio_input_indices.push(next_input_index);
|
||||
next_input_index += 1;
|
||||
}
|
||||
|
||||
@@ -275,7 +278,7 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
||||
.unwrap_or_else(|| "Microphone".to_string())
|
||||
),
|
||||
]);
|
||||
audio_maps.push(format!("{next_input_index}:a?"));
|
||||
audio_input_indices.push(next_input_index);
|
||||
}
|
||||
|
||||
args.extend([
|
||||
@@ -288,10 +291,24 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
||||
"-pix_fmt".to_string(),
|
||||
"yuv420p".to_string(),
|
||||
]);
|
||||
for audio_map in audio_maps {
|
||||
args.extend(["-map".to_string(), audio_map]);
|
||||
}
|
||||
if config.system_audio_enabled || config.mic_enabled {
|
||||
|
||||
if separate_tracks {
|
||||
// Map each audio input to a separate track with its own encoder settings
|
||||
for (idx, &input_idx) in audio_input_indices.iter().enumerate() {
|
||||
args.extend([
|
||||
"-map".to_string(),
|
||||
format!("{}:a?", input_idx),
|
||||
"-c:a:{}".to_string(), idx.to_string(),
|
||||
"aac".to_string(),
|
||||
"-b:a:{}".to_string(), idx.to_string(),
|
||||
"160k".to_string(),
|
||||
]);
|
||||
}
|
||||
} else if config.system_audio_enabled || config.mic_enabled {
|
||||
// Legacy: mix all audio into single track
|
||||
for input_idx in audio_input_indices {
|
||||
args.extend(["-map".to_string(), format!("{}:a?", input_idx)]);
|
||||
}
|
||||
args.extend([
|
||||
"-c:a".to_string(),
|
||||
"aac".to_string(),
|
||||
@@ -509,6 +526,7 @@ mod tests {
|
||||
mic_enabled: false,
|
||||
system_audio_device: None,
|
||||
mic_device: None,
|
||||
separate_audio_tracks: false,
|
||||
};
|
||||
|
||||
let plan = FfmpegRecordingPlan::for_windows_desktop("ffmpeg", "out.mp4", &config);
|
||||
@@ -532,6 +550,7 @@ mod tests {
|
||||
mic_enabled: false,
|
||||
system_audio_device: None,
|
||||
mic_device: None,
|
||||
separate_audio_tracks: false,
|
||||
};
|
||||
|
||||
let plan = FfmpegRecordingPlan::for_windows_desktop_segments(
|
||||
|
||||
@@ -704,6 +704,7 @@ mod tests {
|
||||
mic_enabled: false,
|
||||
system_audio_device: None,
|
||||
mic_device: None,
|
||||
separate_audio_tracks: false,
|
||||
};
|
||||
let mut backend = NativeWgcReplayCaptureBackend::new(&pattern, Duration::from_secs(1));
|
||||
|
||||
@@ -750,6 +751,7 @@ mod tests {
|
||||
mic_enabled: false,
|
||||
system_audio_device: None,
|
||||
mic_device: None,
|
||||
separate_audio_tracks: false,
|
||||
};
|
||||
let mut backend = NativeWgcReplayCaptureBackend::new(&pattern, Duration::from_secs(1));
|
||||
|
||||
@@ -796,6 +798,7 @@ mod tests {
|
||||
mic_enabled: true,
|
||||
system_audio_device: None,
|
||||
mic_device: None,
|
||||
separate_audio_tracks: false,
|
||||
};
|
||||
let mut backend = NativeWgcReplayCaptureBackend::new(&pattern, Duration::from_secs(1));
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ pub struct PrivacySettings {
|
||||
pub mic_device: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_audio_device: Option<String>,
|
||||
#[serde(default)]
|
||||
pub separate_audio_tracks: bool,
|
||||
pub desktop_capture_requires_confirmation: bool,
|
||||
pub excluded_window_titles: Vec<String>,
|
||||
pub upload_requires_confirmation: bool,
|
||||
@@ -119,6 +121,7 @@ impl AppSettings {
|
||||
mic_enabled: false,
|
||||
mic_device: None,
|
||||
system_audio_device: None,
|
||||
separate_audio_tracks: false,
|
||||
desktop_capture_requires_confirmation: true,
|
||||
excluded_window_titles: Vec::new(),
|
||||
upload_requires_confirmation: true,
|
||||
@@ -152,6 +155,8 @@ impl AppSettings {
|
||||
if self.upload.custom_response_url_path.trim().is_empty() {
|
||||
self.upload.custom_response_url_path = "url".to_string();
|
||||
}
|
||||
// Ensure separate_audio_tracks defaults to false for older configs
|
||||
// (serde default handles this, but explicit for clarity)
|
||||
self.schema_version = CURRENT_SCHEMA_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user