3 # WARNING: This is a terribly dirty and messy shellscript, written over a
4 # couple of late nights. There was alcohol …
6 # Further tweaks and porting to free codecs done one early Saturday morning
7 # in May. There was no coffee … and very little experience with vp8
9 # So this script allows you to create screencasts on Linux, with optional
10 # sound inputs (both Microphone and system sounds). It stores system sounds
11 # and microphone in separate audio streams.
13 # It dumps the recording in your $HOME directory with a filename like
14 # screencast-YYYY-MM-DD-HH-MM-SS.mp4
16 # Written by Einar Jørgen Haraldseid (http://einar.slaskete.net)
17 # License: http://sam.zoy.org/wtfpl/COPYING
19 # Get device names and pretty names for enumerating playback sinks:
20 PLAYSINKLIST
=$
(pacmd list-sinks | \
21 grep -e "name: " -e "device.description = " | cut
-d " " -f "2-" | \
22 sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g")
24 # Display playback monitor chooser
25 PLAYMON
=$
(echo "${PLAYSINKLIST}
27 Don't capture system sounds" | \
28 zenity
--list --title "Choose Output Device" \
29 --text "Choose a sound device to capture system sound from:" \
30 --column "device" --column "Name" --print-column=1 \
31 --hide-column=1 2>/dev
/null
)
34 if [ -z ${PLAYMON} ]; then
35 echo "No choice made on output device, assuming cancel."
39 if [ ${PLAYMON} != "none" ]; then
40 # Unmute monitor of the playback sink (if set):
41 PLAYMON
="${PLAYMON}.monitor"
42 pacmd set-source-mute
${PLAYMON} false
>/dev
/null
43 echo "Recording system sounds from ${PLAYMON}"
45 echo "Not recording system sounds."
48 # Get device names and pretty names for microphones:
49 MICLIST
=$
(pacmd list-sources | \
50 grep -e "name: " -e "device.description = " | \
51 grep -v -i "monitor" | cut
-d " " -f "2-" | \
52 sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g")
54 # Display device chooser
55 MIC
=$
(echo "${MICLIST}
57 Don't use a microphone" | \
58 zenity
--list --title "Choose Microphone" \
59 --text "Choose a microphone to capture voice from:" \
60 --column "device" --column "Name" --print-column=1 \
61 --hide-column=1 2>/dev
/null
)
63 if [ -z ${MIC} ]; then
64 echo "No choice made on microphone, assuming cancel."
68 if [ ${MIC} != "none" ]; then
69 echo "Recording voice from ${MIC}"
71 echo "Not recording voice."
74 # Get target window for recording:
79 zenity
--list --title "Choose recording mode" \
80 --text "Do you want to record the whole screen,\
81 or record a specific window?" --column "target" \
82 --column "Mode" --print-column=1 --hide-column=1 2>/dev
/null
)
84 if [ -z ${TARGET} ]; then
85 echo "No choice for recording target, assuming cancel."
89 if [ ${TARGET} = "root" ]; then
90 echo "Root window chosen."
91 XWININFO
=$
(xwininfo
-root)
93 echo "Custom window chosen."
97 # Get Window ID and dimensions, make sure X and Y dimensions are
98 # divisible by two, or else the encoder might fail
99 WID
=$
(echo "${XWININFO}" |
grep "Window id:" |
awk '{print $4}')
100 WIDTH
=$
(echo "${XWININFO}" |
grep "Width: " | \
101 cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
102 HEIGHT
=$
(echo "${XWININFO}" |
grep "Height: " | \
103 cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
105 # Calculate a suitable bitrate based on window dimensions
106 BITRATE
=$
(echo "${WIDTH} * ${HEIGHT} * 0.85" |
bc | cut
-d "." -f 1 )
109 FILENAME
="screencast-$(date +%F-%H-%M-%S).webm"
111 # Enable inputs as suitable
112 if [ ${PLAYMON} != "none" ]; then
113 MONITORARG
="pulsesrc device=${PLAYMON} slave-method=0 provide-clock=false \
114 ! audiorate ! audioconvert ! vorbisenc ! queue2 ! mux."
116 if [ ${MIC} != "none" ]; then
117 MICARG
="pulsesrc device=${MIC} slave-method=0 provide-clock=false \
118 ! audiorate ! audioconvert ! vorbisenc ! queue2 ! mux."
122 gst-launch-1.0
-q -e ximagesrc xid
="${WID}" do-timestamp
=1 use-damage
=0 \
123 ! video
/x-raw
,framerate
=20/1 ! videoscale method
=0 \
124 ! video
/x-raw
,width
=${WIDTH},height
=${HEIGHT} ! videoconvert \
125 ! vp8enc end-usage
=vbr cpu-used
=16 target-bitrate
=${BITRATE} \
126 deadline
=100 static-threshold
=1000 min-quantizer
=0 max-quantizer
=63 ! queue2 \
127 ! webmmux name
="mux" \
128 ! filesink location
="${HOME}/${FILENAME}" ${MONITORARG} ${MICARG}
130 echo "Recording
done, file is
${FILENAME}"