diff --git a/encode b/encode index d9e13f9..421d861 100755 --- a/encode +++ b/encode @@ -9,6 +9,7 @@ set +vx # Check for oldest uploaded file _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*} log=$repopath/process.log dir=$repopath/web/streams +shopt -s dotglob # Also get files starting with '.' upload=$(ls -Atr "$dir"/*.upload 2>/dev/null |head -1) # Finished if no web/streams/*.upload files found @@ -59,27 +60,27 @@ Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,em } # Rename upload and check type -file=${upload%.upload} video=$file.mp4 name=${file##*/} key=${name%%.*} +file=${upload%.upload} proc=$file.processing video=$file.mp4 name=${file##*/} key=${name%%.*} rest=${name#*.} date=${rest:0:15} id=${rest:15:1} _=${rest:16} _=${_%@*} username=${_%%:*} email=${_#$username} -mv "$upload" "$file" +mv "$upload" "$proc" start=$(date +'%Y-%m-%d at %H:%M:%S') -type=$(file -bL --mime-type "$file") +type=$(file -bL --mime-type "$proc") [[ ! ${type:0:5} = video ]] && Mail 1 "File $name is of type $type" # Encode video Mail 3 error=0 ## Single pass -#ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -force_key_frames 'expr:gte(t,n_forced*2)' -c:a copy -tune zerolatency -f mp4 "$video" |tail -n 20 >"$file.0log" || error=1 +#ffmpeg -y -i "$proc" -c:v libx264 -x264opts no-scenecut -b:v 6M -force_key_frames 'expr:gte(t,n_forced*2)' -c:a copy -tune zerolatency -f mp4 "$video" |tail -n 20 >"$file.0log" || error=1 # Double pass set -o pipefail # to get ffmpeg's returncode -ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 1 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.1log" && - ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 2 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.2log" || +ffmpeg -y -i "$proc" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 1 -passlogfile "$proc" -f mp4 "$video" 2>&1 |tail -n 20 >"$proc.1log" && + ffmpeg -y -i "$proc" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 12M -force_key_frames 'expr:gte(t,n_forced*2)' -vf "format=yuv420p,scale=1920x1080,setdar=16/9,fps=30" -video_track_timescale 18000 -movflags faststart -tune zerolatency -pass 2 -passlogfile "$proc" -f mp4 "$video" 2>&1 |tail -n 20 >"$proc.2log" || error=1 # Remove logfiles -rm "$file"-* +rm "$proc"-* finish=$(date +'%Y-%m-%d at %H:%M:%S') ((error)) && Mail 2 "Error encoding $name" @@ -87,12 +88,14 @@ finish=$(date +'%Y-%m-%d at %H:%M:%S') if [[ ! $id = _ ]] then countdown=$(ls -tr "$dir/.$id"*.mp4 2>/dev/null |head -1) - ffmpeg -f concat -safe 0 -i <(echo -e "file '$countdown'\nfile '$video'") -c copy "${video%.mp4}_.mp4" 2>&1 |tail -n 20 >"$file.3log" + ffmpeg -f concat -safe 0 -i <(echo -e "file '$countdown'\nfile '$video'") -c copy "${video%.mp4}_.mp4" 2>&1 |tail -n 20 >"$proc.3log" mv "${video%.mp4}_.mp4" "$video" fi # Remove tailfiles -rm -- "$file".?log +rm -- "$proc".?log +# Rename +mv -- "$proc" "$file" # Schedule cron job m=${date:13:2} m=${m#0} h=${date:11:2} h=${h#0} diff --git a/web/index.php b/web/index.php index ad36ba2..42d5fb7 100755 --- a/web/index.php +++ b/web/index.php @@ -34,7 +34,7 @@ function filename(){
Click to select the video
'); -if($user!=='library' && $user!=='pp'){ /////////////////////////////// +if($user!=='library'){ /////////////////////////////// // Check countdown options $cf=file(__DIR__.'/../countdown',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); $n=0; diff --git a/web/upload.php b/web/upload.php index 02b3817..4da82fb 100755 --- a/web/upload.php +++ b/web/upload.php @@ -53,7 +53,7 @@ $min=substr($time, 3, 2); $tme=$hour.$min; $dir='streams/'; $name=$key.'.'.$date.'_'.$tme.$id.$user.$email.'@'.$target; -if($user=='library' || $user=='pp'){ //////////////////////// +if($user=='library'){ //////////////////////// move_uploaded_file($_FILES['file']['tmp_name'], $dir.'video.'.$user); sleep(15); session_unset(); @@ -101,7 +101,7 @@ if(isset($countdown)){ } print(' -When done encoding, email '.$to.'
+After encoding, an email is sent to '.$to.'
Streaming on '.$date.' at '.$time.'h on '.$target.'
'); Back(''); ?>