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'
|
||||
|
||||
base_url="$1"
|
||||
version="0.1.0"
|
||||
version="0.2.0"
|
||||
|
||||
while true; do
|
||||
sleep 30
|
||||
@ -43,26 +43,28 @@ while true; do
|
||||
|
||||
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`
|
||||
aomenco=`echo $job | jq -r .description.options.aomenc`
|
||||
aomenco=${aomenco//[^a-zA-Z0-9_\- =]/}
|
||||
ffmpego=`echo $job | jq -r .description.options.ffmpeg`
|
||||
ffmpego=${ffmpego//[^a-zA-Z0-9_\- =:]/}
|
||||
|
||||
speed=`echo $job | jq -r .description.options.speed`
|
||||
two_pass=`echo $job | jq -r .description.options.two_pass`
|
||||
|
||||
ffmpeg -nostats -hide_banner -loglevel warning \
|
||||
-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"
|
||||
echo $two_pass
|
||||
|
||||
ffmpeg -nostats -hide_banner -loglevel warning \
|
||||
-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=2 --passes=2 --fpf="$input.$target_bitrate.$width.$height.$color_depth.fpf" --webm -o "$input.$target_bitrate.$width.$height.$color_depth.webm"
|
||||
if [[ $two_pass = true ]]; then
|
||||
eval 'ffmpeg -nostats -hide_banner -loglevel warning \
|
||||
-i "'$input'" '$ffmpego' -pix_fmt yuv444p -f yuv4mpegpipe - | aomenc - --i444 '$aomenco' \
|
||||
--pass=1 --passes=2 --fpf="'$input'.fpf" --webm -o "'$input'.out.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
|
||||
|
||||
|
81
src/main.rs
81
src/main.rs
@ -12,12 +12,13 @@ use rocket_contrib::uuid::Uuid;
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
mod workunit;
|
||||
use workunit::WUnit;
|
||||
use workunit::EStatus;
|
||||
|
||||
const VERSION: &str = "0.1.0";
|
||||
const VERSION: &str = "0.2.0";
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct SharedState {
|
||||
@ -26,77 +27,13 @@ struct SharedState {
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> &'static str {
|
||||
r#"#! /usr/bin/env nix-shell
|
||||
#! 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
|
||||
r#"
|
||||
"#
|
||||
}
|
||||
|
||||
#[get("/version")]
|
||||
fn version() -> &'static str {
|
||||
"0.1.0"
|
||||
VERSION
|
||||
}
|
||||
|
||||
#[get("/get_jobs")]
|
||||
@ -105,7 +42,6 @@ fn get_jobs(shared: State<SharedState>) -> Json<Value> {
|
||||
|
||||
println!("{:#?}", list);
|
||||
|
||||
//Json(json!("god hlep me"))
|
||||
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>")]
|
||||
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 job = list.get_mut(&id).ok_or("what")?;
|
||||
let status = match status.as_str() {
|
||||
"queued" => Ok(EStatus::Queued),
|
||||
"reserved" => Ok(EStatus::Reserved),
|
||||
"completed" => Ok(EStatus::Completed),
|
||||
_ => Err("Not a valid status, valid statuses are queued, reserved, completed")
|
||||
"reserved" => Ok(EStatus::Reserved(remote_addr.to_string())),
|
||||
"completed" => Ok(EStatus::Completed(remote_addr.to_string())),
|
||||
"error" => Ok(EStatus::Error(remote_addr.to_string())),
|
||||
_ => Err("Not a valid status, valid statuses are queued, reserved, completed, and error")
|
||||
}?;
|
||||
|
||||
job.status = status;
|
||||
|
@ -41,73 +41,30 @@ impl WDesc {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct EOptions {
|
||||
pub mode: EMode,
|
||||
pub resolution: Option<Resolution>,
|
||||
pub color_depth: EColorDepth,
|
||||
pub enable_fwd_keyframe: bool,
|
||||
pub kf_min_dist: Option<u16>,
|
||||
pub kf_max_dist: Option<u16>,
|
||||
pub two_pass: bool,
|
||||
pub speed: u8
|
||||
pub ffmpeg: String,
|
||||
pub aomenc: String,
|
||||
pub two_pass: bool
|
||||
}
|
||||
impl Default for EOptions {
|
||||
fn default() -> Self {
|
||||
EOptions{
|
||||
mode: EMode::default(),
|
||||
resolution: Option::default(),
|
||||
color_depth: EColorDepth::default(),
|
||||
enable_fwd_keyframe: true,
|
||||
kf_min_dist: Option::default(),
|
||||
kf_max_dist: Option::default(),
|
||||
two_pass: false,
|
||||
speed: 3
|
||||
ffmpeg: String::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(),
|
||||
two_pass: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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)]
|
||||
pub enum EStatus {
|
||||
Queued,
|
||||
Reserved,
|
||||
Completed
|
||||
Reserved(String),
|
||||
Completed(String),
|
||||
Cancelled,
|
||||
Error(String)
|
||||
}
|
||||
impl Default for EStatus {
|
||||
fn default() -> Self {
|
||||
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 \
|
||||
'
|
||||
{
|
||||
"file_url": "https://pomf.dodsorf.as/f/38ez7v.mkv",
|
||||
"file_url": "https://pomf.dodsorf.as/f/vz9dtl.mkv",
|
||||
"file_name": "014",
|
||||
"priority": 0,
|
||||
"length": 15,
|
||||
"options": {
|
||||
"mode": { "VBR": 33 },
|
||||
"color_depth": 10,
|
||||
"enable_fwd_keyframe": true,
|
||||
"two_pass": true,
|
||||
"speed": 0,
|
||||
"resolution": {
|
||||
"width": 960,
|
||||
"height": 540
|
||||
},
|
||||
"kf_min_dist": 9999,
|
||||
"kf_max_dist": 9999
|
||||
"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",
|
||||
"ffmpeg": "-vf scale=540:960",
|
||||
"two_pass": true
|
||||
}
|
||||
}
|
||||
'
|
||||
|
Loading…
Reference in New Issue
Block a user