Generate mp4 thumbnails

This commit is contained in:
Cameron Cordes
2020-07-16 21:24:10 -04:00
parent a49619c98c
commit 7dbd93cedc
2 changed files with 23 additions and 2 deletions

View File

@@ -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())
}) { }) {
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" ext == "jpg" || ext == "jpeg" || ext == "png"
}
} else { } else {
false false
} }

View File

@@ -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");
}