summaryrefslogtreecommitdiff
path: root/roles/streaming/rtmp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2020-08-20 01:31:45 +0200
committerChristian Pointner <equinox@spreadspace.org>2020-08-20 01:31:45 +0200
commitb7b6a053edd8ef10371a6f4cc094722a2b91b410 (patch)
tree89076eb460251844a42605676e3b3c61bf57b505 /roles/streaming/rtmp
parentadd new rtmp streamer role (diff)
rtmp-streamer: enable recording
Diffstat (limited to 'roles/streaming/rtmp')
-rw-r--r--roles/streaming/rtmp/streamer/defaults/main.yml6
-rw-r--r--roles/streaming/rtmp/streamer/tasks/main.yml19
-rw-r--r--roles/streaming/rtmp/streamer/templates/pod-spec.yml.j220
-rw-r--r--roles/streaming/rtmp/streamer/templates/record.sh.j29
4 files changed, 51 insertions, 3 deletions
diff --git a/roles/streaming/rtmp/streamer/defaults/main.yml b/roles/streaming/rtmp/streamer/defaults/main.yml
index 5a9b48f7..5f74af02 100644
--- a/roles/streaming/rtmp/streamer/defaults/main.yml
+++ b/roles/streaming/rtmp/streamer/defaults/main.yml
@@ -1,6 +1,7 @@
---
rtmp_streamer_base_path: /srv/rtmp/streamer
+rtmp_streamer_port: 1935
# rtmp_streamer_inst_name: feed
# rtmp_streamer_nginx_image_version: 2020-04-29.7
# rtmp_streamer_decklink_card: "DeckLink Mini Recorder"
@@ -8,6 +9,7 @@ rtmp_streamer_app_name: "{{ rtmp_streamer_inst_name }}"
rtmp_streamer_quality_levels:
- full
-rtmp_streamer_config: {}
+rtmp_streamer_recording_enabled: no
+rtmp_streamer_recording_level: full
-rtmp_streamer_port: 1935
+rtmp_streamer_config: {}
diff --git a/roles/streaming/rtmp/streamer/tasks/main.yml b/roles/streaming/rtmp/streamer/tasks/main.yml
index 828ceba6..e63bbdce 100644
--- a/roles/streaming/rtmp/streamer/tasks/main.yml
+++ b/roles/streaming/rtmp/streamer/tasks/main.yml
@@ -1,5 +1,5 @@
---
-- name: create rtmp-streamer scripts subdirectories
+- name: create rtmp-streamer instance directory
file:
path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}"
state: directory
@@ -14,6 +14,22 @@
content: "{{ rtmp_streamer_config | combine({'rtmp_base_url': 'rtmp://127.0.0.1/'+rtmp_streamer_app_name}) | to_nice_yaml }}\n"
dest: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/config.yml"
+- name: enable recording
+ when: rtmp_streamer_recording_enabled | bool
+ block:
+ - name: create recording directory
+ file:
+ path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/recordings"
+ state: directory
+ owner: app
+ group: app
+
+ - name: generate recording script
+ template:
+ src: record.sh.j2
+ dest: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/record.sh"
+ mode: 0755
+
- name: install pod manifest
vars:
kubernetes_standalone_pod:
@@ -26,5 +42,6 @@
- path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/config.yml"
properties:
- checksum
+ ## TODO: add record.sh if recording is enabled
include_role:
name: kubernetes/standalone/pod
diff --git a/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2 b/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2
index b4a6ee9d..f670fb25 100644
--- a/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2
+++ b/roles/streaming/rtmp/streamer/templates/pod-spec.yml.j2
@@ -53,6 +53,20 @@ containers:
- name: CONFIG_FILENAME
value: /srv/config.yml
+{% if rtmp_streamer_recording_enabled %}
+- name: record
+ image: registry.gitlab.com/spreadspace/docker/nginx:{{ rtmp_streamer_nginx_image_version }}
+ imagePullPolicy: Always
+ args:
+ - /srv/record.sh
+ volumeMounts:
+ - name: home
+ mountPath: /srv
+ readOnly: true
+ - name: recordings
+ mountPath: /srv/recordings
+
+{% endif %}
volumes:
- name: home
hostPath:
@@ -67,3 +81,9 @@ volumes:
hostPath:
type: Directory
path: /usr/lib/
+{% if rtmp_streamer_recording_enabled %}
+- name: recordings
+ hostPath:
+ type: Directory
+ path: "{{ rtmp_streamer_base_path }}/{{ rtmp_streamer_inst_name }}/recordings"
+{% endif %}
diff --git a/roles/streaming/rtmp/streamer/templates/record.sh.j2 b/roles/streaming/rtmp/streamer/templates/record.sh.j2
new file mode 100644
index 00000000..159bf5e2
--- /dev/null
+++ b/roles/streaming/rtmp/streamer/templates/record.sh.j2
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+BASE_D="/srv/recordings"
+DAY=$(date '+%Y-%m-%d')
+TIME=$(date '+%H-%M-%S')
+
+umask 022
+mkdir -p "$BASE_D/$DAY"
+exec /usr/bin/ffmpeg -f live_flv -rtmp_live live -i "rtmp://127.0.0.1/{{ rtmp_streamer_app_name }}/{{ rtmp_streamer_recording_level }}" -c:a copy -c:v copy -f matroska "$BASE_D/$DAY/$DAY""_$TIME.mkv"