diff options
Diffstat (limited to 'transcoder')
-rw-r--r-- | transcoder/Cargo.toml | 6 | ||||
-rw-r--r-- | transcoder/src/bin/reproduce_decode_error.rs | 11 | ||||
-rw-r--r-- | transcoder/src/image.rs | 16 |
3 files changed, 26 insertions, 7 deletions
diff --git a/transcoder/Cargo.toml b/transcoder/Cargo.toml index ac6fe24..e39b07c 100644 --- a/transcoder/Cargo.toml +++ b/transcoder/Cargo.toml @@ -6,8 +6,10 @@ edition = "2021" [dependencies] jellycommon = { path = "../common" } jellybase = { path = "../base" } -log = "0.4.20" -image = { git = "https://github.com/image-rs/image", features = ["avif-decoder"] } +log = { workspace = true } +image = { git = "https://github.com/image-rs/image", features = [ + "avif-decoder", +] } anyhow = "1.0.75" rgb = "0.8.36" rav1e = { version = "0.6.6", default-features = false, features = [ diff --git a/transcoder/src/bin/reproduce_decode_error.rs b/transcoder/src/bin/reproduce_decode_error.rs new file mode 100644 index 0000000..84fa6fd --- /dev/null +++ b/transcoder/src/bin/reproduce_decode_error.rs @@ -0,0 +1,11 @@ +use jellytranscoder::image::transcode; + +fn main() { + transcode( + jellycommon::AssetLocation::Cache(std::env::args().nth(2).unwrap().into()), + 1.0, + 1, + 1, + ) + .unwrap(); +} diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index c28ef2b..6da1be7 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -1,6 +1,8 @@ +use anyhow::Context; +use image::{imageops::FilterType, ImageFormat}; use jellybase::{cache_file, AssetLocationExt}; use jellycommon::AssetLocation; -use log::info; +use log::{debug, info}; use rgb::FromSlice; use std::{ fs::File, @@ -22,14 +24,18 @@ pub fn transcode( .path(); if !path.exists() { info!("encoding {path:?} (speed={speed}, quality={quality}, width={width})"); - let reader = image::io::Reader::new(BufReader::new(File::open(original_path)?)) - .with_guessed_format()?; - let original = reader.decode()?.to_rgba8(); + // TODO shouldn't be neccessary with guessed format. + let file = BufReader::new(File::open(&original_path).context("opening source")?); + let mut reader = image::io::Reader::new(file); + reader.set_format(ImageFormat::Avif); + let reader = reader.with_guessed_format().context("guessing format")?; + debug!("guessed format (or fallback): {:?}", reader.format()); + let original = reader.decode().context("decoding image")?.to_rgba8(); let image = image::imageops::resize( &original, width as u32, width as u32 * original.height() / original.width(), - image::imageops::FilterType::Lanczos3, + FilterType::Lanczos3, ); let pixels = image.to_vec(); let encoded = ravif::Encoder::new() |