Video Recorder (VHS, webcam, monitor, etc)

Video recorder which uses ffmpeg, pulseaudio, yad and xterm programs. It is very useful for recording VHS-videos. Read also:

https://puolanka.info/goto/vhs-capturing-using-ffmpeg/

VIDEO-RECORDER-pulseaudio2.zip

#!/bin/bash
#
# RJP 29.1.2025 VHS or video camera recorder
# Packages YAD, XTERM, PULSEAUDIO and FFMPEG must be installed
#
# 30.1.2025 Message dialog changed as yad dialog
arecord -L > /tmp/adevice-full.txt
AUDIO=$(/tmp/adevice-full.txt)
choose=$(cat /tmp/adevice-full.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="audio $AUDIO")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $2}' > /tmp/audiodevice
cat /tmp/audiodevice | sed 's/^.//' > /tmp/audiodevice3
sed 's/.$//' /tmp/audiodevice3 > /tmp/audiodevice4
sed 's/.$//' /tmp/audiodevice4 > /tmp/audiodevice5
sed 's/.$//' /tmp/audiodevice5 > /tmp/audiodevice.txt
#
ls /dev/video* > /tmp/video.txt
VIDEO=$(/tmp/video.txt)
choose=$(cat /tmp/video.txt | \
yad --list --text="Choose video device" --title="Choose video device" --height=500 --width=600 --center \
--column="video $VIDEO")
--button=Exit:1
cat "$choose" 2> /tmp/videodevice1.txt
cat /tmp/videodevice1.txt | awk '{print $2}' > /tmp/videodevice2
cat /tmp/videodevice2 | sed 's/^.//' > /tmp/videodevice3
sed 's/.$//' /tmp/videodevice3 > /tmp/videodevice4
sed 's/.$//' /tmp/videodevice4 > /tmp/videodevice5
sed 's/.$//' /tmp/videodevice5 > /tmp/videodevice.txt
#
time=$(date "+%F-%H-%M-%S")
#
yad --center --width=300 --height=100 --text-align=center --text="Record video"
if [ $? = 0 ];
then
xterm -e "ffmpeg -fflags nobuffer -f $(cat /tmp/audiodevice.txt) -i default -f video4linux2 -i $(cat /tmp/videodevice.txt) -framerate 25 -b:v 2000k -s 700x480 video$time.avi" & \
#
# Message if ffmpeg is running or not
#
sleep 2 && (ps -ef|grep -v grep|grep ffmpeg >/dev/null && echo "ffmpeg is running ... stop recording closing the Terminal. You can close this message" || echo "ffmpeg is not running, you probably has the wrong audio or video device. You can close this message") > /tmp/message.txt
yad --center --width=700 --height=200 --text-align=center --text="INFO: $(cat /tmp/message.txt)"
#
# Stop recording via yad dialog
#
yad --center --width=300 --height=100 --text-align=center --text="Stop Recording"
if [ $? = 0 ];
then
killall --user $USER --ignore-case --signal INT ffmpeg
else exit 2
fi
fi
sleep 1
rm /tmp/audio2.txt /tmp/adevice.txt /tmp/audiodevice3 /tmp/audiodevice4 /tmp/audiodevice4 /tmp/audiodevice.txt /tmp/video.txt /tmp/videodevice1.txt /tmp/videodevice2 /tmp/videodevice3 /tmp/videodevice4 /tmp/videodevice5 /tmp/videodevice.txt

########################################

VIDEO-RECORDER-alsa

In some hardware alsa can be better option than pulseaudio, but it probably need more testing. More info from ffmpeg with alsa can found from https://trac.ffmpeg.org/wiki/Capture/ALSA

VIDEO-RECORDER-alsa.zip

#!/bin/bash
#
# RJP 29.1.2025 VHS or video camera recorder
# Packages YAD, XTERM and FFMPEG must be installed
#
# 30.1.2025 Message dialog changed as yad dialog
# see alsa ffmpeg options from https://trac.ffmpeg.org/wiki/Capture/ALSA
#
cat /proc/asound/cards | cut -d":" -f1 -s > /tmp/adevice.txt
AUDIO=$(/tmp/adevice.txt)
choose=$(cat /tmp/adevice.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="audio $AUDIO")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $3}' > /tmp/audiodevice.txt

ls /dev/video* > /tmp/video.txt
VIDEO=$(/tmp/video.txt)
choose=$(cat /tmp/video.txt | \
yad --list --text="Choose video device" --title="Choose video device" --height=500 --width=600 --center \
--column="video $VIDEO")
--button=Exit:1
cat "$choose" 2> /tmp/videodevice1.txt
cat /tmp/videodevice1.txt | awk '{print $2}' > /tmp/videodevice2
cat /tmp/videodevice2 | sed 's/^.//' > /tmp/videodevice3
sed 's/.$//' /tmp/videodevice3 > /tmp/videodevice4
sed 's/.$//' /tmp/videodevice4 > /tmp/videodevice5
sed 's/.$//' /tmp/videodevice5 > /tmp/videodevice.txt

time=$(date "+%F-%H-%M-%S")

yad --center --width=300 --height=100 --text-align=center --text="Record video"
if [ $? = 0 ];
then
xterm -e "ffmpeg -fflags nobuffer -f alsa -i hw:$(cat /tmp/audiodevice.txt) -f video4linux2 -i $(cat /tmp/videodevice.txt) -framerate 25 -b:v 2000k -b:a 40k -s 700x480 video$time.avi" & \
#
# Message if ffmpeg is running or not
#
sleep 2 && (ps -ef|grep -v grep|grep ffmpeg >/dev/null && echo "ffmpeg is running ... stop recording closing the Terminal. You can close this message" || echo "ffmpeg is not running, you probably has the wrong audio or video device. You can close this message") > /tmp/message.txt
yad --center --width=700 --height=200 --text-align=center --text="INFO: $(cat /tmp/message.txt)"
#
# Stop recording via yad dialog
#
yad --center --width=300 --height=100 --text-align=center --text="Stop Recording"
if [ $? = 0 ];
then
killall --user $USER --ignore-case --signal INT ffmpeg
else exit 2
fi
fi
sleep 1
rm /tmp/audio2.txt /tmp/adevice.txt /tmp/audiodevice.txt /tmp/video.txt /tmp/videodevice1.txt /tmp/videodevice2 /tmp/videodevice3 /tmp/videodevice4 /tmp/videodevice5 /tmp/videodevice.txt

########################################

VIDEO-RECORDER-mpv

VIDEO-RECORDER-mpv.zip

#!/bin/bash
#
# RJP 31.1.2025 VHS or video camera recorder
# Packages YAD, XTERM, MPV, PULSEAUDIO and FFMPEG must be installed
#
#
time=$(date "+%F-%H-%M-%S")
arecord -L > /tmp/adevice-full.txt
AUDIO=$(/tmp/adevice-full.txt)
choose=$(cat /tmp/adevice-full.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="audio $AUDIO")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $2}' > /tmp/audiodevice
cat /tmp/audiodevice | sed 's/^.//' > /tmp/audiodevice3
sed 's/.$//' /tmp/audiodevice3 > /tmp/audiodevice4
sed 's/.$//' /tmp/audiodevice4 > /tmp/audiodevice5
sed 's/.$//' /tmp/audiodevice5 > /tmp/audiodevice.txt
#
ls /dev/video* > /tmp/video.txt
VIDEO=$(/tmp/video.txt)
choose=$(cat /tmp/video.txt | \
yad --list --text="Choose video device" --title="Choose video device" --height=500 --width=600 --center \
--column="video $VIDEO")
--button=Exit:1
cat "$choose" 2> /tmp/videodevice1.txt
cat /tmp/videodevice1.txt | awk '{print $2}' > /tmp/videodevice2
cat /tmp/videodevice2 | sed 's/^.//' > /tmp/videodevice3
sed 's/.$//' /tmp/videodevice3 > /tmp/videodevice4
sed 's/.$//' /tmp/videodevice4 > /tmp/videodevice5
sed 's/.$//' /tmp/videodevice5 > /tmp/videodevice.txt
yad --center --width=300 --height=100 --text-align=center --text="Record video"
if [ $? = 0 ];
then
xterm -e "mpv --ao=$(cat /tmp/audiodevice.txt) --stream-record=video$time.avi $(cat /tmp/videodevice.txt)" & \
sleep 10 && (ps -ef|grep -v grep|grep xterm >/dev/null && echo "Recording is running ... stop recording closing the MPV player. You can close this message" || echo "Recording is not running, you probably has the wrong audio or video device. You can close this message") > /tmp/message.txt
yad --center --width=700 --height=200 --text-align=center --text="INFO: $(cat /tmp/message.txt)"
#
#
# Stop recording via yad dialog
#
yad --center --width=300 --height=100 --text-align=center --text="Stop Recording"
if [ $? = 0 ];
then
killall --user $USER --ignore-case --signal INT mpv
else exit 2
fi
fi
sleep 1
rm /tmp/audio2.txt /tmp/adevice.txt /tmp/audiodevice3 /tmp/audiodevice4 /tmp/audiodevice4 /tmp/audiodevice.txt /tmp/video.txt /tmp/videodevice1.txt /tmp/videodevice2 /tmp/videodevice3 /tmp/videodevice4 /tmp/videodevice5 /tmp/videodevice.txt