diff --git a/Dockerfile b/Dockerfile index 4daf603..af4f2aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,17 @@ ARG JITSI_REPO=jitsi ARG BASE_TAG=stable FROM ${JITSI_REPO}/base-java:${BASE_TAG} +RUN apt-dpkg-wrap apt-get update && \ + apt-dpkg-wrap apt-get install -y jq ffmpeg bc && \ + apt-cleanup + + LABEL org.opencontainers.image.title="Jitsi Multitrack Recorder" LABEL org.opencontainers.image.description="An audio recording component." LABEL org.opencontainers.image.url="https://github.com/jitsi/jitsi-multitrack-recorder" LABEL org.opencontainers.image.source="https://github.com/jitsi/jitsi-multitrack-recorder" LABEL org.opencontainers.image.documentation="https://github.com/jitsi/jitsi-multitrack-recorder" - COPY target/jitsi-multitrack-recorder-0.1-SNAPSHOT-jar-with-dependencies.jar /jmr/ +COPY scripts/* /scripts/ COPY rootfs/ / - - - -VOLUME /config - diff --git a/rerun.sh b/rerun.sh index b3c9082..9483498 100755 --- a/rerun.sh +++ b/rerun.sh @@ -1,6 +1,8 @@ +#!/bin/bash set -e set -x mkdir -p ~/recordings mvn install -DskipTests -Dktlint.skip -docker build -t jitsi-multitrack-recorder:latest . && docker run -p 8989:8989 -v ~/recordings:/data jitsi-multitrack-recorder:latest +docker build -t jitsi-multitrack-recorder:latest . +docker run -e JMR_FINALIZE_SCRIPT=/scripts/finalize-flatten.sh -p 8989:8989 -v ~/recordings:/data jitsi-multitrack-recorder:latest diff --git a/rootfs/defaults/jmr.conf b/rootfs/defaults/jmr.conf index 7bed79b..8458e55 100644 --- a/rootfs/defaults/jmr.conf +++ b/rootfs/defaults/jmr.conf @@ -7,4 +7,7 @@ jitsi-multitrack-recorder { {{- end }} directory = {{ $JMR_DIRECTORY }} } + {{- if .Env.JMR_FINALIZE_SCRIPT }} + finalize-script = "{{ .Env.JMR_FINALIZE_SCRIPT }}" + {{- end }} } diff --git a/scripts/finalize-flatten.sh b/scripts/finalize-flatten.sh new file mode 100755 index 0000000..9037b2a --- /dev/null +++ b/scripts/finalize-flatten.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +set -x + +MEETING_ID=$1 +DIR=$2 +FORMAT=$3 + + +echo "Running $0 for $MEETING_ID, $DIR, $FORMAT" + +if [[ "$FORMAT" == "MKA" ]] ;then + /scripts/flatten-mka.sh "${DIR}/recording.mka" "${DIR}/recording-flat.wav" +fi + +if [[ "$JMR_FINALIZE_WEBHOOK" != "" ]] ;then + curl -s -o /dev/null "$JMR_FINALIZE_WEBHOOK?meetingId=$MEETING_ID" +fi diff --git a/src/main/kotlin/org/jitsi/recorder/Config.kt b/src/main/kotlin/org/jitsi/recorder/Config.kt index d500569..f4af532 100644 --- a/src/main/kotlin/org/jitsi/recorder/Config.kt +++ b/src/main/kotlin/org/jitsi/recorder/Config.kt @@ -19,12 +19,14 @@ package org.jitsi.recorder import org.jitsi.config.JitsiConfig import org.jitsi.metaconfig.config +import org.jitsi.metaconfig.optionalconfig import kotlin.time.Duration import kotlin.time.toKotlinDuration class Config { companion object { const val BASE = "jitsi-multitrack-recorder" + val port: Int by config { "$BASE.port".from(JitsiConfig.newConfig) } @@ -45,11 +47,16 @@ class Config { } } + val finalizeScript: String? by optionalconfig { + "$BASE.finalize-script".from(JitsiConfig.newConfig) + } + override fun toString(): String = """ port: $port recordingDirectory: $recordingDirectory recordingFormat: $recordingFormat maxGapDuration: $maxGapDuration + finalizeScript: $finalizeScript """.trimIndent() } } diff --git a/src/main/kotlin/org/jitsi/recorder/Main.kt b/src/main/kotlin/org/jitsi/recorder/Main.kt index 6d7151b..995fa1f 100644 --- a/src/main/kotlin/org/jitsi/recorder/Main.kt +++ b/src/main/kotlin/org/jitsi/recorder/Main.kt @@ -86,13 +86,14 @@ fun main(args: Array) { .start(wait = true) } -class RecordingSession(val meetingId: String) { +class RecordingSession(private val meetingId: String) { private val logger = createLogger().apply { addContext("meetingId", meetingId) } + private val directory = selectDirectory(meetingId) private val mediaJsonRecorder = if (Config.recordingFormat == RecordingFormat.MKA) { - MediaJsonMkaRecorder(selectDirectory(meetingId), logger) + MediaJsonMkaRecorder(directory, logger) } else { - MediaJsonJsonRecorder(selectDirectory(meetingId)) + MediaJsonJsonRecorder(directory) } fun processText(text: String) { @@ -105,6 +106,21 @@ class RecordingSession(val meetingId: String) { fun stop() = mediaJsonRecorder.stop().also { logger.warn("Stopping") + if (!Config.finalizeScript.isNullOrBlank()) { + logger.warn("Running finalize script") + val process = ProcessBuilder( + Config.finalizeScript, + meetingId, + directory.absolutePath, + Config.recordingFormat.toString() + ).apply { + val logFile = File(directory, "finalize.log") + redirectOutput(logFile) + redirectError(logFile) + }.start() + val ret = process.waitFor() + logger.warn("Finalise script returned $ret") + } } fun selectDirectory(meetingId: String): File { diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 35fcef6..469848a 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -6,5 +6,6 @@ jitsi-multitrack-recorder { // The maximum duration of a gap to repair using Opus PLC. max-gap-duration = 5 minutes } + // finalize-script = /path/to/finalize.sh port = 8989 }