2 # WARNING: This is a terribly dirty and messy shellscript, written over a couple of late nights
4 # You probably need to install all the gstreamer-plugins (at least -ugly and -ffmpeg) to get this to work
5 # I wanted to make mp4 with x264, I didn't bother with free codecs
7 # This script allows you to create screencasts on Linux, with optional sound inputs (both Mic and system sounds)
8 # You also get to choose to record from the whole screen or just a specified window. It has only been tested
11 # Written by Einar Jørgen Haraldseid (http://einar.slaskete.net)
12 # License: http://sam.zoy.org/wtfpl/COPYING
14 # Get device names and pretty names for playback sinks:
15 PLAYSINKLIST
=$
(pacmd list-sinks |
grep -e "name: " -e "device.description = " | cut
-d " " -f "2-" |
sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g")
17 # Display playback monitor chooser
18 PLAYMON
=$
(echo "${PLAYSINKLIST}
20 Don't capture system sounds" | zenity
--list --title "Choose Output Device" --text "Choose a sound device to capture system sound from:" --column "device" --column "Name" --print-column=1 --hide-column=1 2>/dev
/null
)
22 if [ -z ${PLAYMON} ]; then
23 echo "No choice made on output device, assuming cancel."
27 if [ ${PLAYMON} != "none" ]; then
28 # Unmute monitor of the playback sink (if set):
29 PLAYMON
="${PLAYMON}.monitor"
31 pacmd set-source-mute
${PLAYMON} false
>/dev
/null
34 # Get device names and pretty names for microphones:
35 MICLIST
=$
(pacmd list-sources |
grep -e "name: " -e "device.description = " |
grep -v -i "monitor" | cut
-d " " -f "2-" |
sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g")
37 # Display device chooser
38 MIC
=$
(echo "${MICLIST}
40 Don't use a microphone" | zenity
--list --title "Choose Microphone" --text "Choose a microphone to capture voice from:" --column "device" --column "Name" --print-column=1 --hide-column=1 2>/dev
/null
)
42 if [ -z ${MIC} ]; then
43 echo "No choice made on microphone, assuming cancel."
47 # Get target window for recording:
51 Specific window" | zenity
--list --title "Choose recording mode" --text "Do you want to record the whole screen, or record a specific window?" --column "target" --column "Mode" --print-column=1 --hide-column=1 2>/dev
/null
)
53 if [ -z ${TARGET} ]; then
54 echo "No choice for recording target, assuming cancel."
58 if [ ${TARGET} = "root" ]; then
60 XWININFO
=$
(xwininfo
-root)
66 # Get Window ID and dimensions, make sure dimensions are divisible by two, or else the encoder will fail
67 WID
=$
(echo "${XWININFO}" |
grep "Window id:" |
awk '{print $4}')
68 WIDTH
=$
(echo "${XWININFO}" |
grep "Width: " | cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
69 HEIGHT
=$
(echo "${XWININFO}" |
grep "Height: " | cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
71 # Calculate a suitable bitrate based on window dimensions
72 BITRATE
=$
(echo "${WIDTH} * ${HEIGHT} * 0.006" |
bc | cut
-d "." -f 1 )
74 # Enable inputs as suitable
75 if [ ${PLAYMON} != "none" ]; then
76 MONITORARG
="pulsesrc device=${PLAYMON} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux."
78 if [ ${MIC} != "none" ]; then
79 MICARG
="pulsesrc device=${MIC} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux."
83 gst-launch
-e ximagesrc xid
="${WID}" do-timestamp
=1 use-damage
=0 ! video
/x-raw-rgb
,framerate
=30/1 \
84 ! ffmpegcolorspace
! videoscale method
=0 ! video
/x-raw-yuv
,width
=${WIDTH},height
=${HEIGHT} \
85 ! x264enc speed-preset
=ultrafast bitrate
=${BITRATE} ! queue2 \
86 ! mp4mux name
="mux" ! filesink location
="output.mp4" $MONITORARG $MICARG