mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-25 21:11:00 +00:00
parent
36b346e733
commit
82df25694a
1 changed files with 45 additions and 25 deletions
|
@ -20,6 +20,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_REPEAT: i32 = 0;
|
const DEFAULT_REPEAT: i32 = 0;
|
||||||
|
const DEFAULT_SPEED: i32 = 10;
|
||||||
|
|
||||||
/// The gif::Encoder requires a std::io::Write implementation, to which it
|
/// The gif::Encoder requires a std::io::Write implementation, to which it
|
||||||
/// can save the generated gif. This struct is used as a temporary cache, into
|
/// can save the generated gif. This struct is used as a temporary cache, into
|
||||||
|
@ -70,12 +71,14 @@ impl Write for CacheBufferWriter {
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Settings {
|
struct Settings {
|
||||||
repeat: i32,
|
repeat: i32,
|
||||||
|
speed: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Settings {
|
Settings {
|
||||||
repeat: DEFAULT_REPEAT,
|
repeat: DEFAULT_REPEAT,
|
||||||
|
speed: DEFAULT_SPEED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,15 +143,26 @@ impl ObjectSubclass for GifEnc {
|
||||||
impl ObjectImpl for GifEnc {
|
impl ObjectImpl for GifEnc {
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
fn properties() -> &'static [glib::ParamSpec] {
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||||
vec![glib::ParamSpec::new_int(
|
vec![
|
||||||
"repeat",
|
glib::ParamSpec::new_int(
|
||||||
"Repeat",
|
"repeat",
|
||||||
"Repeat (-1 to loop forever, 0 .. n finite repetitions)",
|
"Repeat",
|
||||||
-1,
|
"Repeat (-1 to loop forever, 0 .. n finite repetitions)",
|
||||||
std::u16::MAX as i32,
|
-1,
|
||||||
DEFAULT_REPEAT,
|
std::u16::MAX as i32,
|
||||||
glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY,
|
DEFAULT_REPEAT,
|
||||||
)]
|
glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY,
|
||||||
|
),
|
||||||
|
glib::ParamSpec::new_int(
|
||||||
|
"speed",
|
||||||
|
"Speed",
|
||||||
|
"Speed (1 .. 30; higher value yields faster encoding)",
|
||||||
|
1,
|
||||||
|
30,
|
||||||
|
DEFAULT_SPEED,
|
||||||
|
glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY,
|
||||||
|
),
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
PROPERTIES.as_ref()
|
PROPERTIES.as_ref()
|
||||||
|
@ -166,6 +180,10 @@ impl ObjectImpl for GifEnc {
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
settings.repeat = value.get().expect("type checked upstream");
|
settings.repeat = value.get().expect("type checked upstream");
|
||||||
}
|
}
|
||||||
|
"speed" => {
|
||||||
|
let mut settings = self.settings.lock().unwrap();
|
||||||
|
settings.speed = value.get().expect("type checked upstream");
|
||||||
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,6 +194,10 @@ impl ObjectImpl for GifEnc {
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
settings.repeat.to_value()
|
settings.repeat.to_value()
|
||||||
}
|
}
|
||||||
|
"speed" => {
|
||||||
|
let settings = self.settings.lock().unwrap();
|
||||||
|
settings.speed.to_value()
|
||||||
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,24 +368,22 @@ impl VideoEncoderImpl for GifEnc {
|
||||||
gst::FlowError::Error
|
gst::FlowError::Error
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let settings = self.settings.lock().unwrap();
|
||||||
|
|
||||||
let mut raw_frame = tightly_packed_framebuffer(&in_frame);
|
let mut raw_frame = tightly_packed_framebuffer(&in_frame);
|
||||||
let mut gif_frame = match in_frame.info().format() {
|
let mut gif_frame = match in_frame.info().format() {
|
||||||
gst_video::VideoFormat::Rgb => {
|
gst_video::VideoFormat::Rgb => gif::Frame::from_rgb_speed(
|
||||||
gif::Frame::from_rgb_speed(
|
frame_width as u16,
|
||||||
frame_width as u16,
|
frame_height as u16,
|
||||||
frame_height as u16,
|
&raw_frame,
|
||||||
&raw_frame,
|
settings.speed,
|
||||||
10, // TODO: Export option for this quality/speed tradeoff
|
),
|
||||||
)
|
gst_video::VideoFormat::Rgba => gif::Frame::from_rgba_speed(
|
||||||
}
|
frame_width as u16,
|
||||||
gst_video::VideoFormat::Rgba => {
|
frame_height as u16,
|
||||||
gif::Frame::from_rgba_speed(
|
&mut raw_frame,
|
||||||
frame_width as u16,
|
settings.speed,
|
||||||
frame_height as u16,
|
),
|
||||||
&mut raw_frame,
|
|
||||||
10, //TODO: Export option for this quality/speed tradeoff
|
|
||||||
)
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue