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

Further cleanup

parent 956a87e1
No related branches found
No related tags found
No related merge requests found
...@@ -540,9 +540,9 @@ dependencies = [ ...@@ -540,9 +540,9 @@ dependencies = [
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.5" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]] [[package]]
name = "jobserver" name = "jobserver"
...@@ -625,7 +625,7 @@ dependencies = [ ...@@ -625,7 +625,7 @@ dependencies = [
[[package]] [[package]]
name = "media-ingestion" name = "media-ingestion"
version = "0.2.0" version = "1.0.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"ffmpeg_api", "ffmpeg_api",
...@@ -1110,11 +1110,12 @@ dependencies = [ ...@@ -1110,11 +1110,12 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.57" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr",
"ryu", "ryu",
"serde", "serde",
] ]
...@@ -1163,9 +1164,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" ...@@ -1163,9 +1164,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "structopt" name = "structopt"
version = "0.3.18" version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33f6461027d7f08a13715659b2948e1602c31a3756aeae9378bfe7518c72e82" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [ dependencies = [
"clap", "clap",
"lazy_static", "lazy_static",
...@@ -1174,9 +1175,9 @@ dependencies = [ ...@@ -1174,9 +1175,9 @@ dependencies = [
[[package]] [[package]]
name = "structopt-derive" name = "structopt-derive"
version = "0.4.11" version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92e775028122a4b3dd55d58f14fc5120289c69bee99df1d117ae30f84b225c9" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [ dependencies = [
"heck 0.3.1", "heck 0.3.1",
"proc-macro-error", "proc-macro-error",
......
...@@ -12,17 +12,17 @@ repository = "https://github.com/justjanne/media-ingestion" ...@@ -12,17 +12,17 @@ repository = "https://github.com/justjanne/media-ingestion"
readme = "README.md" readme = "README.md"
license = "MPL-2.0" license = "MPL-2.0"
edition = "2018" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.32" anyhow = "1.0.98"
fraction = "0.15.3" fraction = "0.15.3"
image = "0.25.6" image = "0.25.6"
serde_json = "1.0.57" serde_json = "1.0.140"
serde = { version = "1.0.116", features = ["derive"] } serde = { version = "1.0.219", features = ["derive"] }
structopt = "0.3.18" structopt = "0.3.26"
ffmpeg_api = { path = "lib/ffmpeg_api" } ffmpeg_api = { path = "lib/ffmpeg_api" }
media_time = { path = "lib/media_time" } media_time = { path = "lib/media_time" }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
name = "ffmpeg_api" name = "ffmpeg_api"
version = "0.1.0" version = "0.1.0"
authors = ["Janne Mareike Koschinski <janne@kuschku.de>"] authors = ["Janne Mareike Koschinski <janne@kuschku.de>"]
edition = "2018" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
name = "media_time" name = "media_time"
version = "0.1.0" version = "0.1.0"
authors = ["Janne Mareike Koschinski <janne@kuschku.de>"] authors = ["Janne Mareike Koschinski <janne@kuschku.de>"]
edition = "2018" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
name = "webvtt" name = "webvtt"
version = "0.1.0" version = "0.1.0"
authors = ["Janne Mareike Koschinski <janne@kuschku.de>"] authors = ["Janne Mareike Koschinski <janne@kuschku.de>"]
edition = "2018" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
#![allow(dead_code)] #![allow(dead_code)]
pub mod spritesheet; pub mod spritesheet;
mod options;
use std::path::Path; use std::path::Path;
use anyhow::format_err; use anyhow::format_err;
use ffmpeg_api::api::*; use ffmpeg_api::api::*;
use ffmpeg_api::enums::*; use ffmpeg_api::enums::*;
use image::ImageFormat as ImageOutputFormat; pub use options::ExtractOptions;
#[allow(clippy::too_many_arguments)]
pub fn extract( pub fn extract(
max_size: u32,
num_horizontal: u32,
num_vertical: u32,
frame_interval: media_time::MediaTime,
input_file: &Path, input_file: &Path,
output_folder: &Path, output_folder: &Path,
format: ImageOutputFormat, options: ExtractOptions,
scaler: SwsScaler, scaler: SwsScaler,
flags: SwsFlags, flags: SwsFlags,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
...@@ -24,15 +22,11 @@ pub fn extract( ...@@ -24,15 +22,11 @@ pub fn extract(
avformat_context.open_input(input_file)?; avformat_context.open_input(input_file)?;
let duration = avformat_context.duration()?; let duration = avformat_context.duration()?;
std::fs::create_dir_all(&output_folder)?; std::fs::create_dir_all(output_folder)?;
let mut spritesheet_manager = spritesheet::SpritesheetManager::new( let mut spritesheet_manager = spritesheet::SpritesheetManager::new(
max_size, options,
num_horizontal,
num_vertical,
frame_interval,
output_folder, output_folder,
"preview", "preview",
format,
); );
let mut stream: AVStream = avformat_context let mut stream: AVStream = avformat_context
......
...@@ -4,6 +4,7 @@ use ffmpeg_api::enums::{SwsFlags, SwsScaler}; ...@@ -4,6 +4,7 @@ use ffmpeg_api::enums::{SwsFlags, SwsScaler};
use image::ImageFormat as ImageOutputFormat; use image::ImageFormat as ImageOutputFormat;
use media_time::MediaTime; use media_time::MediaTime;
use structopt::StructOpt; use structopt::StructOpt;
use media_ingestion::ExtractOptions;
fn parse_scaler(src: &str) -> Result<SwsScaler, String> { fn parse_scaler(src: &str) -> Result<SwsScaler, String> {
match src { match src {
...@@ -62,17 +63,19 @@ fn main() -> anyhow::Result<()> { ...@@ -62,17 +63,19 @@ fn main() -> anyhow::Result<()> {
} }
if let Err(err) = media_ingestion::extract( if let Err(err) = media_ingestion::extract(
options.max_size,
options.num_horizontal,
options.num_vertical,
MediaTime::from_seconds(options.frame_interval),
Path::new(&options.input), Path::new(&options.input),
Path::new(&options.output), Path::new(&options.output),
match options.format.as_str() { ExtractOptions {
max_size: options.max_size,
num_horizontal: options.num_horizontal,
num_vertical: options.num_vertical,
frame_interval: MediaTime::from_seconds(options.frame_interval),
format: match options.format.as_str() {
"jpeg" | "jpg" => ImageOutputFormat::Jpeg, "jpeg" | "jpg" => ImageOutputFormat::Jpeg,
"png" => ImageOutputFormat::Png, "png" => ImageOutputFormat::Png,
"bmp" => ImageOutputFormat::Bmp, "bmp" => ImageOutputFormat::Bmp,
_ => panic!("Unsupported image format: {}", options.format), _ => panic!("Unsupported image format: {}", options.format),
}
}, },
options.scaler, options.scaler,
flags, flags,
......
use image::ImageFormat as ImageOutputFormat;
pub struct ExtractOptions {
pub max_size: u32,
pub num_horizontal: u32,
pub num_vertical: u32,
pub frame_interval: media_time::MediaTime,
pub format: ImageOutputFormat,
}
...@@ -6,6 +6,7 @@ use anyhow::{bail, Error, format_err}; ...@@ -6,6 +6,7 @@ use anyhow::{bail, Error, format_err};
use image::{DynamicImage, ImageFormat as ImageOutputFormat, RgbImage}; use image::{DynamicImage, ImageFormat as ImageOutputFormat, RgbImage};
use media_time::MediaTime; use media_time::MediaTime;
use webvtt::{WebVTTCue, WebVTTFile}; use webvtt::{WebVTTCue, WebVTTFile};
use crate::options::ExtractOptions;
pub enum ImageFormat { pub enum ImageFormat {
Jpeg(i32), Jpeg(i32),
...@@ -31,28 +32,24 @@ pub struct SpritesheetManager { ...@@ -31,28 +32,24 @@ pub struct SpritesheetManager {
impl SpritesheetManager { impl SpritesheetManager {
pub fn new( pub fn new(
max_side: u32, options: ExtractOptions,
num_horizontal: u32,
num_vertical: u32,
frame_interval: MediaTime,
output_path: impl Into<PathBuf>, output_path: impl Into<PathBuf>,
name: impl AsRef<str>, name: impl AsRef<str>,
format: ImageOutputFormat,
) -> SpritesheetManager { ) -> SpritesheetManager {
SpritesheetManager { SpritesheetManager {
num_horizontal, num_horizontal: options.num_horizontal,
num_vertical, num_vertical: options.num_vertical,
max_side, max_side: options.max_size,
sprite_width: 0, sprite_width: 0,
sprite_height: 0, sprite_height: 0,
spritesheet: RgbImage::new(0, 0), spritesheet: RgbImage::new(0, 0),
current_image: 0, current_image: 0,
last_timestamp: MediaTime::from_millis(0), last_timestamp: MediaTime::from_millis(0),
frame_interval, frame_interval: options.frame_interval,
metadata: WebVTTFile::new(), metadata: WebVTTFile::new(),
output_path: output_path.into(), output_path: output_path.into(),
name: String::from(name.as_ref()), name: String::from(name.as_ref()),
format, format: options.format,
initialized: false, initialized: false,
} }
} }
...@@ -184,7 +181,7 @@ impl SpritesheetManager { ...@@ -184,7 +181,7 @@ impl SpritesheetManager {
let new_buffer = self.reinit_buffer(); let new_buffer = self.reinit_buffer();
DynamicImage::ImageRgb8(std::mem::replace(&mut self.spritesheet, new_buffer)) DynamicImage::ImageRgb8(std::mem::replace(&mut self.spritesheet, new_buffer))
.write_to(&mut BufWriter::new(file), self.format.clone()) .write_to(&mut BufWriter::new(file), self.format)
.map_err(|err| format_err!("Could not write spritesheet {}: {}", &name, err))?; .map_err(|err| format_err!("Could not write spritesheet {}: {}", &name, err))?;
Ok(()) Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment