Skip to content
Snippets Groups Projects
Commit b1905755 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

allow setting minimal distance

parent e6a0429f
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ pub(crate) mod spritesheet;
use crate::ffmpeg_api::enums::*;
use crate::ffmpeg_api::api::*;
use image::{ImageBuffer};
use crate::media_time::MediaTime;
fn main() -> Result<(), std::io::Error> {
let mut before = std::time::SystemTime::now();
......@@ -25,6 +25,7 @@ fn main() -> Result<(), std::io::Error> {
let mut spritesheet_manager = spritesheet::SpritesheetManager::new(
160,
5, 5,
MediaTime::from_seconds(10),
output,
);
......@@ -89,6 +90,7 @@ fn main() -> Result<(), std::io::Error> {
println!("Reading Time: {:#?}", before.elapsed().unwrap());
before = std::time::SystemTime::now();
if spritesheet_manager.fulfils_frame_interval(stream.timestamp(frame.pts())) {
if !spritesheet_manager.initialized() {
spritesheet_manager.initialize(frame.width() as u32, frame.height() as u32);
output_frame.init(
......@@ -114,7 +116,7 @@ fn main() -> Result<(), std::io::Error> {
spritesheet_manager.add_image(
stream.timestamp(frame.pts()),
ImageBuffer::from_raw(
image::ImageBuffer::from_raw(
output_frame.width() as u32,
output_frame.height() as u32,
output_frame.data(0).to_vec(),
......@@ -128,6 +130,7 @@ fn main() -> Result<(), std::io::Error> {
}
}
}
}
spritesheet_manager.end_frame(stream.duration());
spritesheet_manager.save();
......
use fraction::Fraction;
#[derive(Copy,Clone,Debug)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct MediaTime(time::Duration);
impl MediaTime {
......@@ -41,3 +41,19 @@ impl std::fmt::Display for MediaTime {
}
}
}
impl std::ops::Add for MediaTime {
type Output = Self;
fn add(self, other: Self) -> Self {
Self(self.0 + other.0)
}
}
impl std::ops::Sub for MediaTime {
type Output = Self;
fn sub(self, other: Self) -> Self {
Self(self.0 - other.0)
}
}
\ No newline at end of file
......@@ -11,13 +11,14 @@ pub struct SpritesheetManager {
spritesheet: RgbImage,
current_image: u32,
last_timestamp: MediaTime,
frame_interval: MediaTime,
metadata: WebVTTFile,
output_path: std::string::String,
initialized: bool,
}
impl SpritesheetManager {
pub fn new<T: AsRef<str>>(max_side: u32, num_horizontal: u32, num_vertical: u32, output_path: T) -> SpritesheetManager {
pub fn new<T: AsRef<str>>(max_side: u32, num_horizontal: u32, num_vertical: u32, frame_interval: MediaTime, output_path: T) -> SpritesheetManager {
SpritesheetManager {
num_horizontal,
num_vertical,
......@@ -27,6 +28,7 @@ impl SpritesheetManager {
spritesheet: ImageBuffer::new(0, 0),
current_image: 0,
last_timestamp: MediaTime::from_millis(0),
frame_interval,
metadata: WebVTTFile::new(),
output_path: std::string::String::from(output_path.as_ref()),
initialized: false,
......@@ -82,6 +84,10 @@ impl SpritesheetManager {
index * self.sprite_height
}
pub fn fulfils_frame_interval(&self, timestamp: MediaTime) -> bool {
timestamp - self.last_timestamp > self.frame_interval
}
pub fn add_image(&mut self, timestamp: MediaTime, image: RgbImage) {
if image.width() != self.sprite_width || image.height() != self.sprite_height {
panic!(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment