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
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@ pub fn extract(
frame_interval: MediaTime,
input_file: &Path,
output_folder: &Path,
format: impl AsRef<str>,
scaler: SwsScaler,
) -> Result<(), Error> {
let mut avformat_context = AVFormatContext::new()
.map_err(|error| format_err!("Could not open video input: {}", error))?;
......@@ -32,6 +34,7 @@ pub fn extract(
frame_interval,
spritesheet_path,
"preview",
format
);
let mut stream: AVStream = avformat_context
......@@ -117,7 +120,7 @@ pub fn extract(
format_err!("Could not init output frame: {}", error)
})?;
scale_context
.reinit(&frame, &output_frame, SwsScaler::FastBilinear)
.reinit(&frame, &output_frame, scaler)
.map_err(|error| {
format_err!("Could not reinit scale context: {}", error)
})?;
......
......@@ -18,7 +18,8 @@ pub struct SpritesheetManager {
frame_interval: MediaTime,
metadata: WebVTTFile,
output_path: PathBuf,
name: std::string::String,
name: String,
format: String,
initialized: bool,
}
......@@ -30,6 +31,7 @@ impl SpritesheetManager {
frame_interval: MediaTime,
output_path: impl Into<PathBuf>,
name: impl AsRef<str>,
format: impl AsRef<str>
) -> SpritesheetManager {
SpritesheetManager {
num_horizontal,
......@@ -43,7 +45,8 @@ impl SpritesheetManager {
frame_interval,
metadata: WebVTTFile::new(),
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,
}
}
......@@ -135,9 +138,10 @@ impl SpritesheetManager {
self.last_timestamp,
timestamp,
format!(
"{}_{}.jpg#xywh={},{},{},{}",
"{}_{}.{}#xywh={},{},{},{}",
self.name,
self.spritesheet_index(self.current_image - 1),
self.format,
self.x(self.current_image - 1),
self.y(self.current_image - 1),
self.sprite_width,
......@@ -149,9 +153,10 @@ impl SpritesheetManager {
fn save_spritesheet(&mut self) -> Result<(), Error> {
self.spritesheet
.save(self.output_path.join(format!(
"{}_{}.jpg",
"{}_{}.{}",
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))?;
self.reinit_buffer();
......
......@@ -10,6 +10,24 @@ use failure::Error;
use structopt::StructOpt;
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)]
#[structopt(author, about)]
......@@ -24,6 +42,10 @@ struct Options {
num_vertical: u32,
#[structopt(long = "max-size", default_value = "160")]
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> {
......@@ -36,6 +58,8 @@ fn main() -> Result<(), Error> {
MediaTime::from_seconds(options.frame_interval),
Path::new(&options.input),
Path::new(&options.output),
options.format,
options.scaler,
)?;
Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment