more flexible options
This commit is contained in:
parent
389e4beead
commit
d4b52afff0
38
client.sh
38
client.sh
@ -5,7 +5,7 @@ set -euo pipefail
|
|||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
base_url="$1"
|
base_url="$1"
|
||||||
version="0.1.0"
|
version="0.2.0"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
sleep 30
|
sleep 30
|
||||||
@ -43,26 +43,28 @@ while true; do
|
|||||||
|
|
||||||
echo "Starting Encode"
|
echo "Starting Encode"
|
||||||
|
|
||||||
target_bitrate=`echo $job | jq -r .description.options.mode.VBR`
|
aomenco=`echo $job | jq -r .description.options.aomenc`
|
||||||
width=`echo $job | jq -r .description.options.resolution.width`
|
aomenco=${aomenco//[^a-zA-Z0-9_\- =]/}
|
||||||
height=`echo $job | jq -r .description.options.resolution.height`
|
ffmpego=`echo $job | jq -r .description.options.ffmpeg`
|
||||||
color_depth=`echo $job | jq -r .description.options.color_depth`
|
ffmpego=${ffmpego//[^a-zA-Z0-9_\- =:]/}
|
||||||
kf_min_dist=`echo $job | jq -r .description.options.kf_min_dist`
|
|
||||||
kf_max_dist=`echo $job | jq -r .description.options.kf_max_dist`
|
|
||||||
|
|
||||||
speed=`echo $job | jq -r .description.options.speed`
|
two_pass=`echo $job | jq -r .description.options.two_pass`
|
||||||
|
|
||||||
ffmpeg -nostats -hide_banner -loglevel warning \
|
echo $two_pass
|
||||||
-i "$input" -vf scale=$width:$height -f yuv4mpegpipe - | aomenc - --lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 \
|
|
||||||
--target-bitrate=$target_bitrate --width="$width" --height="$height" --bit-depth=$color_depth --kf-min-dist=$kf_min_dist --kf-max-dist=$kf_max_dist \
|
|
||||||
--cpu-used=$speed \
|
|
||||||
--pass=1 --passes=2 --fpf="$input.$target_bitrate.$width.$height.$color_depth.fpf" --webm -o "$input.$target_bitrate.$width.$height.$color_depth.webm"
|
|
||||||
|
|
||||||
ffmpeg -nostats -hide_banner -loglevel warning \
|
if [[ $two_pass = true ]]; then
|
||||||
-i "$input" -vf scale=$width:$height -f yuv4mpegpipe - | aomenc - --lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 \
|
eval 'ffmpeg -nostats -hide_banner -loglevel warning \
|
||||||
--target-bitrate=$target_bitrate --width="$width" --height="$height" --bit-depth=$color_depth --kf-min-dist=$kf_min_dist --kf-max-dist=$kf_max_dist \
|
-i "'$input'" '$ffmpego' -pix_fmt yuv444p -f yuv4mpegpipe - | aomenc - --i444 '$aomenco' \
|
||||||
--cpu-used=$speed \
|
--pass=1 --passes=2 --fpf="'$input'.fpf" --webm -o "'$input'.out.webm"'
|
||||||
--pass=2 --passes=2 --fpf="$input.$target_bitrate.$width.$height.$color_depth.fpf" --webm -o "$input.$target_bitrate.$width.$height.$color_depth.webm"
|
|
||||||
|
eval 'ffmpeg -nostats -hide_banner -loglevel warning \
|
||||||
|
-i "'$input'" '$ffmpego' -pix_fmt yuv444p -f yuv4mpegpipe - | aomenc - --i444 '$aomenco' \
|
||||||
|
--pass=2 --passes=2 --fpf="'$input.fpf'" --webm -o "'$input'.out.webm"'
|
||||||
|
else
|
||||||
|
eval 'ffmpeg -nostats -hide_banner -loglevel warning \
|
||||||
|
-i "'$input'" '$ffmpego' -pix_fmt yuv444p -f yuv4mpegpipe - | aomenc - --i444 '$aomenco' \
|
||||||
|
--passes=1 --fpf="'$input.fpf'" --webm -o "'$input.out.webm'"'
|
||||||
|
fi
|
||||||
|
|
||||||
curl -s -L "$base_url"/edit_status/"$job_id"/completed
|
curl -s -L "$base_url"/edit_status/"$job_id"/completed
|
||||||
|
|
||||||
|
81
src/main.rs
81
src/main.rs
@ -12,12 +12,13 @@ use rocket_contrib::uuid::Uuid;
|
|||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
mod workunit;
|
mod workunit;
|
||||||
use workunit::WUnit;
|
use workunit::WUnit;
|
||||||
use workunit::EStatus;
|
use workunit::EStatus;
|
||||||
|
|
||||||
const VERSION: &str = "0.1.0";
|
const VERSION: &str = "0.2.0";
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
struct SharedState {
|
struct SharedState {
|
||||||
@ -26,77 +27,13 @@ struct SharedState {
|
|||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> &'static str {
|
fn index() -> &'static str {
|
||||||
r#"#! /usr/bin/env nix-shell
|
r#"
|
||||||
#! nix-shell -i bash -p bash curl jq libaom ffmpeg-full
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
IFS=$'\n\t'
|
|
||||||
|
|
||||||
base_url="http://localhost:8000"
|
|
||||||
version="0.1.0"
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
sleep 1
|
|
||||||
upsteam_version=`curl -s "$base_url"/version`
|
|
||||||
if [[ $version != $upsteam_version ]]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
job=`curl -s "$base_url"/request_job | jq`
|
|
||||||
if [[ $job = "null" ]]; then
|
|
||||||
echo "No Jobs Available ¯\_(ツ)_/¯"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Got new job!"
|
|
||||||
echo "$job" | jq
|
|
||||||
|
|
||||||
job_id=`echo "$job" | jq -r .id`
|
|
||||||
|
|
||||||
echo "Reserving Job"
|
|
||||||
curl -s "$base_url"/edit_status/"$job_id"/reserved
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
source=`echo $job | jq -r .description.file_url`
|
|
||||||
sourceext=${source##*.}
|
|
||||||
echo "Downloading source file: $source"
|
|
||||||
|
|
||||||
source=`echo $job | jq -r .description.file_url`
|
|
||||||
|
|
||||||
name=`echo $job | jq -r .description.file_name`
|
|
||||||
input="$name.$job_id.$sourceext"
|
|
||||||
|
|
||||||
curl "$source" -o "$input"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "Starting Encode"
|
|
||||||
|
|
||||||
target_bitrate=`echo $job | jq -r .description.options.mode.VBR`
|
|
||||||
width=`echo $job | jq -r .description.options.resolution.width`
|
|
||||||
height=`echo $job | jq -r .description.options.resolution.height`
|
|
||||||
color_depth=`echo $job | jq -r .description.options.color_depth`
|
|
||||||
kf_min_dist=`echo $job | jq -r .description.options.kf_min_dist`
|
|
||||||
kf_max_dist=`echo $job | jq -r .description.options.kf_max_dist`
|
|
||||||
|
|
||||||
speed=`echo $job | jq -r .description.options.speed`
|
|
||||||
|
|
||||||
ffmpeg -i "$input" -vf scale=$width:$height -f yuv4mpegpipe - | aomenc - --lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 \
|
|
||||||
--target-bitrate=$target_bitrate --width="$width" --height="$height" --bit-depth=$color_depth --kf-min-dist=$kf_min_dist --kf-max-dist=$kf_min_dist \
|
|
||||||
--cpu-used=$speed \
|
|
||||||
--pass=1 --passes=2 --fpf="$input.$target_bitrate.$width.$height.$color_depth.fpf" --webm -o "$input.$target_bitrate.$width.$height.$color_depth.webm"
|
|
||||||
|
|
||||||
ffmpeg -i "$input" -vf scale=$width:$height -f yuv4mpegpipe - | aomenc - --lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 \
|
|
||||||
--target-bitrate=$target_bitrate --width="$width" --height="$height" --bit-depth=$color_depth --kf-min-dist=$kf_min_dist --kf-max-dist=$kf_min_dist \
|
|
||||||
--cpu-used=$speed \
|
|
||||||
--pass=2 --passes=2 --fpf="$input.$target_bitrate.$width.$height.$color_depth.fpf" --webm -o "$input.$target_bitrate.$width.$height.$color_depth.webm"
|
|
||||||
|
|
||||||
done
|
|
||||||
"#
|
"#
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/version")]
|
#[get("/version")]
|
||||||
fn version() -> &'static str {
|
fn version() -> &'static str {
|
||||||
"0.1.0"
|
VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/get_jobs")]
|
#[get("/get_jobs")]
|
||||||
@ -105,7 +42,6 @@ fn get_jobs(shared: State<SharedState>) -> Json<Value> {
|
|||||||
|
|
||||||
println!("{:#?}", list);
|
println!("{:#?}", list);
|
||||||
|
|
||||||
//Json(json!("god hlep me"))
|
|
||||||
Json(serde_json::to_value(&list).unwrap())
|
Json(serde_json::to_value(&list).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,14 +72,15 @@ fn get_job(id: Uuid, shared: State<SharedState>) -> Result<Json<Value>, NotFound
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/edit_status/<id>/<status>")]
|
#[get("/edit_status/<id>/<status>")]
|
||||||
fn edit_status(id: Uuid, status: String, shared: State<SharedState>) -> Result<String, Box<std::error::Error>> {
|
fn edit_status(id: Uuid, status: String, shared: State<SharedState>, remote_addr: SocketAddr) -> Result<String, Box<std::error::Error>> {
|
||||||
let mut list = shared.jobs.lock().unwrap();
|
let mut list = shared.jobs.lock().unwrap();
|
||||||
let job = list.get_mut(&id).ok_or("what")?;
|
let job = list.get_mut(&id).ok_or("what")?;
|
||||||
let status = match status.as_str() {
|
let status = match status.as_str() {
|
||||||
"queued" => Ok(EStatus::Queued),
|
"queued" => Ok(EStatus::Queued),
|
||||||
"reserved" => Ok(EStatus::Reserved),
|
"reserved" => Ok(EStatus::Reserved(remote_addr.to_string())),
|
||||||
"completed" => Ok(EStatus::Completed),
|
"completed" => Ok(EStatus::Completed(remote_addr.to_string())),
|
||||||
_ => Err("Not a valid status, valid statuses are queued, reserved, completed")
|
"error" => Ok(EStatus::Error(remote_addr.to_string())),
|
||||||
|
_ => Err("Not a valid status, valid statuses are queued, reserved, completed, and error")
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
job.status = status;
|
job.status = status;
|
||||||
|
@ -41,73 +41,30 @@ impl WDesc {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct EOptions {
|
pub struct EOptions {
|
||||||
pub mode: EMode,
|
pub ffmpeg: String,
|
||||||
pub resolution: Option<Resolution>,
|
pub aomenc: String,
|
||||||
pub color_depth: EColorDepth,
|
pub two_pass: bool
|
||||||
pub enable_fwd_keyframe: bool,
|
|
||||||
pub kf_min_dist: Option<u16>,
|
|
||||||
pub kf_max_dist: Option<u16>,
|
|
||||||
pub two_pass: bool,
|
|
||||||
pub speed: u8
|
|
||||||
}
|
}
|
||||||
impl Default for EOptions {
|
impl Default for EOptions {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
EOptions{
|
EOptions{
|
||||||
mode: EMode::default(),
|
ffmpeg: String::default(),
|
||||||
resolution: Option::default(),
|
aomenc: "--lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 --bit-depth=10 --cpu-used=3 --cq-level=30 --end-usage=q".to_string(),
|
||||||
color_depth: EColorDepth::default(),
|
two_pass: false
|
||||||
enable_fwd_keyframe: true,
|
|
||||||
kf_min_dist: Option::default(),
|
|
||||||
kf_max_dist: Option::default(),
|
|
||||||
two_pass: false,
|
|
||||||
speed: 3
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
|
||||||
pub enum EMode {
|
|
||||||
// Quality (CRF), Constrained Quality, Variable Bitrate, Constant Bitrate
|
|
||||||
Q(u8),
|
|
||||||
CQ(u8),
|
|
||||||
VBR(u32),
|
|
||||||
CBR(u32)
|
|
||||||
}
|
|
||||||
impl Default for EMode {
|
|
||||||
fn default() -> Self {
|
|
||||||
EMode::Q(30)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct Resolution {
|
|
||||||
pub width: u16,
|
|
||||||
pub height: u16
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Clone)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum EColorDepth {
|
|
||||||
Eight = 8,
|
|
||||||
Ten = 10,
|
|
||||||
Twelve = 12
|
|
||||||
}
|
|
||||||
impl Default for EColorDepth {
|
|
||||||
fn default() -> Self {
|
|
||||||
EColorDepth::Ten
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||||
pub enum EStatus {
|
pub enum EStatus {
|
||||||
Queued,
|
Queued,
|
||||||
Reserved,
|
Reserved(String),
|
||||||
Completed
|
Completed(String),
|
||||||
|
Cancelled,
|
||||||
|
Error(String)
|
||||||
}
|
}
|
||||||
impl Default for EStatus {
|
impl Default for EStatus {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
EStatus::Queued
|
EStatus::Queued
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client = String;
|
|
16
test.sh
16
test.sh
@ -11,22 +11,14 @@ curl "$base_url"/get_jobs | jq
|
|||||||
curl "$base_url"/add_job -X POST -H "Content-Type: application/json" -d \
|
curl "$base_url"/add_job -X POST -H "Content-Type: application/json" -d \
|
||||||
'
|
'
|
||||||
{
|
{
|
||||||
"file_url": "https://pomf.dodsorf.as/f/38ez7v.mkv",
|
"file_url": "https://pomf.dodsorf.as/f/vz9dtl.mkv",
|
||||||
"file_name": "014",
|
"file_name": "014",
|
||||||
"priority": 0,
|
"priority": 0,
|
||||||
"length": 15,
|
"length": 15,
|
||||||
"options": {
|
"options": {
|
||||||
"mode": { "VBR": 33 },
|
"aomenc": "--lag-in-frames=25 --tile-columns=0 --tile-rows=0 --enable-fwd-kf=1 --bit-depth=10 --cpu-used=0 --end-usage=vbr --target-bitrate=60 --kf-min-dist=9999 --kf-max-dist=9999",
|
||||||
"color_depth": 10,
|
"ffmpeg": "-vf scale=540:960",
|
||||||
"enable_fwd_keyframe": true,
|
"two_pass": true
|
||||||
"two_pass": true,
|
|
||||||
"speed": 0,
|
|
||||||
"resolution": {
|
|
||||||
"width": 960,
|
|
||||||
"height": 540
|
|
||||||
},
|
|
||||||
"kf_min_dist": 9999,
|
|
||||||
"kf_max_dist": 9999
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
Loading…
Reference in New Issue
Block a user