Add readme
This commit is contained in:
1 parent
e57458dcab
commit
f571c2bca7
6 files changed
+84
-45
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# encode - Encode for streaming and schedule cron job
|
||||
# Usage: encode
|
||||
# Called by cron every minute; process oldest .upload file in uploadpage/streams)
|
||||
|
||||
repopath=/var/www
|
||||
log=$repopath/process.log
|
||||
dir=$repopath/uploadpage/streams
|
||||
|
||||
# Check for oldest uploaded file
|
||||
upload=$(/usr/bin/ls -1tr "$dir"/*.upload 2>/dev/null |head -1)
|
||||
|
||||
# Finished if no uploadpage/streams/*.upload files found
|
||||
[[ $upload ]] || exit 0
|
||||
|
||||
Log(){ # 1:message 2:returncode
|
||||
echo "$1">>"$log"
|
||||
# Remove source (if returncode not zero)
|
||||
/usr/bin/sync
|
||||
/usr/bin/sleep 1
|
||||
#(($2)) && /usr/bin/rm "$file"
|
||||
exit $2
|
||||
}
|
||||
|
||||
# Rename upload and check type
|
||||
file=${upload%.upload} name=${file##*/} key=${name%%.*} date=${name##*.} video=$file.mp4
|
||||
/usr/bin/mv "$upload" "$file"
|
||||
|
||||
type=$(file -bL --mime-type "$file")
|
||||
[[ ! ${type:0:5} = video ]] && Log "File $name is of type $type" 1
|
||||
|
||||
# Encode video
|
||||
## Single pass
|
||||
#/usr/bin/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" ||
|
||||
# Double pass
|
||||
/usr/bin/ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 1M -force_key_frames 'expr:gte(t,n_forced*2)' -movflags faststart -c:a copy -tune zerolatency -pass 1 -f mp4 "$video" &&
|
||||
/usr/bin/ffmpeg -y -i "$file" -c:v libx264 -x264opts no-scenecut -b:v 6M -maxrate 6M -bufsize 1M -force_key_frames 'expr:gte(t,n_forced*2)' -movflags faststart -c:a copy -tune zerolatency -pass 2 -f mp4 "$video" ||
|
||||
Log "Error encoding $name" 2
|
||||
|
||||
# Schedule cron job
|
||||
m=${date:13:2} m=${m#0} h=${date:11:2} h=${h#0}
|
||||
D=${date:8:2} D=${D#0} M=${date:5:2} M=${M#0}
|
||||
/usr/bin/crontab -l ||
|
||||
echo -e "# m h dom mon dow command\n" |/usr/bin/crontab -
|
||||
line="$m $h $D $M "'*'" $repopath/stream '${video##*/}'"
|
||||
echo -e "$(/usr/bin/crontab -l)\n$line" |/usr/bin/crontab -
|
||||
|
||||
Log "crontab: '$line'" 0
|
||||
Reference in new issue
Block a user