Compare commits
No commits in common. "5cd6ffa6d3ab883b5833a5abdc0f21fe191da0ee" and "38547bb175a22c1b13fe618246c55b9567c428c3" have entirely different histories.
5cd6ffa6d3
...
38547bb175
5
.gitignore
vendored
5
.gitignore
vendored
@ -14,3 +14,8 @@ Cargo.lock
|
|||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
30
.woodpecker.yml
Normal file
30
.woodpecker.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
pipeline:
|
||||||
|
test_build:
|
||||||
|
image: rust:1.63
|
||||||
|
commands:
|
||||||
|
- "cargo build"
|
||||||
|
|
||||||
|
build_release:
|
||||||
|
image: rust:1.63
|
||||||
|
commands:
|
||||||
|
- "cargo install cargo-deb cargo-generate-rpm"
|
||||||
|
- "cargo build --release"
|
||||||
|
- "cargo deb"
|
||||||
|
- "cargo generate-rpm"
|
||||||
|
- "mv target/release/adept target/release/adept-${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
gitea_release:
|
||||||
|
image: plugins/gitea-release
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: gitea_api_key
|
||||||
|
base_url: https://git.metaunix.net
|
||||||
|
files:
|
||||||
|
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
- "target/debian/adept*.deb"
|
||||||
|
- "target/generate-rpm/adept*.rpm"
|
||||||
|
title: "${CI_COMMIT_TAG}"
|
||||||
|
when:
|
||||||
|
event: tag
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "adept"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
toml = "0.5"
|
||||||
|
serde = "1.0"
|
||||||
|
serde_derive = "1.0"
|
||||||
|
shellexpand = "2.1"
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) 2022 Bit Goblin
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
34
src/config.rs
Normal file
34
src/config.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub transcoder: Transcoder,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn new(config_path: &str) -> Config {
|
||||||
|
let resolved_path = shellexpand::tilde(config_path);
|
||||||
|
let config_text = fs::read_to_string(&*resolved_path).unwrap();
|
||||||
|
let c: Config = toml::from_str(&config_text).unwrap();
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_repository(&self) -> String {
|
||||||
|
let resolved_path = shellexpand::tilde(&self.transcoder.repository);
|
||||||
|
return String::from(&*resolved_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Transcoder {
|
||||||
|
pub repository: String,
|
||||||
|
pub interval: u16,
|
||||||
|
pub video_format: String,
|
||||||
|
pub video_codec: String,
|
||||||
|
pub video_profile: String,
|
||||||
|
pub video_resolution: String,
|
||||||
|
pub video_framerate: u8,
|
||||||
|
pub video_color: String,
|
||||||
|
pub audio_codec: String,
|
||||||
|
}
|
17
src/main.rs
Normal file
17
src/main.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
use config::Config;
|
||||||
|
use repository::Repository;
|
||||||
|
use transcoder::Transcoder;
|
||||||
|
|
||||||
|
mod config;
|
||||||
|
mod repository;
|
||||||
|
mod transcoder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// create and initialize our config and repository objects
|
||||||
|
let c: Config = Config::new("~/.config/adept.toml");
|
||||||
|
let r: Repository = Repository::new(&c.get_repository());
|
||||||
|
|
||||||
|
// create and start the video transcoder object
|
||||||
|
let t: Transcoder = Transcoder::new(c, r);
|
||||||
|
t.start();
|
||||||
|
}
|
87
src/repository.rs
Normal file
87
src/repository.rs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub struct Repository {
|
||||||
|
pub base_dir: String,
|
||||||
|
pub ingest_dir: String,
|
||||||
|
pub archive_dir: String,
|
||||||
|
pub output_dir: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Repository {
|
||||||
|
pub fn new(base_path: &str) -> Repository {
|
||||||
|
// create the base directory path
|
||||||
|
create_directory(base_path);
|
||||||
|
|
||||||
|
// create the needed sub-directories
|
||||||
|
let ingest_path = Path::new(base_path).join("ingest");
|
||||||
|
create_directory(ingest_path.to_str().unwrap());
|
||||||
|
let archive_path = Path::new(base_path).join("archive");
|
||||||
|
create_directory(archive_path.to_str().unwrap());
|
||||||
|
let output_path = Path::new(base_path).join("output");
|
||||||
|
create_directory(output_path.to_str().unwrap());
|
||||||
|
|
||||||
|
return Repository {
|
||||||
|
base_dir: String::from(base_path),
|
||||||
|
ingest_dir: String::from(ingest_path.to_str().unwrap()),
|
||||||
|
archive_dir: String::from(archive_path.to_str().unwrap()),
|
||||||
|
output_dir: String::from(output_path.to_str().unwrap()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn search_ingest(&self) -> Vec<String> {
|
||||||
|
// read file entries from ingest
|
||||||
|
let files = fs::read_dir(&self.ingest_dir).unwrap();
|
||||||
|
|
||||||
|
// create vec object and loop through entries to find what we want
|
||||||
|
let mut ingest_files: Vec<String> = vec![];
|
||||||
|
for f in files {
|
||||||
|
let f = f.unwrap();
|
||||||
|
let path = f.path();
|
||||||
|
if path.is_file() {
|
||||||
|
let file_path = path.file_name().unwrap().to_str();
|
||||||
|
ingest_files.push(String::from(file_path.unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ingest_files;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn archive_file(&self, file: &str) {
|
||||||
|
let ingest_file = Path::new(&self.ingest_dir).join(file);
|
||||||
|
let archive_file = Path::new(&self.archive_dir).join(file);
|
||||||
|
|
||||||
|
match fs::copy(&ingest_file, &archive_file) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Archiving video file {}.", ingest_file.to_str().unwrap());
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Error archiving file {}: {}", ingest_file.to_str().unwrap(), e);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cleanup_file(&self, file: &str) {
|
||||||
|
let ingest_file = Path::new(&self.ingest_dir).join(file);
|
||||||
|
fs::remove_file(&ingest_file)
|
||||||
|
.expect("File deletion failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_directory(path: &str) {
|
||||||
|
let d = Path::new(path);
|
||||||
|
if d.is_dir() {
|
||||||
|
println!("Directory {} already exists.", path);
|
||||||
|
} else {
|
||||||
|
match fs::create_dir(path) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Creating directory {}.", path);
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Error creating {}: {}", path, e);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
src/transcoder.rs
Normal file
61
src/transcoder.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user