Add region screen recording (#791)
* Add region screen recording * Update readme * Use get-default-sink and software encoding Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com> * Remove log file creation logic Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com> --------- Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Requires wf-recorder: https://github.com/ammen99/wf-recorder
|
||||
|
||||
outputDir="$HOME/Videos/Screencasts"
|
||||
defaultSink=$(pactl get-default-sink)
|
||||
WF_RECORDER_OPTS="--audio=$defaultSink.monitor -c libx264rgb"
|
||||
|
||||
checkRecording() {
|
||||
if pgrep -f "gpu-screen-recorder" >/dev/null; then
|
||||
if pgrep -f "wf-recorder" >/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@@ -18,24 +21,24 @@ startRecording() {
|
||||
|
||||
target="$2"
|
||||
|
||||
outputFile="recording_$(date +%Y-%m-%d_%H-%M-%S).mp4"
|
||||
outputPath="$outputDir/$outputFile"
|
||||
outputFile="recording_$(date +%Y-%m-%d_%H-%M-%S)"
|
||||
outputPath="$outputDir/${outputFile}.mp4"
|
||||
mkdir -p "$outputDir"
|
||||
|
||||
if [ -z "$target" ]; then
|
||||
echo "Usage: $0 start screen [screen_name]"
|
||||
if [ "$target" == "screen" ]; then
|
||||
monitor_info=$(hyprctl -j monitors | jq -r ".[] | select(.name == \"$3\")")
|
||||
w=$(echo $monitor_info | jq -r '.width')
|
||||
h=$(echo $monitor_info | jq -r '.height')
|
||||
x=$(echo $monitor_info | jq -r '.x')
|
||||
y=$(echo $monitor_info | jq -r '.y')
|
||||
wf-recorder $WF_RECORDER_OPTS --geometry "${x},${y} ${w}x${h}" --file "$outputPath" &
|
||||
elif [ "$target" == "region" ]; then
|
||||
wf-recorder $WF_RECORDER_OPTS --geometry "$(slurp)" --file "$outputPath" &
|
||||
else
|
||||
echo "Usage: $0 start {region|screen [screen_name]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GPU_TYPE=$(lspci | grep -E 'VGA|3D' | grep -Ev '00:02.0|Integrated' >/dev/null && echo "" || echo "-encoder cpu")
|
||||
|
||||
gpu-screen-recorder \
|
||||
-w "$target" \
|
||||
-f 60 \
|
||||
-k h264 \
|
||||
-a "$(pactl get-default-sink).monitor" \
|
||||
-o "$outputPath" \
|
||||
$GPU_TYPE &
|
||||
disown "$(jobs -p | tail -n 1)"
|
||||
|
||||
echo "Recording started. Output will be saved to $outputPath"
|
||||
}
|
||||
@@ -46,7 +49,7 @@ stopRecording() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pkill -SIGINT -f gpu-screen-recorder
|
||||
pkill -SIGINT -f wf-recorder
|
||||
|
||||
recentFile=$(ls -t "$outputDir"/recording_*.mp4 | head -n 1)
|
||||
|
||||
@@ -74,7 +77,7 @@ status)
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start [screen_name|window_id]|stop|status}"
|
||||
echo "Usage: $0 {start [screen screen_name|region]|stop|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user