Guard system audio by FFmpeg capability
This commit is contained in:
1 parent
6e47f69141
commit
3e6a5695ee
3 files changed
+40
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
use clipforge::capture::{
|
use clipforge::capture::{
|
||||||
ffmpeg_is_available, find_ffmpeg_executable, CaptureBackend, CaptureConfig, CaptureSource,
|
ffmpeg_is_available, ffmpeg_supports_input_device, find_ffmpeg_executable, CaptureBackend,
|
||||||
EncoderPreference, FfmpegReplayCaptureBackend,
|
CaptureConfig, CaptureSource, EncoderPreference, FfmpegReplayCaptureBackend,
|
||||||
};
|
};
|
||||||
use clipforge::database::ClipDatabase;
|
use clipforge::database::ClipDatabase;
|
||||||
use clipforge::game_detection::{default_profiles, detect_game};
|
use clipforge::game_detection::{default_profiles, detect_game};
|
||||||
@@ -64,6 +64,7 @@ struct DesktopStatus {
|
|||||||
library_root: String,
|
library_root: String,
|
||||||
ffmpeg_available: bool,
|
ffmpeg_available: bool,
|
||||||
ffmpeg_path: Option<String>,
|
ffmpeg_path: Option<String>,
|
||||||
|
system_audio_available: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -348,6 +349,7 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
let segment_duration = Duration::from_secs(5);
|
let segment_duration = Duration::from_secs(5);
|
||||||
let segment_pattern = buffer_dir.join("segment-%05d.mp4");
|
let segment_pattern = buffer_dir.join("segment-%05d.mp4");
|
||||||
|
|
||||||
|
let system_audio_enabled = ffmpeg_supports_input_device(&ffmpeg, "wasapi");
|
||||||
let config = CaptureConfig {
|
let config = CaptureConfig {
|
||||||
source: CaptureSource::Desktop,
|
source: CaptureSource::Desktop,
|
||||||
width: recorder.settings.quality.width,
|
width: recorder.settings.quality.width,
|
||||||
@@ -355,7 +357,7 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
fps: recorder.settings.quality.fps,
|
fps: recorder.settings.quality.fps,
|
||||||
bitrate_kbps: recorder.settings.quality.bitrate_kbps,
|
bitrate_kbps: recorder.settings.quality.bitrate_kbps,
|
||||||
encoder: EncoderPreference::HardwareH264,
|
encoder: EncoderPreference::HardwareH264,
|
||||||
system_audio_enabled: true,
|
system_audio_enabled,
|
||||||
mic_enabled: recorder.settings.privacy.mic_enabled,
|
mic_enabled: recorder.settings.privacy.mic_enabled,
|
||||||
system_audio_device: None,
|
system_audio_device: None,
|
||||||
mic_device: None,
|
mic_device: None,
|
||||||
@@ -788,6 +790,9 @@ fn status_from_recorder(recorder: &RecorderService, capture: Option<&ActiveCaptu
|
|||||||
library_root: recorder.paths.clip_root.display().to_string(),
|
library_root: recorder.paths.clip_root.display().to_string(),
|
||||||
ffmpeg_available: ffmpeg_is_available(),
|
ffmpeg_available: ffmpeg_is_available(),
|
||||||
ffmpeg_path: find_ffmpeg_executable().map(|path| path.display().to_string()),
|
ffmpeg_path: find_ffmpeg_executable().map(|path| path.display().to_string()),
|
||||||
|
system_audio_available: find_ffmpeg_executable()
|
||||||
|
.map(|path| ffmpeg_supports_input_device(&path, "wasapi"))
|
||||||
|
.unwrap_or(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,24 @@ pub fn find_ffmpeg_executable() -> Option<PathBuf> {
|
|||||||
pub fn ffmpeg_is_available() -> bool {
|
pub fn ffmpeg_is_available() -> bool {
|
||||||
find_ffmpeg_executable().is_some()
|
find_ffmpeg_executable().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ffmpeg_supports_input_device(executable: &std::path::Path, device: &str) -> bool {
|
||||||
|
let Ok(output) = Command::new(executable)
|
||||||
|
.args(["-hide_banner", "-devices"])
|
||||||
|
.output()
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let combined = format!(
|
||||||
|
"{}\n{}",
|
||||||
|
String::from_utf8_lossy(&output.stdout),
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
combined
|
||||||
|
.lines()
|
||||||
|
.any(|line| line.contains('D') && line.split_whitespace().any(|part| part == device))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct FfmpegRecordingPlan {
|
pub struct FfmpegRecordingPlan {
|
||||||
pub executable: PathBuf,
|
pub executable: PathBuf,
|
||||||
@@ -466,4 +484,12 @@ mod tests {
|
|||||||
assert!(plan.args.contains(&"segment".to_string()));
|
assert!(plan.args.contains(&"segment".to_string()));
|
||||||
assert!(plan.args.contains(&"segment-%05d.mp4".to_string()));
|
assert!(plan.args.contains(&"segment-%05d.mp4".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn device_parser_ignores_unknown_executable() {
|
||||||
|
assert!(!ffmpeg_supports_input_device(
|
||||||
|
PathBuf::from("definitely-missing-ffmpeg.exe").as_path(),
|
||||||
|
"wasapi"
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-1
@@ -48,6 +48,7 @@ type DesktopStatus = {
|
|||||||
library_root: string;
|
library_root: string;
|
||||||
ffmpeg_available: boolean;
|
ffmpeg_available: boolean;
|
||||||
ffmpeg_path: string | null;
|
ffmpeg_path: string | null;
|
||||||
|
system_audio_available: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClipDto = {
|
type ClipDto = {
|
||||||
@@ -75,6 +76,7 @@ type AppState = {
|
|||||||
capturePath: string | null;
|
capturePath: string | null;
|
||||||
ffmpegAvailable: boolean;
|
ffmpegAvailable: boolean;
|
||||||
ffmpegPath: string | null;
|
ffmpegPath: string | null;
|
||||||
|
systemAudioAvailable: boolean;
|
||||||
micEnabled: boolean;
|
micEnabled: boolean;
|
||||||
autoUpload: boolean;
|
autoUpload: boolean;
|
||||||
uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful";
|
uploadProvider: "catbox" | "litterbox" | "custom_http" | "lustful";
|
||||||
@@ -110,6 +112,7 @@ const state: AppState = {
|
|||||||
capturePath: null,
|
capturePath: null,
|
||||||
ffmpegAvailable: false,
|
ffmpegAvailable: false,
|
||||||
ffmpegPath: null,
|
ffmpegPath: null,
|
||||||
|
systemAudioAvailable: false,
|
||||||
micEnabled: false,
|
micEnabled: false,
|
||||||
autoUpload: false,
|
autoUpload: false,
|
||||||
uploadProvider: "catbox",
|
uploadProvider: "catbox",
|
||||||
@@ -370,7 +373,8 @@ function renderRecordingView() {
|
|||||||
</article>
|
</article>
|
||||||
<article class="settings-panel">
|
<article class="settings-panel">
|
||||||
<p class="eyebrow">Audio</p>
|
<p class="eyebrow">Audio</p>
|
||||||
<h2>System audio on</h2>
|
<h2>${state.systemAudioAvailable ? "System audio ready" : "System audio unavailable"}</h2>
|
||||||
|
<p class="muted">${state.systemAudioAvailable ? "FFmpeg reports WASAPI input support." : "This FFmpeg build does not expose WASAPI; video recording still works."}</p>
|
||||||
<label class="toggle"><input type="checkbox" ${state.micEnabled ? "checked" : ""} data-action="toggle-mic" /> Mic capture</label>
|
<label class="toggle"><input type="checkbox" ${state.micEnabled ? "checked" : ""} data-action="toggle-mic" /> Mic capture</label>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
@@ -607,6 +611,7 @@ function applyDesktopStatus(status: DesktopStatus) {
|
|||||||
state.capturePath = status.capture_path;
|
state.capturePath = status.capture_path;
|
||||||
state.ffmpegAvailable = status.ffmpeg_available;
|
state.ffmpegAvailable = status.ffmpeg_available;
|
||||||
state.ffmpegPath = status.ffmpeg_path;
|
state.ffmpegPath = status.ffmpeg_path;
|
||||||
|
state.systemAudioAvailable = status.system_audio_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function trimSelectedClip() {
|
async function trimSelectedClip() {
|
||||||
|
|||||||
Reference in new issue
Block a user