debloat slightly, add wayland support using wf-recorder
This commit is contained in:
parent
65f365733d
commit
bcac3fbca8
|
@ -11,7 +11,34 @@
|
|||
[ -z "$NOMKCONFIG" ] && NOMKCONFIG=false
|
||||
[ -z "$HAVEGRID" ] && HAVEGRID=true
|
||||
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
|
||||
[ "$1" = "-s" ] && pkill -x ffmpeg && rm -f /tmp/dfmpeg-recording && STATUS=idle && exit
|
||||
|
||||
KILL_REC() {
|
||||
pgrep -x ffmpeg > /dev/null && pkill ffmpeg
|
||||
pgrep -x wf-recorder > /dev/null && pkill -2 wf-recorder
|
||||
}
|
||||
|
||||
CHECK_SESSION() {
|
||||
if [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
[ ! -x "$(command -v wf-recorder)" ] && printf "wf-recorder not found\n" && exit 1
|
||||
session="wayland"
|
||||
elif [ -n "$DISPLAY" ]; then
|
||||
[ ! -x "$(command -v ffmpeg)" ] && printf "ffmpeg not found\n" && exit 1
|
||||
session="x11"
|
||||
else
|
||||
printf "no display server found\n" && exit 1
|
||||
fi
|
||||
|
||||
[ ! -x "$(command -v "$RUNLAUNCHER")" ] && printf "no run launcher found\n" && exit 1
|
||||
}
|
||||
|
||||
CHECK_SESSION
|
||||
|
||||
# -s option stops the recording
|
||||
if [ "$1" = "-s" ]; then
|
||||
KILL_REC
|
||||
rm -f /tmp/dfmpeg-recording
|
||||
exit
|
||||
fi
|
||||
|
||||
mkdir -p "$DFMPEG_DOTDIR"
|
||||
|
||||
|
@ -19,19 +46,21 @@ MKCONFIG() {
|
|||
[ -e "$DFMPEG_DOTDIR/dfmpegrc" ] && . "$DFMPEG_DOTDIR/dfmpegrc" && return || \
|
||||
cat << CFGFILE > "$DFMPEG_DOTDIR/dfmpegrc"
|
||||
# dfmpeg config file
|
||||
# See https://codeberg.org/speedie/speedwm-extras for more information
|
||||
RESOLUTION="\$(xdpyinfo | awk '/dimensions/ {print \$2}')" # The resolution to record in
|
||||
AUDIO_BACKEND="pulse" # How to capture audio (alsa/pulse)
|
||||
AUDIO_DEVICE="default" # Device to capture audio from. If you're using pulseaudio, check this using pactl list short sources. Set to default to use default.
|
||||
FRAME_RATE="60" # Frame rate to capture in.
|
||||
RECORD_DEVICE="x11grab" # Probably do not change.
|
||||
# See https://git.speedie.site/speedie/speedwm-extras for more information
|
||||
OUTPUT_PATH="$HOME/Recordings" # Path where videos will be saved.
|
||||
OUTPUT_FORMAT="mp4" # What format to use
|
||||
OUTPUT_FILENAME="dfmpeg-output-"\$(date "+%d_%m_%y-%H%M%S")"" # File name of the output. Probably don't need to change.
|
||||
|
||||
# ffmpeg (X11) specific
|
||||
ENCODE=true # Encode or not (true/false)
|
||||
ENCODE_CODEC=libx264 # Codec to encode in
|
||||
ENCODE_PRESET=ultrafast # ffmpeg preset. Available options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
|
||||
WH=":0.0" # Width and height, no need to change, defaults should work.
|
||||
FRAME_RATE="60" # Frame rate to capture in.
|
||||
RECORD_DEVICE="x11grab" # Probably do not change.
|
||||
RESOLUTION="\$(xdpyinfo | awk '/dimensions/ {print \$2}')" # The resolution to record in
|
||||
AUDIO_BACKEND="pulse" # How to capture audio (alsa/pulse)
|
||||
AUDIO_DEVICE="default" # Device to capture audio from. If you're using pulseaudio, check this using pactl list short sources. Set to default to use default.
|
||||
|
||||
# Extra features
|
||||
TERM="st" # Terminal to use when editing the configuration file.
|
||||
|
@ -44,27 +73,30 @@ MKCONFIG
|
|||
|
||||
OUTPUT_FILENAME="$OUTPUT_PATH/$OUTPUT_FILENAME.$OUTPUT_FORMAT"
|
||||
|
||||
if [ "$ENCODE" = "false" ]; then
|
||||
startrec="ffmpeg -f $RECORD_DEVICE -s $RESOLUTION -i $WH -f $AUDIO_BACKEND -r $FRAME_RATE -i $AUDIO_DEVICE $OUTPUT_FILENAME"
|
||||
startrec_no_audio="ffmpeg -y -f $RECORD_DEVICE -s $RESOLUTION -r $FRAME_RATE -i $WH $OUTPUT_FILENAME"
|
||||
if [ "$ENCODE" = "false" ] && [ "$session" = "x11" ]; then
|
||||
startrec="ffmpeg -f $RECORD_DEVICE -s $RESOLUTION -i $WH -f $AUDIO_BACKEND -r $FRAME_RATE -i $AUDIO_DEVICE $OUTPUT_FILENAME"
|
||||
startrec_no_audio="ffmpeg -y -f $RECORD_DEVICE -s $RESOLUTION -r $FRAME_RATE -i $WH $OUTPUT_FILENAME"
|
||||
elif [ "$session" = "x11" ]; then
|
||||
startrec="ffmpeg -y -f x11grab -framerate $FRAME_RATE -s $RESOLUTION -i $WH -f $AUDIO_BACKEND -i $AUDIO_DEVICE -r 30 -c:v $ENCODE_CODEC -crf 0 -preset ultrafast -c:a aac $OUTPUT_FILENAME"
|
||||
startrec_no_audio="ffmpeg -y -f x11grab -framerate $FRAME_RATE -s $RESOLUTION -i $WH -r 30 -c:v $ENCODE_CODEC -crf 0 -preset ultrafast -c:a aac $OUTPUT_FILENAME"
|
||||
touch /tmp/isencoding
|
||||
echo "$ENCODE_CODEC" > /tmp/encoding-codec
|
||||
else
|
||||
startrec="ffmpeg -y -f x11grab -framerate $FRAME_RATE -s $RESOLUTION -i $WH -f $AUDIO_BACKEND -i $AUDIO_DEVICE -r 30 -c:v $ENCODE_CODEC -crf 0 -preset ultrafast -c:a aac $OUTPUT_FILENAME"
|
||||
startrec_no_audio="ffmpeg -y -f x11grab -framerate $FRAME_RATE -s $RESOLUTION -i $WH -r 30 -c:v $ENCODE_CODEC -crf 0 -preset ultrafast -c:a aac $OUTPUT_FILENAME"
|
||||
touch /tmp/isencoding
|
||||
echo "$ENCODE_CODEC" > /tmp/encoding-codec
|
||||
startrec="wf-recorder -f $OUTPUT_FILENAME -a"
|
||||
startrec_no_audio="wf-recorder -f $OUTPUT_FILENAME"
|
||||
fi
|
||||
|
||||
# Call this function to encode a video manually.
|
||||
# /tmp/rec.$OUTPUT_FORMAT must be the file. Consider copying it there and then copying it back.
|
||||
encode() {
|
||||
cp "$(cat /tmp/outputfilename)" "/tmp/rec.$OUTPUT_FORMAT"
|
||||
ffmpeg -i /tmp/rec.$OUTPUT_FORMAT -c:v $ENCODE_CODEC -preset $ENCODE_PRESET -threads 0 -b:v -pass 1 -f $OUTPUT_FORMAT -qp 0
|
||||
cp "/tmp/rec.$OUTPUT_FORMAT" "$(cat /tmp/outputfilename)"
|
||||
rm -f "/tmp/rec.$OUTPUT_FORMAT"
|
||||
cp "$(cat /tmp/outputfilename)" "/tmp/rec.$OUTPUT_FORMAT"
|
||||
ffmpeg -i /tmp/rec.$OUTPUT_FORMAT -c:v $ENCODE_CODEC -preset $ENCODE_PRESET -threads 0 -b:v -pass 1 -f $OUTPUT_FORMAT -qp 0
|
||||
cp "/tmp/rec.$OUTPUT_FORMAT" "$(cat /tmp/outputfilename)"
|
||||
rm -f "/tmp/rec.$OUTPUT_FORMAT"
|
||||
}
|
||||
|
||||
# Hardcoded version number
|
||||
dfmpeg_ver="2022-12-11-r1"
|
||||
dfmpeg_ver="2023-06-15-r1"
|
||||
about_screen="dfmpeg $dfmpeg_ver."
|
||||
|
||||
# About screen text
|
||||
|
@ -72,31 +104,6 @@ about_screen_2="Licensed under MIT, written by speedie.site and emilyd."
|
|||
about_screen_3="Modified for https://speedie.site/speedwm"
|
||||
about_screen_4="https://speedie.site/spmenu-scripts"
|
||||
|
||||
encodeopts() {
|
||||
|
||||
case "$(printf 'Encode last recording\nEncode video\n\n..\nExit' | $RUNLAUNCHER -l 40 -p 'Encoding options' -g 1)" in
|
||||
"Encode last recording") encode ; exit 0 ;;
|
||||
"Encode video") echo "$(echo "" | $RUNLAUNCHER -l 1 $GRIDARG $GRIDNUM -p "What file do you want to encode?")" > /tmp/outputfilename && encode ; exit 0 ;;
|
||||
"") exit 0 ;;
|
||||
"Exit") exit 0 ;;
|
||||
"..") $0 && exit 0 ;;
|
||||
"") exit 0 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# More options
|
||||
MORE_OPTIONS() {
|
||||
case "$(printf 'Encode\nConvert\nConfigure\n\n..\nExit' | $RUNLAUNCHER -l 40 -p 'More options' -g 1)" in
|
||||
"Encode last recording") [ "$ENCODE" != "false" ] && encode ; exit 0 ;;
|
||||
"Encode video") echo "$(echo "" | $RUNLAUNCHER -l 1 $GRIDARG $GRIDNUM -p "What file do you want to encode?")" > /tmp/outputfilename && encode ; exit 0 ;;
|
||||
"Encode") encodeopts ; exit 0 ;;
|
||||
"Configure") $TERM $EDITOR "$DFMPEG_DOTDIR/dfmpegrc" ; exit 0 ;;
|
||||
"") exit 0 ;;
|
||||
"..") $0 && exit 0 ;;
|
||||
"") exit 0 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$(printf 'Start\nStop\nStart without audio\nPlay last\n\nMore options\nAbout\nExit' | $RUNLAUNCHER -l 40 -p 'Record your screen:' -g 1)" in
|
||||
"Exit") STATUS=idle && exit 0 ;;
|
||||
"Start") touch /tmp/isaudio ; echo "$OUTPUT_FILENAME" > /tmp/outputfilename && STATUS=recording && touch /tmp/dfmpeg-recording
|
||||
|
@ -105,7 +112,7 @@ case "$(printf 'Start\nStop\nStart without audio\nPlay last\n\nMore options\n
|
|||
|
||||
exit 0 ;;
|
||||
"Stop") [ ! -e /tmp/dfmpeg-recording ] && exit 1
|
||||
pkill -x ffmpeg ; rm /tmp/dfmpeg-recording
|
||||
KILL_REC ; rm /tmp/dfmpeg-recording
|
||||
pidof dunst > /dev/null && command -v dunstctl > /dev/null && dunstctl set-paused false
|
||||
STATUS=idle
|
||||
;;
|
||||
|
@ -116,7 +123,6 @@ case "$(printf 'Start\nStop\nStart without audio\nPlay last\n\nMore options\n
|
|||
exit 0
|
||||
;;
|
||||
"Play last") DFMPEG_STATUS=idle && $MEDIA_PLAYER "$(cat /tmp/outputfilename)" && exit 0 ;;
|
||||
"More options") MORE_OPTIONS && exit 0 ;;
|
||||
"") exit 0 ;;
|
||||
"About")
|
||||
printf "$about_screen\n$about_screen_2\n$about_screen_3\n$about_screen_4\n" | $RUNLAUNCHER -l 40 $GRIDARG $GRIDNUM
|
||||
|
|
Loading…
Reference in a new issue