Move ffmpeg to feature flag

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 1ab447a108
commit 35bef3ee0b
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -4,7 +4,7 @@ readme = "README.md"
license = "Apache-2.0"
authors = ["trivernis <trivernis@protonmail.com>"]
description = "An image thumbnail creation library"
version = "0.2.2"
version = "0.2.3"
edition = "2018"
repository = "https://github.com/Trivernis/thumbnailer"
@ -14,8 +14,12 @@ repository = "https://github.com/Trivernis/thumbnailer"
webp = "0.2.0"
mime = "0.3.16"
rayon = "1.5.1"
ffmpeg-next = "4.4.0"
ffmpeg-next = {version = "4.4.0", optional=true}
tempfile = "3.2.0"
[dependencies.image]
version = "0.23.14"
version = "0.23.14"
[features]
default = ["ffmpeg"]
ffmpeg = ["ffmpeg-next"]

@ -17,6 +17,7 @@ pub enum ThumbError {
NullVideo,
#[cfg(feature = "ffmpeg")]
FFMPEG(ffmpeg_next::Error),
}
@ -28,6 +29,8 @@ impl Display for ThumbError {
ThumbError::Decode => write!(f, "failed to decode image"),
ThumbError::Unsupported(mime) => write!(f, "Unsupported media type {}", mime),
ThumbError::NullVideo => write!(f, "no video data found in file"),
#[cfg(feature = "ffmpeg")]
ThumbError::FFMPEG(e) => write!(f, "ffmpeg error: {}", e),
}
}
@ -38,7 +41,10 @@ impl std::error::Error for ThumbError {
match self {
ThumbError::IO(e) => e.source(),
ThumbError::Image(i) => i.source(),
#[cfg(feature = "ffmpeg")]
ThumbError::FFMPEG(e) => e.source(),
_ => None,
}
}
@ -56,6 +62,7 @@ impl From<image::error::ImageError> for ThumbError {
}
}
#[cfg(feature = "ffmpeg")]
impl From<ffmpeg_next::Error> for ThumbError {
fn from(e: ffmpeg_next::Error) -> Self {
Self::FFMPEG(e)

@ -1,17 +1,21 @@
use crate::error::{ThumbError, ThumbResult};
use crate::formats::image_format::read_image;
use crate::formats::video_format::get_video_frame;
use image::DynamicImage;
use mime::Mime;
use std::io::{BufRead, Seek};
#[cfg(feature = "ffmpeg")]
use crate::formats::video_format::get_video_frame;
pub mod image_format;
#[cfg(feature = "ffmpeg")]
pub mod video_format;
/// Reads the buffer content into an image that can be used for thumbnail generation
pub fn get_base_image<R: BufRead + Seek>(reader: R, mime: Mime) -> ThumbResult<DynamicImage> {
match mime.type_() {
mime::IMAGE => read_image(reader, mime),
#[cfg(feature = "ffmpeg")]
mime::VIDEO => get_video_frame(reader, mime),
_ => Err(ThumbError::Unsupported(mime)),
}

@ -8,7 +8,7 @@ const VIDEO_BYTES: &'static [u8] = include_bytes!("assets/test.mp4");
#[test]
fn it_creates_thumbnails_for_mp4() {
let reader = Cursor::new(VIDEO_BYTES);
create_thumbnails(
let result = create_thumbnails(
reader,
Mime::from_str("video/mp4").unwrap(),
[
@ -16,6 +16,10 @@ fn it_creates_thumbnails_for_mp4() {
ThumbnailSize::Medium,
ThumbnailSize::Large,
],
)
.unwrap();
);
#[cfg(feature = "ffmpeg")]
result.unwrap();
#[cfg(not(feature = "ffmpeg"))]
assert!(result.is_err())
}

Loading…
Cancel
Save