Finally added the ability to transcode videos

This commit is contained in:
Gregory Ballantine 2022-08-31 18:55:22 -04:00
parent a778de5b34
commit 0b6f6fea02
2 changed files with 32 additions and 5 deletions

View File

@ -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 {

View File

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