Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: FFmpeg errors

Richie McIlroy662691a57718
diff --git a/apps/desktop-solid/src-tauri/src/ffmpeg.rs b/apps/desktop-solid/src-tauri/src/ffmpeg.rs
index e48b6f14a..4d863dad9 100644
--- a/apps/desktop-solid/src-tauri/src/ffmpeg.rs
+++ b/apps/desktop-solid/src-tauri/src/ffmpeg.rs
@@ -27,8 +27,6 @@ impl FFmpegProcess {
pub fn spawn(mut command: Command) -> Self {
let mut cmd = command
.stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .stderr(Stdio::piped())
.spawn()
.unwrap_or_else(|e| {
println!("Failed to start FFmpeg: {}", e);
@@ -48,49 +46,9 @@ impl FFmpegProcess {
self.ffmpeg_stdin.write_all(data)
}
- pub fn stop(&mut self) -> io::Result<()> {
- self.ffmpeg_stdin.flush()?;
- println!("Flushed FFmpeg stdin");
-
- // Send the quit command
- self.ffmpeg_stdin.write_all(b"q")?;
- println!("Sent quit command to FFmpeg");
-
- self.cmd.wait();
- println!("FFmpeg exited");
-
- // Wait for the process to exit
- let timeout = std::time::Duration::from_secs(5);
- match self.wait_with_timeout(timeout)? {
- Some(status) => {
- println!("FFmpeg exited with status: {}", status);
- Ok(())
- }
- None => {
- println!("FFmpeg did not exit within the timeout period. Attempting to terminate.");
- self.cmd.kill()?;
-
- // Wait a bit more to see if the process terminates after kill
- std::thread::sleep(std::time::Duration::from_secs(1));
-
- match self.cmd.try_wait()? {
- Some(status) => {
- println!("FFmpeg terminated with status: {}", status);
- Ok(())
- }
- None => {
- println!("FFmpeg still running after kill attempt. Forcing termination.");
- self.cmd.kill()?;
- Err(
- io::Error::new(
- io::ErrorKind::TimedOut,
- "FFmpeg did not exit even after kill attempt"
- )
- )
- }
- }
- }
- }
+ pub fn stop(&mut self) {
+ self.ffmpeg_stdin.write_all(b"q").ok();
+ println!("Sent stop command to FFmpeg");
}
pub fn wait(&mut self) -> std::io::Result<std::process::ExitStatus> {
diff --git a/apps/desktop-solid/src-tauri/src/video_renderer.rs b/apps/desktop-solid/src-tauri/src/video_renderer.rs
index 57b765c89..f9889d803 100644
--- a/apps/desktop-solid/src-tauri/src/video_renderer.rs
+++ b/apps/desktop-solid/src-tauri/src/video_renderer.rs
@@ -288,13 +288,13 @@ pub async fn render_video(options: RenderOptions) -> Result<PathBuf> {
}
Err(mpsc::RecvError) => {
println!("All frames sent to FFmpeg");
- ffmpeg_process.ffmpeg_stdin.flush().unwrap();
- ffmpeg_process.ffmpeg_stdin.write_all(b"q").unwrap();
- ffmpeg_process.wait().unwrap();
break;
}
}
}
+
+ println!("Stopping FFmpeg process...");
+ ffmpeg_process.stop();
});
let mut screen_command = Command::new(&ffmpeg_binary_path_str);
diff --git a/apps/desktop-solid/src/routes/index.tsx b/apps/desktop-solid/src/routes/index.tsx
index bc3543fa4..1815781e3 100644
--- a/apps/desktop-solid/src/routes/index.tsx
+++ b/apps/desktop-solid/src/routes/index.tsx
@@ -29,12 +29,12 @@ async function testRender() {
[settings.webcamPosition.x / 100, settings.webcamPosition.y / 100],
{
border_radius: settings.webcamStyle.borderRadius,
- shadow_color: [0, 0, 0, 0.5], // Assuming shadow is "rgba(0, 0, 0, 0.5)"
- shadow_blur: 5, // You may want to add this to your settings
- shadow_offset: [2, 2], // You may want to add this to your settings
+ shadow_color: [0, 0, 0, 0.5],
+ shadow_blur: 5,
+ shadow_offset: [2, 2],
},
[settings.videoOutputSize.width, settings.videoOutputSize.height],
- { Color: [0, 0, 0, 1] } // Assuming videoBackground is "#000000"
+ { Color: [0, 0, 0, 1] }
);
console.log(`Video rendered successfully: ${outputFilePath}`);
} catch (error) {
@@ -115,14 +115,14 @@ export default function () {
type="button"
class={cx(
"flex-1",
- "display" === options().captureTarget
+ "screen" === options().captureTarget
? "bg-neutral-200"
: "bg-neutral-100"
)}
onClick={() =>
commands.setRecordingOptions({
...options(),
- captureTarget: "display",
+ captureTarget: "screen",
})
}
>
@@ -134,7 +134,7 @@ export default function () {
type="button"
class={cx(
"flex-1",
- options().captureTarget !== "display"
+ options().captureTarget !== "screen"
? "bg-neutral-200"
: "bg-neutral-100"
)}
@@ -160,7 +160,7 @@ export default function () {
<Show
when={(() => {
const captureTarget = options().captureTarget;
- if (captureTarget === "display") return;
+ if (captureTarget === "screen") return;
return {
windows: windows.data,