From 180e0d71df4a2efacf2bf4cc6c2f0d0f98ce90dd Mon Sep 17 00:00:00 2001 From: ochibani <11yzyv86j@relay.firefox.com> Date: Fri, 21 Jun 2024 03:57:53 +0200 Subject: [PATCH] update gif record --- src/config_management.rs | 12 ++++++------ src/ffmpeg_interface.rs | 24 ++++++++++++++++++++---- src/main.rs | 1 + 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/config_management.rs b/src/config_management.rs index c7c77fe..3f3efb7 100755 --- a/src/config_management.rs +++ b/src/config_management.rs @@ -141,7 +141,7 @@ pub fn set_default_video_bitrate(format: &str) -> bool { "4" => self::set("default", "videobitrate-4", "0"), "5" => self::set("default", "videobitrate-5", "0"), "6" => self::set("default", "videobitrate-6", "0"), - _ => self::set("default", "videobitrate-0", "0"), // Default value + _ => self::set("default", "videobitrate-0", "0"), // Default value (disabled) }; rate } @@ -151,11 +151,11 @@ pub fn set_default_frame(format: &str) -> bool { "0" => self::set("default", "frame-0", "60"), "1" => self::set("default", "frame-1", "60"), "2" => self::set("default", "frame-2", "60"), - "3" => self::set("default", "frame-3", "60"), - "4" => self::set("default", "frame-4", "60"), - "5" => self::set("default", "frame-5", "60"), - "6" => self::set("default", "frame-6", "60"), - _ => self::set("default", "frame-0", "60"), // Default value + "3" => self::set("default", "frame-3", "10"), + "4" => self::set("default", "frame-4", "2"), + "5" => self::set("default", "frame-5", "2"), + "6" => self::set("default", "frame-6", "0"), + _ => self::set("default", "frame-0", "0"), // Default value (disabled) }; rate } diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 598678a..87dd7d5 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -31,6 +31,7 @@ pub struct Ffmpeg { pub command: Entry, pub video_process: Option>>, pub audio_process: Option>>, + pub height: Option, pub saved_filename: Option, pub unbound: Option>, pub window: Window, @@ -221,6 +222,7 @@ impl Ffmpeg { // start recording and return the process id self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap()))); + self.height = Some(height); } else if self.record_video.is_active() && is_wayland() { sleep(Duration::from_secs(self.record_delay.value() as u64)); @@ -336,12 +338,26 @@ impl Ffmpeg { .spawn() .unwrap().wait().unwrap(); } else if !is_wayland() && self.filename.2.active_id().unwrap().as_str() == "gif" { - let mut ffmpeg_command = FfmpegCommand::new(); - ffmpeg_command.input(video_filename.as_str()) + let fps = 100/self.record_frames.value_as_int(); + let scale = self.height.unwrap(); + Command::new("ffmpeg").arg("-i") + .arg(format!("file:{}", video_filename.as_str())) + .arg("-filter_complex") + .arg(format!("fps={},scale={}:-1:flags=lanczos,[0]split[s0][s1]; [s0]palettegen[p]; [s1][p]paletteuse", + fps,scale)) + .args(["-loop", "0"]) + .arg(self.saved_filename.as_ref().unwrap()) + .status() + .unwrap(); + //let mut ffmpeg_command = FfmpegCommand::new(); + /*ffmpeg_command.input(format!("file:{}", video_filename.as_str())) + .filter_complex( + format!("fps={},scale={}:-1:flags=lanczos,[0]split[s0][s1]; [s0]palettegen[p]; [s1][p]paletteuse", + fps,scale) + ) .args(["-loop", "0"]) - .filter_complex("fps=10,[0]split[s0][s1]; [s0]palettegen[p]; [s1][p]paletteuse") .output(self.saved_filename.as_ref().unwrap()) - .overwrite().spawn().unwrap().wait().expect("failed to convert video to gif"); + .overwrite().spawn().unwrap().wait().expect("failed to convert video to gif");*/ if is_audio_record { std::fs::remove_file(audio_filename.clone()).unwrap(); } diff --git a/src/main.rs b/src/main.rs index 9f6358d..8714b8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -618,6 +618,7 @@ pub fn build_ui(application: &Application) { video_process: None, audio_process: None, saved_filename: None, + height: None, unbound: None, window: main_window.clone(), record_delay: delay_spin,