#!/bin/bash
#
# RJP 24.6.2026 FFPIPE-desktop-recorder
# Packages YAD, XTERM, MPV, TASK-PIPEWIRE, WIREPLUMBER and FFMPEG must be installed
# 
# 

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


yad --center --width=500 --height=50 --text-align=center --title=$"Recording video" --button="RECORD VIDEO":0 --button=ABORT:1 --text="INSTRUCTION:
	
When recording video, minimize these messages and Terminal output if you do not want them to see into video"
#
if [ $? = 0 ]
then
rm -f /tmp/video.avi
rm -f /tmp/audio.flac
sleep 1
xterm -hold -e "ffmpeg -threads 1 -f x11grab -video_size $(xdpyinfo | grep 'dimensions:' | awk '{print $2;}') -i :0 -c:v libx264rgb -crf 0 -preset ultrafast video.avi | pw-record -P '{ stream.capture.sink=true }' /tmp/audio.flac"  & \

# Debug mode
#sleep 1 && (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 --title=$"ffmpeg is running" --text-align=center --button=OK:0 --text="INFO: $(cat /tmp/message.txt)"
#sleep 2
#pkill yad
#sleep 0,2
#
# Stop recording via yad dialog
#
yad --center --width=500 --height=50 --text-align=center --title=$"Stop recording video" --button="STOP RECORDING":0 --text="INSTRUCTION:

ffmpeg is running and you can stop recording pressing OK.  An altenative way to abort recording to stop it via Terminal using command 

pkill ffmpeg
pkill pw-record

Minimize this message during a recording"
if [ $? = 0 ];
then
killall --user $USER --ignore-case --signal INT ffmpeg
pkill pw-record
sleep 2
ffmpeg -i video.avi -i /tmp/audio.flac -map 0:v -map 1:a -c copy FFPIPE-video-$time.avi
else 
exit 0
fi
fi
sleep 90
cd /tmp && rm message.txt video.avi audio.flac
