From 0b6f6fea02201bb0ee818c67984d41ab692c71b9 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 31 Aug 2022 18:55:22 -0400 Subject: [PATCH] Finally added the ability to transcode videos --- src/repository.rs | 8 ++++---- src/transcoder.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/repository.rs b/src/repository.rs index e02cc57..1c92636 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -2,10 +2,10 @@ use std::fs; use std::path::Path; pub struct Repository { - base_dir: String, - ingest_dir: String, - archive_dir: String, - output_dir: String, + pub base_dir: String, + pub ingest_dir: String, + pub archive_dir: String, + pub output_dir: String, } impl Repository { diff --git a/src/transcoder.rs b/src/transcoder.rs index a6396e8..a6a17d1 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -1,3 +1,6 @@ +use std::path::Path; +use std::process; + use crate::config::Config; use crate::repository::Repository; @@ -25,10 +28,34 @@ impl Transcoder { self.repository.archive_file(&i); // perform the video transcode - // TODO - self.transcode(i); + self.transcode(&i); // remove the source file self.repository.cleanup_file(&i); } } + + fn transcode(&self, file: &str) { + let ingest_file = Path::new(&self.repository.ingest_dir).join(file); + let output_file = Path::new(&self.repository.output_dir).join(file); + + let cmd_output = process::Command::new("/usr/bin/ffmpeg") + .arg("-i") .arg(&*ingest_file.to_string_lossy()) + .arg("-y") + .arg("-f") .arg(&self.config.transcoder.video_format) + .arg("-c:v") .arg(&self.config.transcoder.video_codec) + .arg("-s") .arg(&self.config.transcoder.video_resolution) + .arg("-r") .arg(format!("{}", self.config.transcoder.video_framerate)) + .arg("-vf") .arg(format!("'format={}'", &self.config.transcoder.video_color)) + .arg("-profile:v").arg(&self.config.transcoder.video_profile) + .arg("-c:a") .arg(&self.config.transcoder.audio_codec) + .arg(&*output_file.to_string_lossy()) + .output() + .expect("Failed to execute command"); + + //assert!(cmd_output.status.success()); + + let results_raw = &String::from_utf8_lossy(&cmd_output.stderr); + println!("{}", results_raw); + } }