system audio capture via wasapi loopback

This commit is contained in:
2026-05-12 01:39:02 +03:00
parent c95e8067c0
commit 63e41297e9
5 changed files with 392 additions and 12 deletions
+52
View File
@@ -381,6 +381,58 @@ pub fn extract_thumbnails(
Ok(paths)
}
pub fn mux_with_audio(
ffmpeg: &Path,
video: &Path,
audio_pcm: &Path,
sample_rate: u32,
channels: u16,
output: &Path,
) -> Result<()> {
if let Some(parent) = output.parent() {
std::fs::create_dir_all(parent).context("creating output parent dir")?;
}
let mut cmd = Command::new(ffmpeg);
cmd.arg("-y")
.arg("-hide_banner")
.arg("-i")
.arg(video)
.args(["-f", "f32le"])
.args(["-ar", &sample_rate.to_string()])
.args(["-ac", &channels.to_string()])
.arg("-i")
.arg(audio_pcm)
.args(["-c:v", "copy"])
.args(["-c:a", "aac"])
.args(["-b:a", "192k"])
.args(["-shortest"])
.arg(output);
run(&mut cmd, "mux")
}
pub fn concat_pcm(segments: &[PathBuf], output: &Path) -> Result<()> {
use std::io::{Read, Write};
if segments.is_empty() {
bail!("no audio segments to concatenate");
}
if let Some(parent) = output.parent() {
std::fs::create_dir_all(parent).context("creating audio concat parent")?;
}
let mut out = std::fs::File::create(output).context("creating audio concat file")?;
for seg in segments {
let mut f = std::fs::File::open(seg).with_context(|| format!("opening {seg:?}"))?;
let mut buf = vec![0u8; 64 * 1024];
loop {
let n = f.read(&mut buf)?;
if n == 0 {
break;
}
out.write_all(&buf[..n])?;
}
}
Ok(())
}
pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
if segments.is_empty() {
bail!("no segments to concatenate");