update gif record

This commit is contained in:
ochibani 2024-06-19 00:11:26 +02:00
parent b4e6b6393e
commit 06d964adab
No known key found for this signature in database
GPG Key ID: 2C6B61CE0C704ED4
8 changed files with 134 additions and 52 deletions

View File

@ -7,18 +7,18 @@
<property name="logo-icon-name">blue-recorder</property>
<property name="modal">True</property>
</object>
<object class="GtkAdjustment" id="adjustment-delay">
<object class="GtkAdjustment" id="adjustment_delay">
<property name="upper">10</property>
<property name="step-increment">1</property>
<property name="page-increment">2</property>
</object>
<object class="GtkAdjustment" id="adjustment-frames">
<object class="GtkAdjustment" id="adjustment_frames">
<property name="lower">0</property>
<property name="upper">240</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment-bitrate">
<object class="GtkAdjustment" id="adjustment_bitrate">
<property name="lower">0</property>
<property name="upper">50000</property>
<property name="step-increment">1</property>
@ -434,7 +434,7 @@
<property name="max-width-chars">2</property>
<property name="width-chars">2</property>
<property name="text">number</property>
<property name="adjustment">adjustment-frames</property>
<property name="adjustment">adjustment_frames</property>
<property name="has-tooltip">True</property>
</object>
</child>
@ -457,7 +457,7 @@
<property name="max-width-chars">2</property>
<property name="width-chars">2</property>
<property name="text">number</property>
<property name="adjustment">adjustment-delay</property>
<property name="adjustment">adjustment_delay</property>
<property name="climb-rate">1</property>
<property name="has-tooltip">True</property>
<layout>
@ -467,7 +467,7 @@
</object>
</child>
<child>
<object class="GtkSeparator" id="delay-separator">
<object class="GtkSeparator" id="delay_separator">
<property name="visible">True</property>
<property name="opacity">0.0</property>
<layout>
@ -477,7 +477,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="bitrate_label">
<object class="GtkLabel" id="video_bitrate_label">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">label</property>
@ -488,13 +488,13 @@
</object>
</child>
<child>
<object class="GtkSpinButton" id="bitrate">
<object class="GtkSpinButton" id="video_bitrate">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="max-width-chars">2</property>
<property name="width-chars">2</property>
<property name="text">number</property>
<property name="adjustment">adjustment-bitrate</property>
<property name="adjustment">adjustment_bitrate</property>
<property name="climb-rate">1</property>
<property name="has-tooltip">True</property>
<layout>

View File

@ -102,8 +102,9 @@ license =
لمزيد تفاصيل راجع رخصة جنو العمومية. إن لم تكن حصلت على نسخة من رخصة جنو العمومية مع المسجل الأزرق فانظر { license-website }.
# Bitrate label
bitrate = Bitrate:
# Video bitrate label
video-bitrate = B/Video:
# Recording button
record = سجل
@ -146,7 +147,7 @@ format-tooltip = لاختيار صيغة الخَرج
frames-tooltip = عدد الإطارات في الثانية
hide-tooltip = لإخفاء نافذة المسجل الأزرق عند بدء التسجيل
mouse-tooltip = يظهر مؤشر الفأرة عند التسجيل
bitrate-tooltip = Set video bitrate in KB/s
video-bitrate-tooltip = Set video bitrate in KB/s
record-tooltip = يبدأ تسجيل الشاشة
screen-tooltip = يحدد الشاشة ليسجلها
speaker-tooltip = Speakr sound recording

View File

@ -102,8 +102,9 @@ license =
لمزيد تفاصيل راجع رخصة جنو العمومية. إن لم تكن حصلت على نسخة من رخصة جنو العمومية مع المسجل الأزرق فانظر { license-website }.
# Bitrate label
bitrate = Bitrate:
# Video bitrate label
video-bitrate = B/Video:
# Recording button
record = سجل
@ -146,7 +147,7 @@ format-tooltip = لاختيار صيغة الخَرج
frames-tooltip = عدد الإطارات في الثانية
hide-tooltip = لإخفاء نافذة المسجل الأزرق عند بدء التسجيل
mouse-tooltip = يظهر مؤشر الفأرة عند التسجيل
bitrate-tooltip = Set video bitrate in KB/s
video-bitrate-tooltip = Set video bitrate in KB/s
record-tooltip = يبدأ تسجيل الشاشة
screen-tooltip = يحدد الشاشة ليسجلها
speaker-tooltip = Speakr sound recording

View File

@ -99,8 +99,8 @@ license =
Blue Recorder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Blue Recorder. If not, see { license-website }.
# Bitrate label
bitrate = Bitrate:
# Video bitrate label
video-bitrate = B/Video:
# Recording button
record = Record
@ -143,7 +143,7 @@ format-tooltip = Select file format
frames-tooltip = Frames rate
hide-tooltip = Hide window when start recording
mouse-tooltip = Mouse appears in video recording
bitrate-tooltip = Set video bitrate in KB/s
video-bitrate-tooltip = Set video bitrate in KB/s
record-tooltip = Start screen record
screen-tooltip = Select screen to record
speaker-tooltip = Speakr sound recording

View File

@ -99,8 +99,8 @@ license =
Blue Recorder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Blue Recorder. If not, see { license-website }.
# Bitrate label
bitrate = Bitrate:
# Video bitrate label
video-bitrate = B/Video:
# Recording button
record = Record
@ -143,7 +143,7 @@ format-tooltip = Select file format
frames-tooltip = Frames rate
hide-tooltip = Hide window when start recording
mouse-tooltip = Mouse appears in video recording
bitrate-tooltip = Set video bitrate in KB/s
video-bitrate-tooltip = Set video bitrate in KB/s
record-tooltip = Start screen record
screen-tooltip = Select screen to record
speaker-tooltip = Speakr sound recording

View File

@ -28,7 +28,7 @@ pub fn initialize() -> PathBuf {
fn default() {
for format in 0..7 {
set_default_bitrate(&format.to_string());
set_default_video_bitrate(&format.to_string());
set_default_frame(&format.to_string());
}
set("default", "delay", "0");
@ -132,16 +132,16 @@ pub fn folder_icon(folder_chooser_name: Option<&str>) -> &str {
}
}
pub fn set_default_bitrate(format: &str) -> bool {
pub fn set_default_video_bitrate(format: &str) -> bool {
let rate = match format {
"0" => self::set("default", "bitrate-0", "0"),
"1" => self::set("default", "bitrate-1", "0"),
"2" => self::set("default", "bitrate-2", "0"),
"3" => self::set("default", "bitrate-3", "0"),
"4" => self::set("default", "bitrate-4", "0"),
"5" => self::set("default", "bitrate-5", "0"),
"6" => self::set("default", "bitrate-6", "0"),
_ => self::set("default", "bitrate-0", "0"), // Default value
"0" => self::set("default", "videobitrate-0", "0"),
"1" => self::set("default", "videobitrate-1", "0"),
"2" => self::set("default", "videobitrate-2", "0"),
"3" => self::set("default", "videobitrate-3", "0"),
"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
};
rate
}

View File

@ -39,7 +39,7 @@ pub struct Ffmpeg {
pub main_context: gtk::glib::MainContext,
pub temp_video_filename: String,
pub bundle: String,
pub record_bitrate: SpinButton,
pub video_record_bitrate: SpinButton,
}
impl Ffmpeg {
@ -85,7 +85,7 @@ impl Ffmpeg {
}
}
if self.record_video.is_active() && !is_wayland() {
if self.record_video.is_active() && !is_wayland() && self.filename.2.active_id().unwrap().as_str() != "gif" {
let mode = config_management::get("default", "mode");
let format = "x11grab";
let display = format!("{}+{},{}",
@ -127,10 +127,10 @@ impl Ffmpeg {
.input(display);
// Disable bitrate if value is zero
if self.record_bitrate.value() > 0.0 {
if self.video_record_bitrate.value() > 0.0 {
ffmpeg_command.args([
"-b:v",
&format!("{}K", self.record_bitrate.value()),
&format!("{}K", self.video_record_bitrate.value()),
]);
}
@ -155,6 +155,70 @@ impl Ffmpeg {
// sleep for delay
sleep(Duration::from_secs(self.record_delay.value() as u64));
// start recording and return the process id
self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap())));
} else if self.record_video.is_active() && !is_wayland() && self.filename.2.active_id().unwrap().as_str() == "gif" {
let mode = config_management::get("default", "mode");
let format = "x11grab";
let display = format!("{}+{},{}",
std::env::var("DISPLAY").unwrap_or_else(|_| ":0".to_string())
.as_str(),
x,
y
);
let mut ffmpeg_command = FfmpegCommand::new();
// record video with specified width and hight
if self.follow_mouse.is_active() && mode.as_str() == "screen" {
let width = width as f32 * 0.95;
let height = height as f32 * 0.95;
ffmpeg_command.size(width as u32, height as u32);
} else {
ffmpeg_command.size(width.into(), height.into());
}
// if show mouse switch is enabled, draw the mouse to video
if self.record_mouse.is_active() {
ffmpeg_command.args(["-draw_mouse", "1"]);
} else {
ffmpeg_command.args(["-draw_mouse", "0"]);
};
// if follow mouse switch is enabled, follow the mouse
if self.follow_mouse.is_active() {
ffmpeg_command.args(["-follow_mouse", "centered"]);
}
// Disable frame rate if value is zero
if self.record_frames.value() > 0.0 {
ffmpeg_command.args(["-framerate", &self.record_frames.value().to_string()]);
}
// Video format && input
ffmpeg_command.format(format)
.input(display);
// Disable bitrate if value is zero
if self.video_record_bitrate.value() > 0.0 {
ffmpeg_command.args([
"-b:v",
&format!("{}K", self.video_record_bitrate.value()),
]);
}
let video_filename = format!(
"{}.temp.without.audio.{}",
self.saved_filename.as_ref().unwrap(),
self.filename.2.active_id().unwrap()
).replace("gif", "mp4");
// Output
ffmpeg_command.arg(video_filename.as_str())
.overwrite();
// sleep for delay
sleep(Duration::from_secs(self.record_delay.value() as u64));
// start recording and return the process id
self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap())));
} else if self.record_video.is_active() && is_wayland() {
@ -231,6 +295,12 @@ impl Ffmpeg {
let video_filename = {
if is_wayland() {
self.temp_video_filename.clone()
} else if !is_wayland() && self.filename.2.active_id().unwrap().as_str() == "gif" {
format!(
"{}.temp.without.audio.{}",
self.saved_filename.as_ref().unwrap(),
self.filename.2.active_id().unwrap()
).replace("gif", "mp4")
} else {
format!(
"{}.temp.without.audio.{}",
@ -252,10 +322,10 @@ impl Ffmpeg {
// convert webm to specified format
let mut ffmpeg_command = FfmpegCommand::new();
ffmpeg_command.input(self.temp_video_filename.as_str());
if self.record_bitrate.value() > 0.0 {
if self.video_record_bitrate.value() > 0.0 {
ffmpeg_command.args([
"-b:v",
&format!("{}K", self.record_bitrate.value()),
&format!("{}K", self.video_record_bitrate.value()),
]);
}
ffmpeg_command.args([
@ -265,6 +335,16 @@ impl Ffmpeg {
]).overwrite()
.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())
.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");
if is_audio_record {
std::fs::remove_file(audio_filename.clone()).unwrap();
}
} else {
let mut move_command = Command::new("mv");
move_command.args([
@ -279,7 +359,7 @@ impl Ffmpeg {
}
// if audio record, then merge video and audio
if is_audio_record {
if is_audio_record && self.filename.2.active_id().unwrap().as_str() != "gif" {
FfmpegCommand::new().input(video_filename.as_str())
.format("ogg")
.input(audio_filename.as_str())

View File

@ -112,8 +112,6 @@ pub fn build_ui(application: &Application) {
let main_window: Window = builder.object("main_window").unwrap();
let mouse_switch: CheckButton = builder.object("mouseswitch").unwrap();
let play_button: Button = builder.object("playbutton").unwrap();
let bitrate_label: Label = builder.object("bitrate_label").unwrap();
let bitrate_spin: SpinButton = builder.object("bitrate").unwrap();
let record_button: Button = builder.object("recordbutton").unwrap();
let record_label: Label = builder.object("record_label").unwrap();
let record_time_label: Label = builder.object("record_time_label").unwrap();
@ -123,6 +121,8 @@ pub fn build_ui(application: &Application) {
let speaker_switch: CheckButton = builder.object("speakerswitch").unwrap();
let stop_button: Button = builder.object("stopbutton").unwrap();
let stop_label: Label = builder.object("stop_label").unwrap();
let video_bitrate_label: Label = builder.object("video_bitrate_label").unwrap();
let video_bitrate_spin: SpinButton = builder.object("video_bitrate").unwrap();
let video_switch: CheckButton = builder.object("videoswitch").unwrap();
let window_grab_button: ToggleButton = builder.object("window_grab_button").unwrap();
let window_grab_icon: Image = builder.object("window_grab_icon").unwrap();
@ -395,7 +395,7 @@ pub fn build_ui(application: &Application) {
.value().unwrap(), None, &mut vec![]).to_string()));
delay_spin.set_tooltip_text(Some(&bundle.format_pattern(bundle.get_message("delay-tooltip").unwrap()
.value().unwrap(), None, &mut vec![]).to_string()));
bitrate_spin.set_tooltip_text(Some(&bundle.format_pattern(bundle.get_message("bitrate-tooltip").unwrap()
video_bitrate_spin.set_tooltip_text(Some(&bundle.format_pattern(bundle.get_message("video-bitrate-tooltip").unwrap()
.value().unwrap(), None, &mut vec![]).to_string()));
frames_spin.set_value(
config_management::get("default",
@ -410,10 +410,10 @@ pub fn build_ui(application: &Application) {
.parse::<f64>()
.unwrap(),
);
bitrate_spin.set_value(
video_bitrate_spin.set_value(
config_management::get("default",
&format!
("bitrate-{}",
("videobitrate-{}",
&format_chooser_combobox.active().unwrap().to_string()))
.parse::<f64>()
.unwrap(),
@ -421,7 +421,7 @@ pub fn build_ui(application: &Application) {
let _format_chooser_combobox = format_chooser_combobox.clone();
let _frames_spin = frames_spin.clone();
let _bitrate_spin = bitrate_spin.clone();
let _video_bitrate_spin = video_bitrate_spin.clone();
format_chooser_combobox.connect_changed(move |_| {
let format_chooser_combobox = _format_chooser_combobox.clone();
if _format_chooser_combobox.active_text().is_some() {
@ -438,10 +438,10 @@ pub fn build_ui(application: &Application) {
.parse::<f64>()
.unwrap(),
);
_bitrate_spin.set_value(
_video_bitrate_spin.set_value(
config_management::get("default",
&format!
("bitrate-{}",
("videobitrate-{}",
&format_chooser_combobox.active().unwrap().to_string()))
.parse::<f64>()
.unwrap(),
@ -464,14 +464,14 @@ pub fn build_ui(application: &Application) {
"delay",
_delay_spin.value().to_string().as_str());
});
let _bitrate_spin = bitrate_spin.to_owned();
let _video_bitrate_spin = video_bitrate_spin.to_owned();
let _format_chooser_combobox = format_chooser_combobox.clone();
bitrate_spin.connect_value_changed(move |_| {
video_bitrate_spin.connect_value_changed(move |_| {
config_management::set("default",
&format!
("bitrate-{}",
("videobitrate-{}",
&_format_chooser_combobox.active().unwrap().to_string()),
_bitrate_spin.value().to_string().as_str());
_video_bitrate_spin.value().to_string().as_str());
});
// Labels
@ -481,7 +481,7 @@ pub fn build_ui(application: &Application) {
.value().unwrap(), None, &mut vec![]).to_string());
delay_label.set_label(&bundle.format_pattern(bundle.get_message("delay").unwrap()
.value().unwrap(), None, &mut vec![]).to_string());
bitrate_label.set_label(&bundle.format_pattern(bundle.get_message("bitrate").unwrap()
video_bitrate_label.set_label(&bundle.format_pattern(bundle.get_message("video-bitrate").unwrap()
.value().unwrap(), None, &mut vec![]).to_string());
audio_source_label.set_label(&bundle.format_pattern(bundle.get_message("audio-source").unwrap()
.value().unwrap(), None, &mut vec![]).to_string());
@ -626,7 +626,7 @@ pub fn build_ui(application: &Application) {
main_context,
temp_video_filename: String::new(),
bundle: bundle_msg,
record_bitrate: bitrate_spin,
video_record_bitrate: video_bitrate_spin,
}));
// Record Button