-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffrec
More file actions
executable file
·107 lines (91 loc) · 5.05 KB
/
ffrec
File metadata and controls
executable file
·107 lines (91 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
if pidof ffmpeg
then
sleep 3
killall ffmpeg
notify-send -a "${0##*/}" 'Stopped Recording!' --icon=dialog-information
else
option=$(printf "%s\n%s\n%s" "rectangle" "window" "gif" | dmenu -i -p "🔴 Recording Option")
[ -z "$option" ] && exit
time=$(date +%y%b%d%H%M%S)
case $option in
-w|window)
wininfo=$(xwininfo)
width=$(printf "%s" "$wininfo" | awk '/Width/' | grep -oP "\d\d?\d?\d?\d?")
height=$(printf "%s" "$wininfo" | awk '/Height/' | grep -oP "\d\d?\d?\d?\d?")
xpos=$(printf "%s" "$wininfo" | awk '/Absolute/ && /X:/' | grep -oP "\d\d?\d?\d?\d?")
ypos=$(printf "%s" "$wininfo" | awk '/Absolute/ && /Y:/' | grep -oP "\d\d?\d?\d?\d?")
notify-send -a "${0##*/}" 'Started Recording!' --icon=dialog-information
ffmpeg -probesize 20M -f x11grab -s "$width"x"$height" -fflags +genpts -re \
-framerate 60 -threads 0 -thread_queue_size 1024 -i "$DISPLAY".0+"$xpos","$ypos" \
-f pulse -i 'alsa_output.pci-0000_00_0e.0.analog-stereo.monitor' -pix_fmt yuv420p -vsync 1 \
-vcodec libx264 -crf 28 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" \
-c:a aac -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" \
-tune film -qp 18 -preset ultrafast -g 15 -f mp4 -x264opts no-scenecut \
-map 0:v:0 -map 1:a \
~/Videos/recording-"$time".mp4
notify-send -a "${0##*/}" "Done Processing Video"
# -f pulse -i 'alsa_output.pci-0000_00_0e.0.analog-stereo.monitor' \
# -c:a aac -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" \
# -map 0:v:0 -map 1:a \
# notify-send -a "${0##*/}" "Processing Video"
# ffmpeg -i ~/Videos/.tmp-recording-$time.ts \
# -c:v copy -c:a copy -avoid_negative_ts make_zero \
# -shortest -movflags +faststart -bsf:a aac_adtstoasc -f mp4 \
# ~/Videos/recording-$time.mp4
# rm ~/Videos/.tmp-recording-$time.ts
# notify-send -a "${0##*/}" "Done Processing Video"
;;
-g|gif)
slop=$(slop -f "%x %y %w %h")
read -r X Y W H < <(printf "%s\n" "$slop")
# only start recording if we give a width (e.g we press escape to get out of slop - don't record)
width=${#W}
if [ "$width" -gt 0 ];
then
notify-send -a "${0##*/}" 'Started Recording!' --icon=dialog-information
# records without audio input
# for audio add "-f alsa -i pulse" to the line below (at the end before \, without "")
vidTempFile=".temp-$time.mp4"
ffmpeg -probesize 20M -f x11grab -s "$W"x"$H" -framerate 60 -thread_queue_size 512 -i "$DISPLAY".0+"$X","$Y" \
-pix_fmt yuv420p -y -vcodec libx264 -qp 18 -preset ultrafast -tune film -g 30 -crf 28 \
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" \
~/Videos/.temp-video.mp4
printf "%s" "$vidTempFile"
notify-send -a "${0##*/}" "Processing Video"
ffmpeg -i ~/Videos/.temp-video.mp4 \
-vf "fps=30,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
~/Videos/recording-"$time".gif
rm ~/Videos/.temp-video.mp4
notify-send -a "${0##*/}" "Done Processing Video"
fi
;;
*)
slop=$(slop -f "%x %y %w %h")
read -r X Y W H < <(printf "%s\n" "$slop")
# only start recording if we give a width (e.g we press escape to get out of slop - don't record)
width=${#W}
if [ "$width" -gt 0 ];
then
notify-send -a "${0##*/}" 'Started Recording!' --icon=dialog-information
# records without audio input
# for audio add "-f alsa -i pulse" to the line below (at the end before \, without "")
ffmpeg -probesize 20M -f x11grab -s "$W"x"$H" \
-framerate 60 -thread_queue_size 1024 -i "$DISPLAY".0+"$X","$Y" \
-f pulse -i 'alsa_output.pci-0000_00_0e.0.analog-stereo.monitor' -pix_fmt yuv420p -vsync 1 \
-vcodec libx264 -crf 28 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" \
-tune film -qp 18 -preset ultrafast -g 30 -x264opts no-scenecut \
-c:a aac -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" \
-map 0:v:0 -map 1:a \
~/Videos/.tmp-recording-"$time".ts
notify-send -a "${0##*/}" "Processing Video"
ffmpeg -i ~/Videos/.tmp-recording-"$time".ts \
-c:v copy -c:a copy -avoid_negative_ts make_zero \
-shortest -movflags +faststart -bsf:a aac_adtstoasc -f mp4 \
~/Videos/recording-"$time".mp4
rm ~/Videos/.tmp-recording-"$time".ts
notify-send -a "${0##*/}" "Done Processing Video"
fi
;;
esac
fi