From f571c2bca7392ada93e381822208b445c073d39f Mon Sep 17 00:00:00 2001 From: pepa65 Date: Mon, 29 Aug 2022 15:24:26 +0700 Subject: [PATCH] Add readme --- .gitignore | 2 +- README.md | 24 ++++++++++++++++++++++++ prep => encode | 23 ++++++++++++----------- stream | 20 +++++++++++++------- uploadpage/index.php | 17 +++++++++++++---- uploadpage/upload.php | 43 +++++++++++++++++++++---------------------- 6 files changed, 84 insertions(+), 45 deletions(-) create mode 100644 README.md rename prep => encode (64%) diff --git a/.gitignore b/.gitignore index c0781b7..6c4fb35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -encoding.log +process.log uploadpage/streams/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..75f5edf --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# streamupload +**Upload videos to be re-encoded and scheduled for streaming** + +## Install +* Prepare a server, set its timezone to the users' timezone + (on deb-based systems: `dpkg-reconfigure tzdata`) +* On the server, `cd` to the place where you want the files +* Clone repo: `git clone https://gitlab.com/pepa65/streamupload` +* `cd streamupload` +* Change the value of the `repopath` variable in `stream` and `encode` + to the output of `echo $PWD` +* Run a php/webserver on $PWD/uploadpage + - Get it to restart on reboot + - Setting up basicauth on the page is a good idea if others can get access! + - Change the relevant `php.ini` to allow large file uploads: + * `post_max_size` - Upper limit of uploaded video sizes, say `10G` + * `upload_max_filesize` - same value as `post_max_size` +* Make a crontab-entry: "* * * * * $PWD/encode" (replace $PWD with its value!) + +## Usage +* Get a streamkey for the target by scheduling a stream + (supported are: Restream.io, YouTube.com, Facebook.com) +* Go to the server's IP address in the browser: `http://$ipaddress` +* Fill in the form, click "Schedule Stream" diff --git a/prep b/encode similarity index 64% rename from prep rename to encode index 93a2144..4223634 100755 --- a/prep +++ b/encode @@ -1,16 +1,17 @@ #!/usr/bin/env bash -# prep - Encode for streaming and schedule cron job -# Usage: prep -# Called by cron every minute; process oldest .upload file in /var/www/uploadpage/streams) +# encode - Encode for streaming and schedule cron job +# Usage: encode +# Called by cron every minute; process oldest .upload file in uploadpage/streams) -log=/var/www/encoding.log -dir=/var/www/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 /var/www/uploadpage/streams/*.upload files found +# Finished if no uploadpage/streams/*.upload files found [[ $upload ]] || exit 0 Log(){ # 1:message 2:returncode @@ -18,7 +19,7 @@ Log(){ # 1:message 2:returncode # Remove source (if returncode not zero) /usr/bin/sync /usr/bin/sleep 1 - (($2)) && /usr/bin/rm "$file" + #(($2)) && /usr/bin/rm "$file" exit $2 } @@ -33,16 +34,16 @@ type=$(file -bL --mime-type "$file") ## 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 -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 -force_key_frames 'expr:gte(t,n_forced*2)' -movflags faststart -c:a copy -tune zerolatency -pass 2 -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 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:14:2} m=${m#0} h=${date:11:2} h=${h#0} +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 "'*'" /var/www/stream '${video##*/}'" +line="$m $h $D $M "'*'" $repopath/stream '${video##*/}'" echo -e "$(/usr/bin/crontab -l)\n$line" |/usr/bin/crontab - Log "crontab: '$line'" 0 diff --git a/stream b/stream index ec0118f..9b02ca4 100755 --- a/stream +++ b/stream @@ -2,12 +2,18 @@ # stream - Stream video when called from crontab # Usage: stream