First commit
This commit is contained in:
commit
08a25f62af
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
upload.log
|
||||
uploadpage/uploads/*
|
||||
31
prep
Executable file
31
prep
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# prep - Encode for streaming and schedule cron job
|
||||
# Usage: prep <upload>
|
||||
# (called from upload.php in /var/www/uploadpage)
|
||||
# <upload>: "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
|
||||
6
stream
Executable file
6
stream
Executable file
@ -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"
|
||||
32
uploadpage/index.php
Normal file
32
uploadpage/index.php
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Stream Upload</title>
|
||||
<script>
|
||||
function respond(){
|
||||
const feedback = document.getElementById('response');
|
||||
feedback.innerHTML = '<b>File is uploading</b>';
|
||||
}
|
||||
</script>
|
||||
<div style="display:flex; justify-content:center; align-items:center; height:95vh;">
|
||||
<form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="respond()">
|
||||
<table>
|
||||
<tr><td colspan=2 align=center><h1>Video Upload Page</h1></td></tr>
|
||||
<tr>
|
||||
<td>Streamkey:</td>
|
||||
<td><input type="text" name="streamkey" id="streamkey" required title="re_ followed by a string of 0-9, a-f or underscore characters (20 or longer)" pattern="re_[a-f0-9_]{20,}"></td></tr>
|
||||
<tr>
|
||||
<td>Date:</td>
|
||||
<td><input type="date" name="date" id="date" required></td></tr>
|
||||
<tr>
|
||||
<td>Time:</td>
|
||||
<td><input type="time" name="time" id="time" required></td></tr>
|
||||
<tr>
|
||||
<td>Video File:</td>
|
||||
<td><input type="file" name="fileToUpload" id="fileToUpload" required accept=".mp4"></td></tr>
|
||||
<tr><td><p></td></tr>
|
||||
<tr><td align=center colspan="2"><input type="submit" value="Schedule Stream" name="submit"></td></tr>
|
||||
<tr><td><p></td></tr>
|
||||
<tr><td align=center colspan="2" id="response"></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
59
uploadpage/upload.php
Normal file
59
uploadpage/upload.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
//ob_implicit_flush(true);
|
||||
//ob_end_flush();
|
||||
if($_SERVER['REQUEST_METHOD']!=='POST'){
|
||||
header('Location: /');
|
||||
}
|
||||
|
||||
function back($msg){
|
||||
print($msg);
|
||||
print('<br><br>
|
||||
<form action="/" method="post">
|
||||
<input type="submit" value="Upload another file" name="submit">
|
||||
</form>');
|
||||
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('<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Uploading</title>
|
||||
<h3>Uploading</h3>
|
||||
File: '.$upload.'<br>');
|
||||
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.'"<br>
|
||||
Scheduled for '.$date.' at '.$time);
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user