Timestamp to log
Email on start encode Encode audio 48000 bps Clearly show error or success in Results page Optional savedir
This commit is contained in:
1 parent
f0279c4ca2
commit
ab642d9c51
6 files changed
+50
-28
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set +vx
|
||||
# encode - Encode for streaming and schedule cron job
|
||||
# Usage: encode
|
||||
# Called by cron every minute; process oldest .upload file in ./uploadpage/streams)
|
||||
@@ -15,7 +15,7 @@ upload=$(ls -Atr "$dir"/*.upload 2>/dev/null |head -1)
|
||||
[[ $upload ]] || exit 0
|
||||
|
||||
Log(){ # 1:message 2:returncode(empty: no exit) I:file
|
||||
echo -e "$1">>"$log"
|
||||
echo -e "$(date +'%m/%d %H:%M:%S') $1">>"$log"
|
||||
[[ $2 ]] && exit $2 || return 0
|
||||
}
|
||||
|
||||
@@ -36,9 +36,11 @@ Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,em
|
||||
sbj[0]="Stream Upload encoding done for ${name##*@}"
|
||||
sbj[1]="Stream Upload file wrong type: $type"
|
||||
sbj[2]="Stream Upload error encoding"
|
||||
sbj[3]="Stream Upload encoding started"
|
||||
msg[0]="Encoded video with tag '$name'.\nEncoding started on $start and finished on $finish."
|
||||
msg[1]="The file '$name' from $start is of type '$type' and could not be used."
|
||||
msg[2]="The file '$name' started encoding on $start but ran into an error on $finish."
|
||||
msg[3]="The file '$name' was received and encoding is starting."
|
||||
message="Heya,\n\n${msg[$1]}\n\nStream Upload server\n"
|
||||
if [[ $to && $user && $password && $smtp && $port ]]
|
||||
then # All required ingredients for a mail present
|
||||
@@ -48,10 +50,12 @@ Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,em
|
||||
((err==1)) && Log "== Mail with subject '${sbj[$1]}' could not be sent"
|
||||
((err==2)) && Log "== Mail with subject '${sbj[$1]}' failed to send to: $to"
|
||||
else # Can't send
|
||||
Log "== Mail with subject '${sbj[$1]}' cannot be sent"
|
||||
Log "== Mail with subject '${sbj[$1]}' cannot be sent [$to-$user-$password-$smtp-$port]"
|
||||
fi
|
||||
|
||||
Log "${msg[$1]}"
|
||||
Log "$2" $1
|
||||
# No log, no exit when just mailing to say we're starting
|
||||
(($1==3)) || Log "$2" $1
|
||||
}
|
||||
|
||||
# Rename upload and check type
|
||||
@@ -59,17 +63,19 @@ file=${upload%.upload} 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"
|
||||
|
||||
start=$(date +'%Y-%m-%d at %H:%M:%S')
|
||||
type=$(file -bL --mime-type "$file")
|
||||
[[ ! ${type:0:5} = video ]] && Mail 1 "File $name is of type $type"
|
||||
|
||||
# Encode video
|
||||
start=$(date +'%Y-%m-%d at %H:%M:%S') error=0
|
||||
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
|
||||
# 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=25" -video_track_timescale 18000 -movflags faststart -c:a copy -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=25" -video_track_timescale 18000 -movflags faststart -c:a copy -tune zerolatency -pass 2 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.2log" ||
|
||||
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=25" -video_track_timescale 18000 -movflags faststart -ar 48000 -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=25" -video_track_timescale 18000 -movflags faststart -ar 48000 -tune zerolatency -pass 2 -passlogfile "$file" -f mp4 "$video" 2>&1 |tail -n 20 >"$file.2log" ||
|
||||
error=1
|
||||
|
||||
# Remove logfiles
|
||||
|
||||
Reference in new issue
Block a user