Skip to content

Int 159 public image #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/videos/*.mp4
/videos/*.ts
/videos/*.json
/docker/app
1 change: 1 addition & 0 deletions app/cancel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include('includes/authorize.php');
exec('killall -9 ffmpeg');
if (count(glob('/videos/*.mp4')) != count(glob('/videos/*.json'))) {
foreach (glob('/videos/*.mp4') as $file) {
Expand Down
14 changes: 14 additions & 0 deletions app/credentials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

include('includes/authorize.php');

// Only allow to set initially
if (file_get_contents('/htpasswd/.htpasswd') == 'oskberlin:YWG41BPzVAkN6') {
$username = isset($_GET['username']) ? $_GET['username'] : exit;
$password = isset($_GET['password']) ? $_GET['password'] : exit;
$encrypted_password = crypt($password, base64_encode($password));
file_put_contents('/htpasswd/.htpasswd', $username . ':' . $encrypted_password);
echo json_encode(['status' => true]);
exit;
}
echo json_encode(['status' => false]);
1 change: 1 addition & 0 deletions app/hls-pull.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include('includes/authorize.php');
include('includes/analyze.php');
set_time_limit(0);

Expand Down
17 changes: 17 additions & 0 deletions app/includes/authorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
authenticate();
} else {
$encrypted_password = isset($_SERVER['PHP_AUTH_PW']) ? crypt($_SERVER['PHP_AUTH_PW'], base64_encode($_SERVER['PHP_AUTH_PW'])) : '';
if ($_SERVER['PHP_AUTH_USER'] . ':' . $encrypted_password != file_get_contents('/htpasswd/.htpasswd')) {
authenticate();
}
}

function authenticate() {
header('WWW-Authenticate: Basic realm="OSK Encoder Validator - default (oskberlin/admin)"');
header('HTTP/1.0 401 Unauthorized');
echo 'No Access';
exit;
}
42 changes: 42 additions & 0 deletions app/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php include('includes/authorize.php'); ?>
<!doctype html>
<html lang="en">
<head>
Expand Down Expand Up @@ -86,6 +87,47 @@
</div>
</div>
</div>

<div class="modal" id="basicAuthModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Set new username & password</h4>
</div>

<div class="modal-body">
<p>You are currently using <strong>oskberlin/admin</strong> as credentials for the validator. Please give a new username and password.</p>
<div class="form-group">
<label for="basic-auth-username">Username*</label>
<input type="text" class="form-control" id="basic-auth-username" aria-describedby="urlHelp" />
<div id="basic-auth-username-help"></div>
</div>
<div class="form-group">
<label for="basic-auth-password">Password*</label>
<input type="password" class="form-control" id="basic-auth-password" aria-describedby="urlHelp" />
<div id="basic-auth-password-help"></div>
</div>
<div class="form-group">
<label for="basic-auth-password-validate">Password (again)*</label>
<input type="password" class="form-control" id="basic-auth-password-validate" aria-describedby="urlHelp" />
<div id="basic-auth-password-validate-help"></div>
</div>
</div>

<div class="modal-footer">
<button type="button" id="set-credentials" class="btn btn-primary">Set new credentials</button>
</div>
</div>
</div>
</div>
<?php
// Only load admin if it's the standard
if (file_get_contents('/htpasswd/.htpasswd') == 'oskberlin:YWG41BPzVAkN6') {
?>
<script>$('#basicAuthModal').modal({backdrop: 'static', keyboard: false}).modal('show');</script>
<?php
}
?>
<script src="/js/list-logic.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions app/info.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
include('includes/authorize.php');
include('includes/test.php');
if (!isset($_GET['id']) || !file_exists('/videos/test-' . $_GET['id'] . '.json')) {
echo "This is not a valid run";
Expand Down
74 changes: 70 additions & 4 deletions app/js/list-logic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
var lastStatus = false;
var lastFetchAmount = 0;
var waitingForNew = false;

$(document).ready(function() {
checkStatus(true);
checkList();
Expand All @@ -16,6 +20,9 @@ $(document).ready(function() {
$('#cancel-test').on('click', function() {
cancelTest();
})
$('#set-credentials').on('click', function() {
setNewCredentials();
});
});

function testSrt() {
Expand Down Expand Up @@ -115,6 +122,10 @@ function cancelTest() {
function checkList() {
$.getJSON("/list.php", function( json ) {
var html = '';
if (waitingForNew) {
html = html + '<tr><td colspan="3">Processing a new video, have patience.<br><div class="bs-component"><div class="progress">';
html = html + '<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 10%"></div></div></div></td></tr>';
}
for (row of json.list) {
var link = '/info.php?id=' + row.number;
html = html + '<tr><td>' + row.number + '</td><td>' + row.date + '</td><td>';
Expand All @@ -126,8 +137,13 @@ function checkList() {
}
html = html + '</div></div></div></td></tr>';
}
$('#result-set tbody').html(html);
setTimeout(checkList, 20000);
if (lastFetchAmount !== json.list.length || waitingForNew) {
waitingForNew = false;
$('#result-set tbody').html(html);
}

lastFetchAmount = json.list.length;
setTimeout(checkList, 4000);
});
}

Expand All @@ -146,11 +162,11 @@ function checkStatus(first) {
}
if (json.listening === true && json.running === false && json.listening_format == 'rtmp') {
activeStream();
$('#message').html('Listening to rtmp on <strong>rtmp://' + window.location.hostname + ':6872</strong>. Please stream to this when ready.');
$('#message').html('Listening to rtmp on <strong>rtmp://' + window.location.hostname + ':6872/test/live</strong>. Please stream to this when ready.');
}
if (json.listening === true && json.running === true) {
activeStream();
$('#message').html('Currently streaming/reading. It will run for 30 seconds before we validate the stream.');
$('#message').html('Currently streaming/reading. It will run for 30 seconds or shorter before we validate the stream.');
}
if (json.listening === false && json.running === true) {
activeStream();
Expand All @@ -163,6 +179,11 @@ function checkStatus(first) {
$('#test-hls-pull').attr('disabled', false);
$('#test-srt').attr('disabled', false);
}

if (lastStatus && !json.running) {
waitingForNew = true;
}
lastStatus = json.running;
setTimeout(checkStatus, 500);
});
}
Expand All @@ -183,4 +204,49 @@ function nonActiveStream() {
$('#test-rtmp-pull').show();
$('#test-hls-pull').show();
$('#cancel-test').hide();
}

function setNewCredentials() {
var credValidation = true;
$('#basic-auth-password-help').removeClass('invalid-feedback');
$('#basic-auth-password').removeClass('is-invalid');
$('#basic-auth-password-validate-help').removeClass('invalid-feedback');
$('#basic-auth-password-validate-help').html('');
$('#basic-auth-password-validate').removeClass('is-invalid');
$('#basic-auth-password-help').html('');
$('#basic-auth-username-help').removeClass('invalid-feedback');
$('#basic-auth-username').removeClass('is-invalid');
$('#basic-auth-username-help').html('');

if ($('#basic-auth-username').val() == '') {
credValidation = false;
$('#basic-auth-username-help').addClass('invalid-feedback');
$('#basic-auth-username').addClass('is-invalid');
$('#basic-auth-username-help').html('You need to fill out this');
}
if ($('#basic-auth-password').val() == '') {
credValidation = false;
$('#basic-auth-password-help').addClass('invalid-feedback');
$('#basic-auth-password').addClass('is-invalid');
$('#basic-auth-password-help').html('You need to fill out this');
}
if ($('#basic-auth-password-validate').val() == '') {
credValidation = false;
$('#basic-auth-password-validate-help').addClass('invalid-feedback');
$('#basic-auth-password-validate').addClass('is-invalid');
$('#basic-auth-password-validate-help').html('You need to fill out this');
}
if ($('#basic-auth-password-validate').val() !== $('#basic-auth-password').val()) {
credValidation = false;
$('#basic-auth-password-validate-help').addClass('invalid-feedback');
$('#basic-auth-password-validate').addClass('is-invalid');
$('#basic-auth-password-validate-help').html('Passwords needs to match');
}
if (credValidation == true) {
$.getJSON("/credentials.php?username=" + $('#basic-auth-username').val() + '&password=' + $('#basic-auth-password').val(), function( json ) {
if (json.status) {
$('#basicAuthModal').modal('hide');
}
});
}
}
2 changes: 2 additions & 0 deletions app/list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include('includes/authorize.php');

$list = [];
foreach (glob('/videos/*.json') as $file) {
$info = json_decode(file_get_contents($file), TRUE);
Expand Down
3 changes: 1 addition & 2 deletions app/rtmp-pull.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include('includes/authorize.php');
include('includes/analyze.php');
set_time_limit(0);

Expand All @@ -15,8 +16,6 @@

// Tell everyone we are listening
file_put_contents('/tmp/listening-rtmp-pull', TRUE);
echo 'ffmpeg -i "' . $url . '" -c:v copy -c:a copy -strict -2 -y -t 30 -f mpegts /videos/test-' . $i . '.flv';
exit;
exec('ffmpeg -i "' . $url . '" -c:v copy -c:a copy -strict -2 -y -t 30 -f mpegts /videos/test-' . $i . '.flv');

exec('ffmpeg -i /videos/test-' . $i . '.flv -c copy /videos/test-' . $i . '.mp4');
Expand Down
3 changes: 2 additions & 1 deletion app/rtmp.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include('includes/authorize.php');
include('includes/analyze.php');
set_time_limit(0);

Expand All @@ -8,7 +9,7 @@
// Tell everyone we are listening
file_put_contents('/tmp/listening-rtmp', TRUE);

exec('ffmpeg -f flv -listen 1 -t 30 -i "rtmp://0.0.0.0:6872" -c:v copy -c:a copy -strict -2 -y -f mpegts /videos/test-' . $i . '.flv');
exec('ffmpeg -f flv -listen 1 -t 30 -i "rtmp://0.0.0.0:6872/test/live" -c:v copy -c:a copy -strict -2 -y -f mpegts /videos/test-' . $i . '.flv');

exec('ffmpeg -i /videos/test-' . $i . '.flv -c copy /videos/test-' . $i . '.mp4');
unlink('/videos/test-' . $i . '.flv');
Expand Down
1 change: 1 addition & 0 deletions app/srt.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include('includes/authorize.php');
include('includes/analyze.php');
set_time_limit(0);

Expand Down
4 changes: 3 additions & 1 deletion app/status.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include('includes/authorize.php');

$output = [
'listening' => FALSE,
'running' => FALSE,
Expand All @@ -16,7 +18,7 @@
}
if (file_exists('/tmp/listening-rtmp-pull')) {
$output['listening'] = TRUE;
$output['listening_format'] = 'rtmp';
$output['listening_format'] = 'rtmp-pull';
}
if (file_exists('/tmp/listening-hls-pull')) {
$output['listening'] = TRUE;
Expand Down
6 changes: 5 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ COPY config/app.conf /etc/apache2/sites-enabled/

RUN mkdir /videos
RUN mkdir /validation-config
RUN mkdir /htpasswd
COPY config/.htpasswd /htpasswd
RUN chown -R www-data:www-data /htpasswd

COPY config/entrypoint.sh /sbin/entrypoint.sh
COPY config/entrypoint.sh /sbin/entrypoint.sh
COPY app /var/www/app
4 changes: 3 additions & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
cp -r ../app ./
docker build . -t compuccino/encoder-validator:latest
docker push compuccino/encoder-validator:latest
docker push compuccino/encoder-validator:latest
rm -rf ./app
1 change: 1 addition & 0 deletions docker/config/.htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oskberlin:YWG41BPzVAkN6
6 changes: 4 additions & 2 deletions docker/config/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
AllowOverride None
AddDefaultCharset utf-8
DirectoryIndex index.php
Require all granted
Order allow,deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On

Expand All @@ -29,6 +30,7 @@
</Directory>

<Directory /videos>

Order allow,deny
Allow from all
</Directory>
</VirtualHost>
25 changes: 25 additions & 0 deletions validation-config/1080p-h264-stereo-aac-25fps-iframe50.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
video:
format:
and:
- or:
- exact: avc
- exact: h264
- not-exact: av1
width:
exact: 1920
height:
exact: 1080
frameRate:
exact: 25
audio:
format:
and:
- contains: aac
- not-exact: hd-aac
channelS:
exact: 2
# Frames is a special solution with it's own rules
frames:
keyFrameDistance:
min: 50
max: 50