Skip to content

Commit

Permalink
[minor] Add HLS streaming derivative service (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Dec 7, 2024
1 parent 2d10e70 commit 7b401ec
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ci/k8s/coverpage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
app: islandora-coverpage
ports:
- protocol: TCP
port: 8888
port: 8082
targetPort: 8080
---
apiVersion: apps/v1
Expand Down Expand Up @@ -37,7 +37,7 @@ spec:
memory: "1Gi"
ports:
- containerPort: 8080
hostPort: 8888
hostPort: 8082
readinessProbe:
httpGet:
path: /healthcheck
Expand Down
5 changes: 3 additions & 2 deletions ci/k8s/crayfits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spec:
app: islandora-crayfits
ports:
- protocol: TCP
port: 8080
port: 8083
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -36,7 +37,7 @@ spec:
memory: "128Mi"
ports:
- containerPort: 8080
hostPort: 8080
hostPort: 8083
readinessProbe:
httpGet:
path: /healthcheck
Expand Down
4 changes: 3 additions & 1 deletion ci/k8s/fits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spec:
app: fits
ports:
- protocol: TCP
port: 8080
port: 8084
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -41,6 +42,7 @@ spec:
memory: "2Gi"
ports:
- containerPort: 8080
hostPort: 8084
readinessProbe:
httpGet:
path: /fits/version
Expand Down
46 changes: 46 additions & 0 deletions ci/k8s/hls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
apiVersion: v1
kind: Service
metadata:
name: islandora-hls
spec:
selector:
app: islandora-hls
ports:
- protocol: TCP
port: 8085
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: islandora-hls
spec:
replicas: 3
selector:
matchLabels:
app: islandora-hls
template:
metadata:
labels:
app: islandora-hls
spec:
containers:
- name: scyllaridae-hls
image: lehighlts/scyllaridae-hls:main
imagePullPolicy: IfNotPresent
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "4Gi"
ports:
- hostPort: 8085
containerPort: 8080
readinessProbe:
httpGet:
path: /healthcheck
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
6 changes: 4 additions & 2 deletions ci/k8s/homarus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spec:
app: islandora-ffmpeg
ports:
- protocol: TCP
port: 8080
port: 8086
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -35,7 +36,8 @@ spec:
limits:
memory: "4Gi"
ports:
- containerPort: 8080
- hostPort: 8086
containerPort: 8080
readinessProbe:
httpGet:
path: /healthcheck
Expand Down
6 changes: 3 additions & 3 deletions ci/k8s/htr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
app: islandora-openai-htr
ports:
- protocol: TCP
port: 8001
port: 8087
targetPort: 8080
---
apiVersion: apps/v1
Expand All @@ -26,7 +26,7 @@ spec:
app: islandora-openai-htr
spec:
containers:
- name: scyllaridae-tesseract
- name: scyllaridae-htr
image: lehighlts/scyllaridae-openai-htr:main
imagePullPolicy: IfNotPresent
env:
Expand All @@ -42,7 +42,7 @@ spec:
limits:
memory: "1Gi"
ports:
- hostPort: 8001
- hostPort: 8087
containerPort: 8080
readinessProbe:
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions ci/k8s/mergepdf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
app: islandora-mergepdf
ports:
- protocol: TCP
port: 8887
port: 8088
targetPort: 8080
---
apiVersion: apps/v1
Expand Down Expand Up @@ -40,7 +40,7 @@ spec:
memory: "4Gi"
ports:
- containerPort: 8080
hostPort: 8887
hostPort: 8088
readinessProbe:
httpGet:
path: /healthcheck
Expand Down
4 changes: 2 additions & 2 deletions ci/k8s/ocrpdf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
app: islandora-ocrpdf
ports:
- protocol: TCP
port: 8886
port: 8089
targetPort: 8080
---
apiVersion: apps/v1
Expand Down Expand Up @@ -37,7 +37,7 @@ spec:
memory: "2Gi"
ports:
- containerPort: 8080
hostPort: 8886
hostPort: 8089
readinessProbe:
httpGet:
path: /healthcheck
Expand Down
11 changes: 11 additions & 0 deletions examples/hls/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG TAG=main
ARG DOCKER_REPOSITORY=lehighlts
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG}

RUN apk update && \
apk add --no-cache \
ffmpeg==6.1.1-r8 \
jq==1.7.1-r0

COPY scyllaridae.yml /app/scyllaridae.yml
COPY cmd.sh /app/cmd.sh
5 changes: 5 additions & 0 deletions examples/hls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Streaming Audio and Video Derivatives

Create an HLS streaming derivative for audio and video files

Requires `islandora_hls` module running on your Islandora site to render the streaming derivative.
43 changes: 43 additions & 0 deletions examples/hls/cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -eou pipefail

SOURCE_MIMETYPE="$1"
NODE_URL="$2"
NID=$(basename "$NODE_URL")
TMP_DIR=$(mktemp -d)

ffmpeg \
-f "$SOURCE_MIMETYPE" \
-i - \
-profile:v \
baseline \
-level 3.0 \
-s 640x360 \
-start_number 0 \
-hls_time 10 \
-hls_list_size 0 \
-f hls \
-b:v 800k \
-maxrate 800k \
-bufsize 1200k \
-b:a 96k "$TMP_DIR/$NID.m3u8" > /dev/null 2>&1

if [ ! -f "$TMP_DIR/$NID.m3u8" ]; then
exit 1
fi

# shellcheck disable=SC2046
tar -czf "$TMP_DIR/hls.tar.gz" -C "$TMP_DIR" "./$NID.m3u8" $(cd "$TMP_DIR" ; echo ./*.ts)

BASE_URL=$(dirname "$NODE_URL" | xargs dirname)
TID=$(curl -s "$BASE_URL/term_from_term_name?vocab=islandora_media_use&name=Service+File&_format=json" | jq '.[0].tid[0].value')

curl -s \
-H "Authorization: $SCYLLARIDAE_AUTH" \
-H "Content-Type: application/gzip" \
-H "Content-Location: private://derivatives/hls/$NID/hls.tar.gz" \
-T "$TMP_DIR/hls.tar.gz" \
"$NODE_URL/media/file/$TID"

rm -rf "$TMP_DIR"
10 changes: 10 additions & 0 deletions examples/hls/scyllaridae.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
forwardAuth: true
allowedMimeTypes:
- "audio/*"
- "video/*"
cmdByMimeType:
default:
cmd: /app/cmd.sh
args:
- "%source-mime-ext"
- "%canonical"
6 changes: 6 additions & 0 deletions examples/parry/scyllaridae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ queueMiddlewares:
- queueName: islandora-pdf-coverpage
url: http://coverpage:8080
consumers: 3
forwardAuth: true
- queueName: islandora-cache-warmer
url: http://cache-warmer:8080
consumers: 3
noPut: true
- queueName: islandora-merge-pdf
url: http://mergepdf:8080
consumers: 3
forwardAuth: true
- queueName: islandora-hls
url: http://hls:8080
consumers: 3
forwardAuth: true

0 comments on commit 7b401ec

Please sign in to comment.