mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
generics
This commit is contained in:
1 parent
20ba337bb4
commit
b3d5bc6f25
2 files changed
+16
-12
No files matched your search
@@ -6,9 +6,9 @@ use std::process::Command;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
|
||||
pub struct Args<'a> {
|
||||
pub input_video_path: &'a Path,
|
||||
pub output_jpg_path: &'a Path,
|
||||
pub struct Args<I: AsRef<Path>, O: AsRef<Path>> {
|
||||
pub input_video_path: I,
|
||||
pub output_jpg_path: O,
|
||||
}
|
||||
|
||||
/// Extract a single JPG frame from a video file, scaled down to fit within
|
||||
@@ -16,17 +16,19 @@ pub struct Args<'a> {
|
||||
///
|
||||
/// Uses `-sseof -1` to seek 1 second before the end of the file, which avoids
|
||||
/// potentially-black first frames.
|
||||
pub fn ffmpeg_video_first_frame_to_jpg_thumbnail(args: Args<'_>) -> AnyhowResult<()> {
|
||||
pub fn ffmpeg_video_first_frame_to_jpg_thumbnail<I: AsRef<Path>, O: AsRef<Path>>(
|
||||
args: Args<I, O>,
|
||||
) -> AnyhowResult<()> {
|
||||
let mut command = Command::new("ffmpeg");
|
||||
|
||||
command
|
||||
.arg("-nostdin")
|
||||
.arg("-y")
|
||||
.arg("-sseof").arg("-1")
|
||||
.arg("-i").arg(args.input_video_path)
|
||||
.arg("-i").arg(args.input_video_path.as_ref())
|
||||
.arg("-vf").arg("scale=320:320:force_original_aspect_ratio=decrease")
|
||||
.arg("-vframes").arg("1")
|
||||
.arg(args.output_jpg_path);
|
||||
.arg(args.output_jpg_path.as_ref());
|
||||
|
||||
info!("Calling ffmpeg (jpg thumbnail)...");
|
||||
|
||||
|
||||
@@ -6,16 +6,18 @@ use std::process::Command;
|
||||
|
||||
use errors::AnyhowResult;
|
||||
|
||||
pub struct Args<'a> {
|
||||
pub input_video_path: &'a Path,
|
||||
pub output_gif_path: &'a Path,
|
||||
pub struct Args<I: AsRef<Path>, O: AsRef<Path>> {
|
||||
pub input_video_path: I,
|
||||
pub output_gif_path: O,
|
||||
}
|
||||
|
||||
/// Extract a short animated GIF preview from a video file.
|
||||
///
|
||||
/// Takes the first 5 seconds, resampled to 10 fps, scaled to 360px wide
|
||||
/// (preserving aspect ratio), with an optimized color palette.
|
||||
pub fn ffmpeg_video_gif_preview(args: Args<'_>) -> AnyhowResult<()> {
|
||||
pub fn ffmpeg_video_gif_preview<I: AsRef<Path>, O: AsRef<Path>>(
|
||||
args: Args<I, O>,
|
||||
) -> AnyhowResult<()> {
|
||||
let mut command = Command::new("ffmpeg");
|
||||
|
||||
command
|
||||
@@ -23,10 +25,10 @@ pub fn ffmpeg_video_gif_preview(args: Args<'_>) -> AnyhowResult<()> {
|
||||
.arg("-y")
|
||||
.arg("-ss").arg("0")
|
||||
.arg("-to").arg("5")
|
||||
.arg("-i").arg(args.input_video_path)
|
||||
.arg("-i").arg(args.input_video_path.as_ref())
|
||||
.arg("-filter_complex")
|
||||
.arg("fps=10,scale=360:-1[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse")
|
||||
.arg(args.output_gif_path);
|
||||
.arg(args.output_gif_path.as_ref());
|
||||
|
||||
info!("Calling ffmpeg (gif preview)...");
|
||||
|
||||
|
||||
Reference in new issue
Block a user