From d2fc5d02514ce32d73452f145425f20981dfd22a Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 11:47:04 +0100 Subject: [PATCH 1/7] Updating copyright header to 2019 and new URL --- bin/raar-record-handler.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/raar-record-handler.sh b/bin/raar-record-handler.sh index 61aa8ff..17c66b8 100755 --- a/bin/raar-record-handler.sh +++ b/bin/raar-record-handler.sh @@ -3,9 +3,9 @@ # raar-record-handler.sh - Moves new recordings to the raar import directory ################################################################################ # -# Copyright (C) 2018 Radio Bern RaBe -# Switzerland -# http://www.rabe.ch +# Copyright (C) 2018 - 2019 Radio Bern RaBe +# Switzerland +# https://rabe.ch # # This program is free software: you can redistribute it and/or # modify it under the terms of the GNU Affero General Public From 9a31d8ac6c04fc9a51c3aa39b8f4f768d025f915 Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 11:48:23 +0100 Subject: [PATCH 2/7] Removing static 60 minute duration from file name. The duration of the recording will be added by the raar-record-handler, which adds the effective track duration to the file name. --- config/systemd/rotter@raar.service.d/override.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/systemd/rotter@raar.service.d/override.conf b/config/systemd/rotter@raar.service.d/override.conf index bb7ae14..b022854 100644 --- a/config/systemd/rotter@raar.service.d/override.conf +++ b/config/systemd/rotter@raar.service.d/override.conf @@ -1,3 +1,3 @@ [Service] # Rotter startup options -Environment="ROTTER_OPTIONS=-a -f flac -c 2 -R 10 -L '%%FT%%H%%M%%S%%z_060.flac' -j" +Environment="ROTTER_OPTIONS=-a -f flac -c 2 -R 10 -L '%%FT%%H%%M%%S%%z.flac' -j" From e717fdc34b27a01a5cc49a4ab30294658337abbf Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 11:53:49 +0100 Subject: [PATCH 3/7] Fixed typos. --- bin/raar-record-handler.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/raar-record-handler.sh b/bin/raar-record-handler.sh index 17c66b8..2353199 100755 --- a/bin/raar-record-handler.sh +++ b/bin/raar-record-handler.sh @@ -74,7 +74,7 @@ minFileSize="$(( 20 * 1048576 ))" # 20 MiB inotifywait --monitor --event close_write "${watchDir}" | while read \ watchedFileName eventNames eventFileName do - echo "${eventNames} occoured on ${eventFileName}" + echo "${eventNames} occurred on ${eventFileName}" sourcePath="${watchDir}/${eventFileName}" @@ -107,7 +107,7 @@ do echo "${eventFileName} successfully archived" - # Inform the monitoring system about the last successfull recording + # Inform the monitoring system about the last successful recording zabbix_sender --config /etc/zabbix/zabbix_agentd.conf \ --key 'rabe.raar.recording.success[]' \ --value "$(date +%s)" > /dev/null From db0f80cfb7ecdedca3339f2309019a1ea6bc2a12 Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 11:56:10 +0100 Subject: [PATCH 4/7] Updated documentation regarding recording duration. --- bin/raar-record-handler.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/raar-record-handler.sh b/bin/raar-record-handler.sh index 2353199..cd7debc 100755 --- a/bin/raar-record-handler.sh +++ b/bin/raar-record-handler.sh @@ -32,6 +32,8 @@ # watch directory, containing recording files. The script assumes, that a # recording has finished on such an event and moves the file to the given # destination directory. +# Before moving the recording file to its final location, the script determines +# the duration of the recording and adds it to the final file name. # If the archival was successful, the script sends the last successful # recording timestamp to a Zabbix monitoring system with the help of the # zabbix_sender tool. From 6d0210c160f27f7b947726fa35b54ab6ac58c0c0 Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 12:36:23 +0100 Subject: [PATCH 5/7] Add recording duration to file name. Determine the recording duration with the help of ffprobe. Add the rounded duration in seconds to the file name in the ISO 8601 duration format. For example, the original recording file name "2019-11-30T170000+0100.flac" will be renamed to "2019-11-30T170000+0100_PT3600S.flac", whereas 3600 is the duration in seconds for this recording. This implements #6. --- bin/raar-record-handler.sh | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/bin/raar-record-handler.sh b/bin/raar-record-handler.sh index cd7debc..cd0703c 100755 --- a/bin/raar-record-handler.sh +++ b/bin/raar-record-handler.sh @@ -88,8 +88,41 @@ do echo "Archiving ${eventFileName}" - tmpPath="${destDir}/.${eventFileName}.tmp" - destPath="${destDir}/${eventFileName}" + # Get the duration of the recording in seconds, with microsecond accuracy + # such as "3599.998979" + ffprobeOutput="$( LC_ALL=C ffprobe -i "${sourcePath}" \ + -show_entries format="duration" \ + -print_format csv="print_section=0" \ + -v quiet )" + + if [ $? -eq 0 ]; then + # Round to integer value in seconds + # 3599.998979 => 3600 + duration=$( LC_ALL=C printf '%.0f' "$ffprobeOutput" ) + + echo "Duration of recording is ${duration} seconds (${ffprobeOutput})" + else + echo "Unable to determine duration of recording" >&2 + duration="0" + fi + + + # Get the file name without the extension, such as "2019-11-30T170000+0100" + fileName="${eventFileName%.*}" + + # Get the file extension, such as flac, opus or mp3 + fileExtension="${eventFileName##*.}" + + # Add the duration to the original file name in the ISO 8601 duration + # format. + # For example, the file name "2019-11-30T170000+0100.flac" will be renamed + # to "2019-11-30T170000+0100_PT3600S.flac" + finalFileName="${fileName}_PT${duration}S.${fileExtension}" + + echo "Setting final recording file name to: ${finalFileName}" + + tmpPath="${destDir}/.${finalFileName}.tmp" + destPath="${destDir}/${finalFileName}" # Move the file to a temporary location in a first step. This prevents the # archive from importing an unfinished file, in case the source and @@ -107,7 +140,7 @@ do continue fi - echo "${eventFileName} successfully archived" + echo "${eventFileName} successfully archived to ${destPath}" # Inform the monitoring system about the last successful recording zabbix_sender --config /etc/zabbix/zabbix_agentd.conf \ From 4c5930c1d103704882f38c07f2435b49df141760 Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 12:45:27 +0100 Subject: [PATCH 6/7] Check if external commands are available. --- bin/raar-record-handler.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/raar-record-handler.sh b/bin/raar-record-handler.sh index cd0703c..5e2421f 100755 --- a/bin/raar-record-handler.sh +++ b/bin/raar-record-handler.sh @@ -44,6 +44,20 @@ # raar-record-handler.sh # +# Check if all required external commands are available +for cmd in ffprobe \ + inotifywait \ + mv \ + printf \ + zabbix_sender +do + command -v "${cmd}" >/dev/null 2>&1 || { + echo >&2 "Missing command '${cmd}'" + exit 1 + } + +done + watchDir="$1" destDir="$2" From abe4f393ca7a934d21dd80fb3f19ba0fb8b31459 Mon Sep 17 00:00:00 2001 From: Christian Affolter Date: Sun, 1 Dec 2019 13:23:53 +0100 Subject: [PATCH 7/7] Updated recording README regarding duration. Updated the recording README with installation instructions for the ffprobe command which is used for determining the recording duration. Required for #6. --- doc/recording.md | 69 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/doc/recording.md b/doc/recording.md index 5fa770f..f46b167 100644 --- a/doc/recording.md +++ b/doc/recording.md @@ -16,16 +16,24 @@ and some systemd service units, which plays nicely together with RAAR. [Rotter](https://www.aelius.com/njh/rotter/) is a Recording of Transmission / Audio Logger for [JACK](http://www.jackaudio.org/). It captures audio from `jackd`, encodes it in a specified format and creates a new recording file -every hour by default. This makes it ideal to use together with RAAR. +every hour by default. This makes it ideal for using it together with RAAR. In the following deployment walk-through `rotter` will be configured to capture the audio from the first two JACK input ports found, while storing the recordings into the `/var/lib/rotter/raar` directory in the lossless -[FLAC](https://xiph.org/flac/) format. A separate recording-handler will move -the finished recordings from the `/var/lib/rotter/raar` directory to a final -RAAR import directory. Of course, the JACK configuration, audio codec and -directory locations can be customized to meet the requirements of your -environment. +[FLAC](https://xiph.org/flac/) format. + +A separate recording-handler will move the finished recordings from the +`/var/lib/rotter/raar` directory to a final RAAR import directory. It also +determines the recording duration with the help of +[`ffprobe`](http://www.ffmpeg.org/ffprobe.html) and adds it to the recording +file name in the [ISO 8601 duration +format](https://en.wikipedia.org/wiki/ISO_8601#Durations) in seconds. + +A final recording file will be named according to `YYYY-MM-DDThhmmss±hhmm_PTsS.flac` (such as `2019-11-30T170000+0100_PT3600S.flac`). + +Of course, the JACK configuration, audio codec and directory locations can be +customized to meet the requirements of your environment. Also note, that the deployment was tested on [CentOS 7](#deployment-on-centos-7-systems), but should work on [other @@ -36,8 +44,9 @@ modifications). ### Deployment on CentOS 7 systems There are pre-built binary packages for CentOS 7 available from [Fedora EPEL](https://fedoraproject.org/wiki/EPEL) (jack) and [RaBe -APEL](https://build.opensuse.org/project/show/home:radiorabe:audio) (rotter), -which can be installed as follows: +APEL](https://build.opensuse.org/project/show/home:radiorabe:audio) (rotter) +and [Nux Dextop](http://li.nux.ro/repos.html) (ffprobe from ffmpeg), which can +be installed as follows: ```bash # Add Fedora EPEL repository yum install epel-release @@ -45,10 +54,14 @@ yum install epel-release # Add RaBe APEL repository curl -o /etc/yum.repos.d/home:radiorabe:audio.repo \ http://download.opensuse.org/repositories/home:/radiorabe:/audio/CentOS_7/home:radiorabe:audio.repo + +# Add Nux Dextop repository +rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm # Install rotter (which will also install "jack-audio-connection-kit" and -# "jack-audio-connection-kit-example-clients") -yum install rotter +# "jack-audio-connection-kit-example-clients") as well as the ffprobe command +# from the ffmpeg package. +yum install rotter ffmpeg ``` Install the [raar jackd systemd service instance @@ -236,18 +249,33 @@ ls -la /var/lib/rotter/raar total 717844 drwxr-xr-x. 2 rotter rotter 4096 Feb 6 16:59 . drwxr-xr-x. 3 rotter rotter 17 Feb 6 15:45 .. --rw-r--r--. 1 rotter rotter 120309610 Feb 6 16:00 2018-02-06T154512+0100_60.flac --rw-r--r--. 1 rotter rotter 230000737 Feb 6 16:28 2018-02-06T160000+0100_60.flac --rw-r--r--. 1 rotter rotter 250600686 Feb 6 16:59 2018-02-06T162851+0100_60.flac --rw-r--r--. 1 rotter rotter 127717296 Feb 6 17:16 2018-02-06T170000+0100_60.flac +-rw-r--r--. 1 rotter rotter 120309610 Feb 6 16:00 2018-02-06T154512+0100.flac +-rw-r--r--. 1 rotter rotter 230000737 Feb 6 16:28 2018-02-06T160000+0100.flac +-rw-r--r--. 1 rotter rotter 250600686 Feb 6 16:59 2018-02-06T162851+0100.flac +-rw-r--r--. 1 rotter rotter 127717296 Feb 6 17:16 2018-02-06T170000+0100.flac ``` #### RAAR Record Handler The [RAAR Record Handler](bin/raar-record-handler.sh) will move the finished recordings from the `/var/lib/rotter/raar` directory to a final RAAR import -directory (`IMPORT_DIRECTORIES`) for the [RAAR Importer](import.md) to pick -them up. +directory (`IMPORT_DIRECTORIES`) waiting for the [RAAR Importer](import.md) to +pick them up. + +The record handler also determines the recording duration with the help of +[`ffprobe`](http://www.ffmpeg.org/ffprobe.html) and adds it to the recording +file name in the [ISO 8601 duration +format](https://en.wikipedia.org/wiki/ISO_8601#Durations) in seconds. + +For example, a one hour (3600 seconds) rotter recording file +`/var/lib/rotter/raar/2019-11-30T170000+0100.flac` will be renamed and moved to +`/var/tmp/raar/import/2019-11-30T170000+0100_PT3600S.flac` + +##### RAAR Record Handler installation +Install `ffmpeg` (required for +[`ffprobe`](https://www.ffmpeg.org/ffprobe.html)) from the packages provided by +your distribution or [compile it from +source](https://www.ffmpeg.org/download.html). Install the [RAAR Record Handler](bin/raar-record-handler.sh) and its corresponding systemd service unit @@ -360,6 +388,14 @@ RAAR Record Handler: journalctl -u raar-record-handler.service -f ``` +* Duration of recording file in seconds + ```bash + ffprobe -i RECORDING-FILENAME \ + -show_entries format="duration" \ + -print_format csv="print_section=0" \ + -v quiet + ``` + ## Links * [Jack Audio Connection Kit](http://www.jackaudio.org/) * [Rotter](https://www.aelius.com/njh/rotter/) @@ -367,3 +403,4 @@ RAAR Record Handler: Rotter](https://github.com/radiorabe/centos-rpm-rotter) * [Jack and Rotter Systemd service unit templates explained](https://github.com/radiorabe/centos-rpm-rotter#systemd-service-unit-templates-explained) +* [ffprobe](https://www.ffmpeg.org/ffprobe.html)