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

make format and scaler configurable

parent 4d72c4f9
Branches
Tags
No related merge requests found
...@@ -15,6 +15,8 @@ pub fn extract( ...@@ -15,6 +15,8 @@ pub fn extract(
frame_interval: MediaTime, frame_interval: MediaTime,
input_file: &Path, input_file: &Path,
output_folder: &Path, output_folder: &Path,
format: impl AsRef<str>,
scaler: SwsScaler,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut avformat_context = AVFormatContext::new() let mut avformat_context = AVFormatContext::new()
.map_err(|error| format_err!("Could not open video input: {}", error))?; .map_err(|error| format_err!("Could not open video input: {}", error))?;
...@@ -32,6 +34,7 @@ pub fn extract( ...@@ -32,6 +34,7 @@ pub fn extract(
frame_interval, frame_interval,
spritesheet_path, spritesheet_path,
"preview", "preview",
format
); );
let mut stream: AVStream = avformat_context let mut stream: AVStream = avformat_context
...@@ -117,7 +120,7 @@ pub fn extract( ...@@ -117,7 +120,7 @@ pub fn extract(
format_err!("Could not init output frame: {}", error) format_err!("Could not init output frame: {}", error)
})?; })?;
scale_context scale_context
.reinit(&frame, &output_frame, SwsScaler::FastBilinear) .reinit(&frame, &output_frame, scaler)
.map_err(|error| { .map_err(|error| {
format_err!("Could not reinit scale context: {}", error) format_err!("Could not reinit scale context: {}", error)
})?; })?;
......
...@@ -18,7 +18,8 @@ pub struct SpritesheetManager { ...@@ -18,7 +18,8 @@ pub struct SpritesheetManager {
frame_interval: MediaTime, frame_interval: MediaTime,
metadata: WebVTTFile, metadata: WebVTTFile,
output_path: PathBuf, output_path: PathBuf,
name: std::string::String, name: String,
format: String,
initialized: bool, initialized: bool,
} }
...@@ -30,6 +31,7 @@ impl SpritesheetManager { ...@@ -30,6 +31,7 @@ impl SpritesheetManager {
frame_interval: MediaTime, frame_interval: MediaTime,
output_path: impl Into<PathBuf>, output_path: impl Into<PathBuf>,
name: impl AsRef<str>, name: impl AsRef<str>,
format: impl AsRef<str>
) -> SpritesheetManager { ) -> SpritesheetManager {
SpritesheetManager { SpritesheetManager {
num_horizontal, num_horizontal,
...@@ -43,7 +45,8 @@ impl SpritesheetManager { ...@@ -43,7 +45,8 @@ impl SpritesheetManager {
frame_interval, frame_interval,
metadata: WebVTTFile::new(), metadata: WebVTTFile::new(),
output_path: output_path.into(), output_path: output_path.into(),
name: std::string::String::from(name.as_ref()), name: String::from(name.as_ref()),
format: String::from(format.as_ref()),
initialized: false, initialized: false,
} }
} }
...@@ -135,9 +138,10 @@ impl SpritesheetManager { ...@@ -135,9 +138,10 @@ impl SpritesheetManager {
self.last_timestamp, self.last_timestamp,
timestamp, timestamp,
format!( format!(
"{}_{}.jpg#xywh={},{},{},{}", "{}_{}.{}#xywh={},{},{},{}",
self.name, self.name,
self.spritesheet_index(self.current_image - 1), self.spritesheet_index(self.current_image - 1),
self.format,
self.x(self.current_image - 1), self.x(self.current_image - 1),
self.y(self.current_image - 1), self.y(self.current_image - 1),
self.sprite_width, self.sprite_width,
...@@ -149,9 +153,10 @@ impl SpritesheetManager { ...@@ -149,9 +153,10 @@ impl SpritesheetManager {
fn save_spritesheet(&mut self) -> Result<(), Error> { fn save_spritesheet(&mut self) -> Result<(), Error> {
self.spritesheet self.spritesheet
.save(self.output_path.join(format!( .save(self.output_path.join(format!(
"{}_{}.jpg", "{}_{}.{}",
self.name, self.name,
self.spritesheet_index(self.current_image) self.spritesheet_index(self.current_image),
self.format
))) )))
.map_err(|error| format_err!("Could not write spritesheet: {}", error))?; .map_err(|error| format_err!("Could not write spritesheet: {}", error))?;
self.reinit_buffer(); self.reinit_buffer();
......
...@@ -10,6 +10,24 @@ use failure::Error; ...@@ -10,6 +10,24 @@ use failure::Error;
use structopt::StructOpt; use structopt::StructOpt;
use crate::util::media_time::MediaTime; use crate::util::media_time::MediaTime;
use crate::ffmpeg_api::enums::SwsScaler;
fn parse_scaler(src: &str) -> Result<SwsScaler, String> {
match src {
"fast_bilinear" => Ok(SwsScaler::FastBilinear),
"bilinear" => Ok(SwsScaler::Bilinear),
"bicubic" => Ok(SwsScaler::Bicubic),
"x" => Ok(SwsScaler::X),
"point" => Ok(SwsScaler::Point),
"area" => Ok(SwsScaler::Area),
"bicublin" => Ok(SwsScaler::Bicublin),
"gauss" => Ok(SwsScaler::Gauss),
"sinc" => Ok(SwsScaler::Sinc),
"lanczos" => Ok(SwsScaler::Lanczos),
"spline" => Ok(SwsScaler::Spline),
_ => Err(format!("Invalid scaler: {}", src))
}
}
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
#[structopt(author, about)] #[structopt(author, about)]
...@@ -24,6 +42,10 @@ struct Options { ...@@ -24,6 +42,10 @@ struct Options {
num_vertical: u32, num_vertical: u32,
#[structopt(long = "max-size", default_value = "160")] #[structopt(long = "max-size", default_value = "160")]
max_size: u32, max_size: u32,
#[structopt(long = "format", default_value = "jpg")]
format: String,
#[structopt(long = "scaler", default_value = "bilinear", parse(try_from_str = parse_scaler))]
scaler: SwsScaler,
} }
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
...@@ -36,6 +58,8 @@ fn main() -> Result<(), Error> { ...@@ -36,6 +58,8 @@ fn main() -> Result<(), Error> {
MediaTime::from_seconds(options.frame_interval), MediaTime::from_seconds(options.frame_interval),
Path::new(&options.input), Path::new(&options.input),
Path::new(&options.output), Path::new(&options.output),
options.format,
options.scaler,
)?; )?;
Ok(()) Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment