4520980cca64357042ee37eae9d9037f5e33a6f8
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
5 # to work. I wanted to make mp4 with x264, I didn't bother with free codecs.
7 # So this script allows you to create screencasts on Linux, with optional sound inputs (both Mic
8 # and system sounds). It stores system sounds and mic in separate audio streams.
9 # You also get to choose to record from the whole screen or just a specified window. It has only
10 # been tested on Fedora 18.
12 # It dumps the recording in your $HOME directory with filename screencast-YYYY-MM-DD-HH-MM-SS.mp4
14 # Written by Einar Jørgen Haraldseid (http://einar.slaskete.net)
15 # License: http://sam.zoy.org/wtfpl/COPYING
17 # Get device names and pretty names for playback sinks:
18 PLAYSINKLIST
=$
(pacmd list-sinks |
grep -e "name: " -e "device.description = " | cut
-d " " -f "2-" |
sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g")
20 # Display playback monitor chooser
21 PLAYMON
=$
(echo "${PLAYSINKLIST}
23 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
)
25 if [ -z ${PLAYMON} ]; then
26 echo "No choice made on output device, assuming cancel."
30 if [ ${PLAYMON} != "none" ]; then
31 # Unmute monitor of the playback sink (if set):
32 PLAYMON
="${PLAYMON}.monitor"
34 pacmd set-source-mute
${PLAYMON} false
>/dev
/null
37 # Get device names and pretty names for microphones:
38 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")
40 # Display device chooser
41 MIC
=$
(echo "${MICLIST}
43 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
)
45 if [ -z ${MIC} ]; then
46 echo "No choice made on microphone, assuming cancel."
50 # Get target window for recording:
54 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
)
56 if [ -z ${TARGET} ]; then
57 echo "No choice for recording target, assuming cancel."
61 if [ ${TARGET} = "root" ]; then
63 XWININFO
=$
(xwininfo
-root)
69 # Get Window ID and dimensions, make sure dimensions are divisible by two, or else the encoder will fail
70 WID
=$
(echo "${XWININFO}" |
grep "Window id:" |
awk '{print $4}')
71 WIDTH
=$
(echo "${XWININFO}" |
grep "Width: " | cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
72 HEIGHT
=$
(echo "${XWININFO}" |
grep "Height: " | cut
-d ":" -f 2 |
awk '{print $1+$1%2}')
74 # Calculate a suitable bitrate based on window dimensions
75 BITRATE
=$
(echo "${WIDTH} * ${HEIGHT} * 0.006" |
bc | cut
-d "." -f 1 )
78 FILENAME
="screencast-$(date +%F-%H-%M-%S).mp4"
80 # Enable inputs as suitable
81 if [ ${PLAYMON} != "none" ]; then
82 MONITORARG
="pulsesrc device=${PLAYMON} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux."
84 if [ ${MIC} != "none" ]; then
85 MICARG
="pulsesrc device=${MIC} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux."
89 gst-launch
-e ximagesrc xid
="${WID}" do-timestamp
=1 use-damage
=0 ! video
/x-raw-rgb
,framerate
=30/1 \
90 ! ffmpegcolorspace
! videoscale method
=0 ! video
/x-raw-yuv
,width
=${WIDTH},height
=${HEIGHT} \
91 ! x264enc speed-preset
=ultrafast bitrate
=${BITRATE} ! queue2 \
92 ! mp4mux name
="mux" ! filesink location
="${HOME}/${FILENAME}" $MONITORARG $MICARG