Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar

Patrick Kalkman PatrickKalkman

View GitHub Profile
if (encodingInstructions.videoEncoder === constants.ENCODER_TYPES.X265) {
const ffmpegCommand = ffmpeg()
.input(inputAsset)
.videoBitrate(encodingInstructions.videoBitrate)
.videoCodec(encodingInstructions.videoEncoder)
.size(encodingInstructions.videoSize)
.audioCodec(encodingInstructions.audioEncoder)
.audioBitrate(encodingInstructions.audioBitrate)
.audioFrequency(encodingInstructions.audioFrequency)
.withOutputOptions('-force_key_frames "expr:gte(t,n_forced*2)"')
app.processEncodingTasks = function processEncodingTasks() {
encoderEngine.searchTasks((searchErr, encoderInstructions) => {
if (!searchErr && encoderInstructions) {
log.info(`Got encoder instructions, started encoder for task '${encoderInstructions.name}' id:${encoderInstructions._id}`);
encoderEngine.startEncoder(encoderInstructions, (startErr) => {
if (!startErr) {
encoderEngine.setTaskToFinished(encoderInstructions._id, (finishErr) => {
if (finishErr) {
log.error(`An error occurred while trying to set the task to finished. ${finishErr.message}`);
}
@PatrickKalkman
PatrickKalkman / scalingEngine.js
Created January 8, 2023 18:28
Very simple scaling algorithm
scalingEngine.getNumberOfNeededEncoders = (numberOfEncodingTasks, numberOfEncoders) => {
if (numberOfEncodingTasks >= 0 && numberOfEncodingTasks <= 10) {
if (numberOfEncoders >= 1 && numberOfEncodingTasks < 1) {
return 0;
}
return numberOfEncoders;
}
if (numberOfEncodingTasks > 10 && numberOfEncodingTasks <= 50) {
if (numberOfEncoders < 4) {
@PatrickKalkman
PatrickKalkman / encoder-scaler-deploy.yaml
Last active January 8, 2023 10:30
Specifying the service account so that the encoder scaler can access the encoder deployment via the Kubernetes API
apiVersion: apps/v1
kind: Deployment
metadata:
name: encoderscaler
spec:
replicas: 1
selector:
matchLabels:
app: encoderscaler
strategy:
import k8s from '@kubernetes/client-node';
import log from './log.js';
const kubernetesClient = {};
kubernetesClient.setNumberOfEncoders = async (numberOfEncoders) => {
try {
const kubeconfig = new k8s.KubeConfig();
if (process.env.NODE_ENV === 'production') {
@PatrickKalkman
PatrickKalkman / HLS Ladder.csv
Created November 9, 2022 19:22
HLS bitrate ladder
16:9 aspect ratio Bitrate Frame rate
416 x 234 145 ≤ 30 fps
640 x 360 365 ≤ 30 fps
768 x 432 730 ≤ 30 fps
768 x 432 1100 ≤ 30 fps
960 x 540 2000 Same as source
1280 x 720 3000 Same as source
1280 x 720 4500 Same as source
1920 x 1080 6000 Same as source
1920 x 1080 7800 Same as source
public List<ContentValues> parseMovies(JSONArray videoArray) throws JSONException {
List<ContentValues> videosToInsert = new ArrayList<>();
String title = video.optString(TAG_TITLE);
String description = video.optString(TAG_DESCRIPTION);
String short_description = video.optString(TAG_SHORT_DESCRIPTION);
if (description.isEmpty()) {
description = short_description;
}
public List<ContentValues> parseMedia(JSONArray videoArray) throws JSONException {
List<ContentValues> videosToInsert = new ArrayList<>();
for (int j = 0; j < videoArray.length(); j++) {
JSONObject video = videoArray.getJSONObject(j);
String videoUrl = video.optString(TAG_URL);
String titleId = video.optString(TAG_TITLE_ID);
if (videoUrl.isEmpty()) {
if (!titleId.isEmpty()) {
<#
.SYNOPSIS
Get the ip address from the ip-addresses.json and give these access to all the
app services in the given resource group.
.DESCRIPTION
Get the ip address from the ip-addresses.json and give these access to all the
app services in the given resource group.
.PARAMETER JsonFilename
function Add-AccessRestrictionToAppService([string] $ResourceGroupName, [string] $Name, [string] $IpFilterRuleName, [string] $IpAddress, [string] $Priority)
{
Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and $Priority access to $Name"
Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress
Update-AzWebAppAccessRestrictionConfig -Name $appService.Name -ResourceGroupName $ResourceGroupName -ScmSiteUseMainSiteRestrictionConfig
# Also add the access restriction to the staging slots
$allSlots = Get-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name
Foreach ($slot in $allSlots)
{