@@ -24,12 +24,15 @@ use crate::files::{
2424use crate :: lock:: Lock ;
2525use crate :: logger:: Logger ;
2626use crate :: shell:: Command ;
27- use crate :: { format_one_arg, format_three_args, format_two_args, run_shell_command_with_log} ;
27+ use crate :: {
28+ format_four_args, format_one_arg, format_three_args, format_two_args,
29+ run_shell_command_with_log, ENV_DISPLAY ,
30+ } ;
2831use anyhow:: Error ;
2932use reqwest:: Client ;
30- use std:: fs;
3133use std:: fs:: File ;
3234use std:: path:: { Path , PathBuf } ;
35+ use std:: { env, fs} ;
3336use xz2:: read:: XzDecoder ;
3437
3538pub const FFMPEG_NAME : & str = "ffmpeg" ;
@@ -40,9 +43,8 @@ const FFMPEG_LINUX_RELEASE_URL: &str = "https://github.com/BtbN/FFmpeg-Builds/re
4043const FFMPEG_MACOS_RELEASE_URL : & str = "https://evermeet.cx/ffmpeg/ffmpeg-{}.zip" ;
4144const FFMPEG_RECORD_FRAME_RATE : & str = "30" ;
4245const FFMPEG_RECORD_DESKTOP_WINDOWS_COMMAND : & str = "{} -f gdigrab -i desktop -r {} -q:v 1 -y {}" ;
43- const FFMPEG_RECORD_DESKTOP_LINUX_COMMAND : & str =
44- "{} -f x11grab -i $DISPLAY -r {} -vcodec huffyuv -y {}" ;
45- const FFMPEG_RECORD_DESKTOP_MACOS_COMMAND : & str = "{} -f avfoundation -i $DISPLAY -r {} -y {}" ;
46+ const FFMPEG_RECORD_DESKTOP_LINUX_COMMAND : & str = "{} -f x11grab -i {} -r {} -vcodec huffyuv -y {}" ;
47+ const FFMPEG_RECORD_DESKTOP_MACOS_COMMAND : & str = "{} -f avfoundation -i {} -r {} -y {}" ;
4648const FFMPEG_RECORDING_EXTENSION : & str = "avi" ;
4749const FFMPEG_RECORDING_FOLDER : & str = "recordings" ;
4850
@@ -207,12 +209,23 @@ pub fn record_desktop_with_ffmpeg(
207209 "Recording desktop with {} to {}" ,
208210 FFMPEG_NAME , & recording_name
209211 ) ) ;
210- let command = Command :: new_single ( format_three_args (
211- get_recording_command ( os) ,
212- & path_to_string ( & ffmpeg_path) ,
213- FFMPEG_RECORD_FRAME_RATE ,
214- & recording_name,
215- ) ) ;
212+ let command = if WINDOWS . is ( os) {
213+ Command :: new_single ( format_three_args (
214+ get_recording_command ( os) ,
215+ & path_to_string ( & ffmpeg_path) ,
216+ FFMPEG_RECORD_FRAME_RATE ,
217+ & recording_name,
218+ ) )
219+ } else {
220+ let env_display = env:: var ( ENV_DISPLAY ) . unwrap_or_default ( ) ;
221+ Command :: new_single ( format_four_args (
222+ get_recording_command ( os) ,
223+ & path_to_string ( & ffmpeg_path) ,
224+ & env_display,
225+ FFMPEG_RECORD_FRAME_RATE ,
226+ & recording_name,
227+ ) )
228+ } ;
216229 run_shell_command_with_log ( log, os, command) . unwrap ( ) ;
217230 Ok ( ( ) )
218231}
0 commit comments