Skip to content
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

feat: Add a finalize script. #20

Merged
merged 2 commits into from
Nov 19, 2024
Merged
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
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 3 additions & 1 deletion rerun.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions rootfs/defaults/jmr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ jitsi-multitrack-recorder {
{{- end }}
directory = {{ $JMR_DIRECTORY }}
}
{{- if .Env.JMR_FINALIZE_SCRIPT }}
finalize-script = "{{ .Env.JMR_FINALIZE_SCRIPT }}"
{{- end }}
}
19 changes: 19 additions & 0 deletions scripts/finalize-flatten.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/main/kotlin/org/jitsi/recorder/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
}
}
22 changes: 19 additions & 3 deletions src/main/kotlin/org/jitsi/recorder/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ fun main(args: Array<String>) {
.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) {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading