From 88ddc45bff0979a0593663a1f9b8572c1e9d7e9e Mon Sep 17 00:00:00 2001
From: Karchnu <karchnu@karchnu.fr>
Date: Wed, 8 Dec 2021 20:18:53 +0100
Subject: [PATCH] Recording scripts.

---
 recording/camera.sh                 | 14 ++++++++++
 recording/record-audio-and-video.sh |  5 ++++
 recording/record-audio.sh           |  3 +++
 recording/record-video.sh           |  3 +++
 recording/sync.sh                   | 42 +++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+)
 create mode 100755 recording/camera.sh
 create mode 100755 recording/record-audio-and-video.sh
 create mode 100755 recording/record-audio.sh
 create mode 100755 recording/record-video.sh
 create mode 100644 recording/sync.sh

diff --git a/recording/camera.sh b/recording/camera.sh
new file mode 100755
index 0000000..8a3a572
--- /dev/null
+++ b/recording/camera.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+brightness=0.07
+saturation=1.8
+
+if [ $# -eq 2 ]; then
+	brightness=$1
+	saturation=$2
+fi
+
+echo "brightness = $brightness"
+echo "saturation = $saturation"
+
+ffplay -loglevel error -f v4l2 -input_format mjpeg -vf eq=brightness=$brightness:saturation=$saturation -video_size 640x480 /dev/video1
diff --git a/recording/record-audio-and-video.sh b/recording/record-audio-and-video.sh
new file mode 100755
index 0000000..ffebf73
--- /dev/null
+++ b/recording/record-audio-and-video.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# This doesn't work as intended on my very limited computer.
+# Too CPU intensive.
+ffmpeg -y -loglevel error -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 -f sndio -i snd/0 $@
diff --git a/recording/record-audio.sh b/recording/record-audio.sh
new file mode 100755
index 0000000..37638c0
--- /dev/null
+++ b/recording/record-audio.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+ffmpeg -y -loglevel error -f sndio -i snd/0 -ac 1 $@
diff --git a/recording/record-video.sh b/recording/record-video.sh
new file mode 100755
index 0000000..8fcd289
--- /dev/null
+++ b/recording/record-video.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+ffmpeg -y -loglevel error -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 $@
diff --git a/recording/sync.sh b/recording/sync.sh
new file mode 100644
index 0000000..d5db35f
--- /dev/null
+++ b/recording/sync.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# This is a list of simple shell functions to handle a few inconveniences
+# regarding video and audio synchronization.
+
+# When recording a mono source as a stereo, one of the speaker is muted.
+# This removes the second (muted) track from the audio source.
+stereo2mono(){
+	/usr/bin/ffmpeg -i "$1" -c:v copy -ac 1 "mono-$1"
+}
+
+# Side note: I record both audio and video with the same file names, besides the extension.
+please_read(){
+	/usr/bin/mpv "$1.mkv" -audiofile "$1.opus"
+}
+
+# Synchronize the audio and video.
+avsync(){
+
+	if [ $# -ne 4 ]; then
+		echo "usage: avsync video audio delay output"
+		return 1
+	fi
+
+	/usr/bin/ffmpeg -i "$1" \
+		-itsoffset "$3" \
+		-i "$2" \
+		-c:a copy -c:v copy -map 0:v:0 -map 1:a:0 \
+		"$4"
+
+}
+
+# Video and audio have the same name, except for the extension.
+# Example: avs my-video 1.3
+avs(){
+	if [ $# -ne 2 ]; then
+		echo "usage: avs prefix delay"
+		return 1
+	fi
+
+	avsync "$1".mkv "$1".opus "$2" "$1"-sync.mkv
+}