fix: changed some config behaviour.
This commit is contained in:
parent
ea076dcf72
commit
fe55238b10
6 changed files with 39 additions and 52 deletions
|
@ -2,7 +2,6 @@
|
||||||
input_path = "/data/input"
|
input_path = "/data/input"
|
||||||
output_path = "/data/output"
|
output_path = "/data/output"
|
||||||
include = [ 'mp4', 'avi', 'mkv' ] # file extensions to include
|
include = [ 'mp4', 'avi', 'mkv' ] # file extensions to include
|
||||||
keep_file_structure = true # e.g. /data/input/foo/bar.mp4 -> /data/output/foo/bar.webm
|
|
||||||
|
|
||||||
[files.cleanup]
|
[files.cleanup]
|
||||||
enabled = true # do cleanup?
|
enabled = true # do cleanup?
|
||||||
|
@ -10,13 +9,14 @@ original_cleanup_behavior = "delete" # delete, archive or keep
|
||||||
|
|
||||||
[files.cleanup.archive]
|
[files.cleanup.archive]
|
||||||
path = "/data/archive"
|
path = "/data/archive"
|
||||||
keep_file_structure = true # e.g. /data/input/foo/bar.mp4 -> /data/archive/foo/bar.mp4
|
|
||||||
|
|
||||||
[files.cleanup.delete]
|
[files.cleanup.delete]
|
||||||
remove_empty_directories = true # if folder is empty after deleting file, delete folder
|
remove_empty_directories = true # if folder is empty after deleting file, delete folder
|
||||||
|
|
||||||
[ffmpeg]
|
[ffmpeg]
|
||||||
path = "/usr/bin/ffmpeg" # path to ffmpeg executable
|
path = "/usr/bin/ffmpeg" # path to ffmpeg executable
|
||||||
|
allow_overwrite = false # allow overwriting existing files
|
||||||
|
extra_args = []
|
||||||
|
|
||||||
[ffmpeg.process]
|
[ffmpeg.process]
|
||||||
niceness = 10 # 0 = highest priority
|
niceness = 10 # 0 = highest priority
|
||||||
|
|
|
@ -14,6 +14,10 @@ impl ConfigFFmpeg {
|
||||||
audio_codec: self.output.audio.codec.clone(),
|
audio_codec: self.output.audio.codec.clone(),
|
||||||
audio_bitrate: if self.output.audio.bitrate > 0 { Some(self.output.audio.bitrate) } else { None },
|
audio_bitrate: if self.output.audio.bitrate > 0 { Some(self.output.audio.bitrate) } else { None },
|
||||||
|
|
||||||
|
overwrite: if self.overwrite.is_some() { Some(self.overwrite.unwrap()) } else { None },
|
||||||
|
|
||||||
|
extra_args: if self.extra_args.is_some() { self.extra_args.clone().unwrap() } else { Vec::new() },
|
||||||
|
|
||||||
threads: if self.process.threads.unwrap_or(0) > 0 { Some(self.process.threads.unwrap_or(0)) } else { None },
|
threads: if self.process.threads.unwrap_or(0) > 0 { Some(self.process.threads.unwrap_or(0)) } else { None },
|
||||||
niceness: if self.process.niceness.unwrap_or(0) > 0 { Some(self.process.niceness.unwrap_or(0)) } else { None },
|
niceness: if self.process.niceness.unwrap_or(0) > 0 { Some(self.process.niceness.unwrap_or(0)) } else { None },
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ pub enum ConfigFilesCleanupOriginalBehavior {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ConfigFilesCleanupArchive {
|
pub struct ConfigFilesCleanupArchive {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub keep_file_structure: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -31,11 +30,10 @@ pub struct ConfigFilesCleanup {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ConfigFiles {
|
pub struct ConfigFiles {
|
||||||
pub keep_file_structure: bool,
|
|
||||||
pub input_path: String,
|
pub input_path: String,
|
||||||
pub output_path: String,
|
pub output_path: String,
|
||||||
pub include: Vec<String>,
|
pub include: Vec<String>,
|
||||||
pub cleanup: ConfigFilesCleanup,
|
pub cleanup: Option<ConfigFilesCleanup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -67,6 +65,8 @@ pub struct ConfigFFmpegOutput {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ConfigFFmpeg {
|
pub struct ConfigFFmpeg {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
pub extra_args: Option<Vec<String>>,
|
||||||
|
pub overwrite: Option<bool>,
|
||||||
pub process: ConfigFFmpegProcess,
|
pub process: ConfigFFmpegProcess,
|
||||||
pub output: ConfigFFmpegOutput,
|
pub output: ConfigFFmpegOutput,
|
||||||
}
|
}
|
||||||
|
@ -83,24 +83,15 @@ impl Config {
|
||||||
Config {
|
Config {
|
||||||
debug: None,
|
debug: None,
|
||||||
files: ConfigFiles {
|
files: ConfigFiles {
|
||||||
keep_file_structure: false,
|
|
||||||
input_path: String::from("/data/input"),
|
input_path: String::from("/data/input"),
|
||||||
output_path: String::from("/data/output"),
|
output_path: String::from("/data/output"),
|
||||||
include: Vec::new(),
|
include: Vec::new(),
|
||||||
cleanup: ConfigFilesCleanup {
|
cleanup: None
|
||||||
enabled: false,
|
|
||||||
original_cleanup_behavior: ConfigFilesCleanupOriginalBehavior::delete,
|
|
||||||
archive: ConfigFilesCleanupArchive {
|
|
||||||
path: String::from("/data/archive"),
|
|
||||||
keep_file_structure: false,
|
|
||||||
},
|
|
||||||
delete: ConfigFilesCleanupDelete {
|
|
||||||
remove_empty_directories: false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
ffmpeg: ConfigFFmpeg {
|
ffmpeg: ConfigFFmpeg {
|
||||||
path: String::from("/usr/bin/ffmpeg"),
|
path: String::from("/usr/bin/ffmpeg"),
|
||||||
|
extra_args: None,
|
||||||
|
overwrite: None,
|
||||||
process: ConfigFFmpegProcess {
|
process: ConfigFFmpegProcess {
|
||||||
threads: Some(0),
|
threads: Some(0),
|
||||||
niceness: Some(0),
|
niceness: Some(0),
|
||||||
|
|
|
@ -11,6 +11,10 @@ pub struct FFmpegCommandOptions {
|
||||||
pub audio_codec: String,
|
pub audio_codec: String,
|
||||||
pub audio_bitrate: Option<u32>,
|
pub audio_bitrate: Option<u32>,
|
||||||
|
|
||||||
|
pub overwrite: Option<bool>,
|
||||||
|
|
||||||
|
pub extra_args: Vec<String>,
|
||||||
|
|
||||||
pub threads: Option<u8>,
|
pub threads: Option<u8>,
|
||||||
pub niceness: Option<u8>
|
pub niceness: Option<u8>
|
||||||
}
|
}
|
||||||
|
@ -50,39 +54,22 @@ impl FFmpegCommandOptions {
|
||||||
args.push(niceness.to_string());
|
args.push(niceness.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(allow_overwrite) = self.overwrite {
|
||||||
|
if allow_overwrite {
|
||||||
|
args.push("-y".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args.append(&mut self.extra_args.clone());
|
||||||
args.push(self.output.clone());
|
args.push(self.output.clone());
|
||||||
|
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_command(program: &str, options: &FFmpegCommandOptions) -> Command {
|
|
||||||
let mut command = Command::new(program);
|
|
||||||
command.arg("-i").arg(&options.input);
|
|
||||||
command.arg("-c:v").arg(&options.video_codec);
|
|
||||||
command.arg("-c:a").arg(&options.audio_codec);
|
|
||||||
|
|
||||||
if let Some(bitrate) = options.video_bitrate {
|
|
||||||
command.arg("-b:v").arg(bitrate.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(crf) = options.video_crf {
|
|
||||||
command.arg("-crf").arg(crf.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(bitrate) = options.audio_bitrate {
|
|
||||||
command.arg("-b:a").arg(bitrate.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(threads) = options.threads {
|
|
||||||
command.arg("-threads").arg(threads.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(niceness) = options.niceness {
|
|
||||||
command.arg("-threads").arg(niceness.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
command.arg(&options.output);
|
|
||||||
|
|
||||||
|
pub fn to_command(&self, ffmpeg_path: &str) -> Command {
|
||||||
|
let mut command = Command::new(ffmpeg_path);
|
||||||
|
command.args(self.to_args());
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ fn main() {
|
||||||
let mut success_count = 0;
|
let mut success_count = 0;
|
||||||
|
|
||||||
for file in input_files {
|
for file in input_files {
|
||||||
let mut fail = |job: &TranscodeJob, remarks: &str| {
|
let fail = |job: &TranscodeJob, remarks: &str| {
|
||||||
error!("Failed to process file {}: {}", job.input, remarks);
|
error!("Failed to process file {}: {}", job.input, remarks);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,10 +46,15 @@ fn main() {
|
||||||
output_path.to_str().unwrap()
|
output_path.to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// check if overwriting
|
||||||
if job.check_if_exists() {
|
if job.check_if_exists() {
|
||||||
info!("Skipping conversion for {} to {} as the output file already exists.", job.input, job.output);
|
if config.ffmpeg.overwrite.unwrap_or(false) {
|
||||||
|
info!("Overwriting file {}.", job.input);
|
||||||
|
} else {
|
||||||
|
info!("Skipping file {} as it already exists.", job.input);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info!("Processing file {}.", job.input);
|
info!("Processing file {}.", job.input);
|
||||||
let mut child = match job.run(&config.ffmpeg) {
|
let mut child = match job.run(&config.ffmpeg) {
|
||||||
|
|
|
@ -17,10 +17,9 @@ impl TranscodeJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_command(&self, ffmpeg_config: &ConfigFFmpeg) -> Command {
|
pub fn build_command(&self, ffmpeg_config: &ConfigFFmpeg) -> Command {
|
||||||
let options = ffmpeg_config.build_command_options(&self.input, &self.output);
|
ffmpeg_config
|
||||||
let mut command = Command::new("ffmpeg");
|
.build_command_options(&self.input, &self.output)
|
||||||
command.args(options.to_args());
|
.to_command(&ffmpeg_config.path)
|
||||||
command
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_if_exists(&self) -> bool {
|
pub fn check_if_exists(&self) -> bool {
|
||||||
|
@ -28,6 +27,7 @@ impl TranscodeJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, error::Error> {
|
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, error::Error> {
|
||||||
|
debug!("Running job: {:#?}", &self.input);
|
||||||
let mut command = self.build_command(ffmpeg_config);
|
let mut command = self.build_command(ffmpeg_config);
|
||||||
match command.spawn() {
|
match command.spawn() {
|
||||||
Ok(child) => Ok(child),
|
Ok(child) => Ok(child),
|
||||||
|
|
Loading…
Reference in a new issue