Generate mp4 thumbnails
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -15,7 +15,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use crate::data::{Claims, CreateAccountRequest, Token};
|
use crate::data::{Claims, CreateAccountRequest, Token};
|
||||||
use crate::database::{create_user, get_user, user_exists};
|
use crate::database::{create_user, get_user, user_exists};
|
||||||
use crate::files::list_files;
|
use crate::files::list_files;
|
||||||
use crate::video::create_playlist;
|
use crate::video::*;
|
||||||
|
|
||||||
mod data;
|
mod data;
|
||||||
mod database;
|
mod database;
|
||||||
@@ -201,7 +201,13 @@ async fn create_thumbnails() {
|
|||||||
if let Some(ext) = entry.path().extension().and_then(|ext| {
|
if let Some(ext) = entry.path().extension().and_then(|ext| {
|
||||||
ext.to_str().map(|ext| ext.to_lowercase())
|
ext.to_str().map(|ext| ext.to_lowercase())
|
||||||
}) {
|
}) {
|
||||||
ext == "jpg" || ext == "jpeg" || ext == "png"
|
if ext == "mp4" {
|
||||||
|
let thumb = Path::new(thumbnail_directory).join(entry.path().file_name().unwrap());
|
||||||
|
generate_video_thumbnail(entry.path(), &thumb);
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
ext == "jpg" || ext == "jpeg" || ext == "png"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/video.rs
15
src/video.rs
@@ -32,3 +32,18 @@ pub fn create_playlist(video_path: &str, playlist_file: &str) {
|
|||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
println!("Status: {}", String::from_utf8(result.stdout).unwrap())
|
println!("Status: {}", String::from_utf8(result.stdout).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generate_video_thumbnail(path: &Path, destination: &Path) {
|
||||||
|
Command::new("ffmpeg")
|
||||||
|
.arg("-ss")
|
||||||
|
.arg("3")
|
||||||
|
.arg("-i")
|
||||||
|
.arg(path.to_str().unwrap())
|
||||||
|
.arg("-vframes")
|
||||||
|
.arg("1")
|
||||||
|
.arg("-f")
|
||||||
|
.arg("image2")
|
||||||
|
.arg(destination)
|
||||||
|
.output()
|
||||||
|
.expect("Failure to create video frame");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user