commit 08a25f62af3f865ac0973fb998d840ef87d2f820 Author: pepa65 Date: Fri Aug 26 21:31:39 2022 +0700 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a854f73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +upload.log +uploadpage/uploads/* diff --git a/prep b/prep new file mode 100755 index 0000000..699de26 --- /dev/null +++ b/prep @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# prep - Encode for streaming and schedule cron job +# Usage: prep +# (called from upload.php in /var/www/uploadpage) +# : "re_[0-9a-f_]*.YYYY-MM-DD_hh:mm" in /var/www/uploadpage/uploads/ + +log=/var/www/upload.log +dir=/var/www/uploadpage/uploads +name=$1 file=$dir/$name key=${name%%.*} date=${name##*.} +type=$(file -bL --mime-type "$file") +[[ ! ${type:0:5} = video ]] && + echo "$type" && exit 1 + +# Convert videofile +/usr/bin/ffmpeg -y -i "$file" \ + -vcodec libx264 -force_key_frames 'expr:gte(t,n_forced*2)' -b:v 5m -acodec copy "$file.mp4" && + sync && + sleep 1 && + /usr/bin/rm "$file" || + exit 2 + +# Schedule cron job +m=${date:14: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 $name" +echo -e "$(/usr/bin/crontab -l)\n$line" |/usr/bin/crontab - +echo "crontab: '$line'" >>"$log" + +exit 0 diff --git a/stream b/stream new file mode 100755 index 0000000..0a5ae98 --- /dev/null +++ b/stream @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# stream - Stream video when called from crontab + +in=/var/www/uploadpage/uploads/$1.mp4 key=${1%%.*} +/usr/bin/ffmpeg -re -y -i $in -c:v copy -c:a copy \ + -f flv "rtmp://singapore.restream.io/live/$key" diff --git a/uploadpage/index.php b/uploadpage/index.php new file mode 100644 index 0000000..1b74948 --- /dev/null +++ b/uploadpage/index.php @@ -0,0 +1,32 @@ + + +Stream Upload + +
+
+ + + + + + + + + + + + + + + + + + +

Video Upload Page

Streamkey:
Date:
Time:
Video File:

+
+
diff --git a/uploadpage/upload.php b/uploadpage/upload.php new file mode 100644 index 0000000..bfbfa3b --- /dev/null +++ b/uploadpage/upload.php @@ -0,0 +1,59 @@ +
+
+ +
'); + exit; +} + +header('Content-type: text/html; charset=utf-8'); +$upload=htmlspecialchars(basename($_FILES['fileToUpload']['name'])); +$key=$_POST['streamkey']; +$date=$_POST['date']; +$time=$_POST['time']; +$dir='uploads/'; +$name=$key.'.'.$date.'_'.$time; +$file=$dir.$name; +print(' + +Uploading +

Uploading

+File: '.$upload.'
'); +ob_flush(); +flush(); +$now=date('Y-m-dH:i'); +if(strcmp($now, $date.$time)>0){ + back('Scheduling '.$now.' in the past: '.$date.' '.$time); +} +$nextyear=date('Y-m-dH:i', strtotime('+1 year')); +if(strcmp($nextyear, $date.$time)<0){ + back('Scheduling too far into the future: '.$date.' '.$time); +} +if($_FILES['fileToUpload']['error']!=UPLOAD_ERR_OK){ + back('Error uploading the file'); +} +if(!move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)){ + back('Error moving the file'); +} + +$res=exec('../prep '.$name, $output, $ret); +if($ret==1){ + back('Not a video file, but of type: '.$res); +} +if($ret==2){ + back('Error with the encoding'); +} + +print('File uploaded as "'.$name.'"
+Scheduled for '.$date.' at '.$time); +?>