This commit is contained in:
Daniel Løvbrøtte Olsen
2020-03-27 01:50:01 +01:00
parent a68ac91e75
commit 3012c17b17
7 changed files with 235 additions and 3 deletions

View File

@@ -26,7 +26,72 @@ struct SharedState {
#[get("/")]
fn index() -> &'static str {
"Welcome to the AV1 Encoder Master Server"
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
"#
}
#[get("/version")]

View File

@@ -1,4 +1,5 @@
use serde::{Serialize, Deserialize};
use serde_repr::*;
use uuid::Uuid;
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
@@ -20,14 +21,16 @@ impl WUnit {
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct WDesc {
pub file_url: String,
pub file_name: String,
pub priority: u16,
pub length: u32,
pub options: EOptions,
}
impl WDesc {
pub fn new(file_url: &str, priority: Option<u16>, length: u32, options: Option<EOptions>) -> Self {
pub fn new(file_url: &str, file_name: &str, priority: Option<u16>, length: u32, options: Option<EOptions>) -> Self {
WDesc {
file_url: file_url.to_string(),
file_name: file_name.to_string(),
priority: priority.unwrap_or(0),
length: length,
options: options.unwrap_or(EOptions::default()),
@@ -82,7 +85,8 @@ pub struct Resolution {
pub height: u16
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Clone)]
#[repr(u8)]
pub enum EColorDepth {
Eight = 8,
Ten = 10,