use std::path::Path; use std::process; use crate::config::Config; use crate::repository::Repository; pub struct Transcoder { config: Config, repository: Repository, } impl Transcoder { pub fn new(config: Config, repository: Repository) -> Transcoder { return Transcoder{ config: config, repository: repository, } } pub fn start(self) { println!("Starting transcoder..."); // search for files in ingest let ingest_files = self.repository.search_ingest(); for i in ingest_files { // copy the file to the archive self.repository.archive_file(&i); // perform the video transcode 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); } }