Last active
January 3, 2016 09:19
-
-
Save DennisLfromGA/8441689 to your computer and use it in GitHub Desktop.
A script to capture a 'screencast' on your Chromebook via 'crouton' (http://goo.gl/fd3zc) by David Schneider. This is a modified version of the original script 'screencast.sh' (http://goo.gl/UmWAta) by Francois Beaufort.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
## A script to capture a 'screencast' on your Chromebook via 'crouton' (http://goo.gl/fd3zc) by David Schneider. | |
#+ This is a modified version of the original script 'screencast.sh' (http://goo.gl/UmWAta) by Francois Beaufort. | |
#+ This 'screencast' modified source (and author) can be found here - (https://gist.github.com/DennisLfromGA/8441689) | |
# Needs to run in bash so do it. | |
if [ -z "$BASH_VERSION" ]; then exec bash -e "$0" "$@"; fi | |
APPLICATION="${0##*/}" | |
ARGNUM="$#" | |
CHROOT='' | |
DFLTNAME='screencast' | |
PRILOC='/var/crouton/chroots' # crispy crouton | |
ALTLOC='/usr/local/chroots' # standard crouton | |
if [ -d $PRILOC ]; then | |
CHROOTS="$PRILOC" | |
elif [ -d $ALTLOC ]; then | |
CHROOTS="$ALTLOC" | |
fi | |
if [ -d "$CHROOTS/$DFLTNAME" ]; then | |
CHROOTNAME="$DFLTNAME" | |
else | |
CHROOTNAME="$(ls -1 $CHROOTS 2>/dev/null | head -n 1)" | |
fi | |
DELAY='10' | |
if [ -d "$HOME/Extensions/pibhkhofcjfhelinjppfgdcoccedkhmm/" ]; then | |
MINIMIRROR="y" | |
else | |
MINIMIRROR='' | |
fi | |
FILENAME="${APPLICATION}-$(date +%Y%m%d-%H%M%S)" | |
VERSION='20150309200657' | |
VERHIST="\ | |
20150309200657 ## 'MiniMirror' detection and suggestion added. | |
#+ also tweaked the countdown display. | |
20150306124703 ## Added 'screencast' as default CHROOTNAME | |
20141108235808 ## Light cleanup, touchup comments, etc. | |
20141108113743 ## Removed non-functional $HOME and logging | |
#+ also enforce bash invocation. | |
20141108101455 ## Added 'crispy crouton' /var/crouton/chroots location | |
#+ and '-l' option to specify CHROOTS location | |
#+ also updated enter-chroot to add '-p ...' option | |
20140129132631 ## Added option to display instructions | |
#+ to create a new chroot if none exists. | |
20140129123043 ## Changed date format to lead with the year | |
#+ for both the file name and version number. | |
01152014162638 ## Original script (based on screencast.sh by Francois Beaufort) | |
" | |
# Helpers function to color terminal. | |
textreset=$(tput sgr0) | |
colorred=$(tput setaf 1) | |
coloryel=$(tput setaf 3) | |
colorblue=$(tput setaf 6) | |
INSTRUCTIONS=" | |
${coloryel}### You can create a new chroot like this:${textreset} | |
${colorblue}### First, download 'crouton' from: ${textreset}http://goo.gl/fd3zc | |
${colorblue}### Then open a crosh shell and enter:${textreset} | |
sudo sh ~/Downloads/crouton -p `dirname $CHROOTS` -t audio -n $DFLTNAME | |
${colorblue}### Then re-run this script: ${textreset}'sh $0 [options]' | |
" | |
if [ -z "$CHROOTNAME" ] | |
then | |
CHROOT="${colorred}None Found!${textreset}" | |
else | |
CHROOT="$CHROOTNAME" | |
fi | |
USAGE=" | |
'$APPLICATION' - A script to capture a 'screencast' on your Chromebook via crouton. | |
${colorblue}FORMAT: $APPLICATION [-d Delay] [-f File name] [-l Chroots folder] [-n Chroot name]${textreset} | |
Options: | |
-d Delay in seconds before starting the screencast - Default: '$DELAY' | |
-f Screencast file name - Default: '~/Downloads/${FILENAME}.mkv' | |
-n Chroot name - Default: '$CHROOT' ('$DFLTNAME' or alphabetically 1st chroot) | |
-l Chroots location - Default: '$CHROOTS' | |
Also: | |
-h Help - prints this usage summary and exits. | |
-i Instructions - prints instructions to create a chroot and exits. | |
-v Version - displays the current version of '$APPLICATION' and exits. | |
-V Version History - displays version history of '$APPLICATION' and exits. | |
" | |
# Function to exit with exit code $1, spitting out message $@ to stderr | |
error() { | |
local ecode="$1" | |
shift | |
echo "$*" 1>&2 | |
exit "$ecode" | |
} | |
if [ "$1" = "--help" ]; then error 0 "$USAGE"; fi | |
while getopts d:D:f:F:l:L:n:N:hHiIvV OPT; do | |
case ${OPT} in | |
[dD]) DELAY="${OPTARG}";; | |
[fF]) FILENAME="${OPTARG}";; | |
[lL]) CHROOTS="`readlink -f ${OPTARG}`";; | |
[nN]) CHROOTNAME="${OPTARG}";; | |
[hH]*) error 255 "$USAGE";; | |
[iI]*) error 255 "$INSTRUCTIONS";; | |
[v]*) error 255 "$APPLICATION version: $VERSION";; | |
[V]*) error 255 "$VERHIST";; | |
\?) error 2 "$USAGE";; | |
esac | |
done | |
shift "$((OPTIND-1))" | |
if [ -z "$CHROOTNAME" ] | |
then | |
echo "$USAGE" | |
echo "${colorred}*** No chroot found in $CHROOTS ...${textreset}" | |
error 1 "$INSTRUCTIONS" | |
elif [ ! -d $CHROOTS/$CHROOTNAME ] | |
then | |
echo "${colorred}*** Sorry, no chroot named '$CHROOTNAME' found in $CHROOTS ...${textreset}" | |
echo | |
ls $CHROOTS | |
echo | |
error 1 "${coloryel}*** Try one of the above ...${textreset}" | |
else | |
CHROOT="$CHROOTNAME" | |
fi | |
echo "${colorblue}*** Filename: '${textreset}~/Downloads/${FILENAME}.mkv${colorblue}'\ | |
- Chrootname: '${textreset}$CHROOT${colorblue}'\ | |
- Delay: '${textreset}$DELAY${colorblue}'${textreset}" | |
if [ "$ARGNUM" -le 0 ]; then read -p "Press ENTER to continue - Ctrl-C to abort "; fi | |
# Checking package requirements. | |
echo "${colorblue}### Checking requirements ...${textreset}" | |
INSTALLED_PACKAGES=$(sudo enter-chroot -c $CHROOTS -n $CHROOT -b dpkg -l | awk '{print $2}') | |
REQUIRED_PACKAGES="libav-tools libavcodec-extra-53 libavdevice-extra-53 \ | |
libavfilter-extra-2 libavformat-extra-53 libavutil-extra-51 \ | |
libpostproc-extra-52 libswscale-extra-2 x264 libx264-dev pulseaudio" | |
for package in $REQUIRED_PACKAGES; do | |
if ! echo $INSTALLED_PACKAGES | \grep -q -E "^ii $package"; then | |
echo "${colorblue}*** Installing avconv and its friends - if needed ...${textreset}" | |
sudo enter-chroot -c $CHROOTS -n $CHROOT -x sudo apt-get install -qq -y $REQUIRED_PACKAGES | |
break | |
fi | |
done | |
echo | |
echo "${coloryel}*** Now is a good time to switch to the desired window to be captured ...${textreset}" | |
echo "${coloryel}*** It's also a good time to adjust your volume or maybe even mute it ...${textreset}" | |
[ -n "$MINIMIRROR" ] && \ | |
echo "${colorblue}*** Mini Mirror is installed, have you got it running and situated ? ...${textreset}" | |
echo | |
echo -e "*** Starting screen capture in $DELAY seconds - Press Ctrl+C to abort.${colorred}\c" | |
echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c" | |
for ((i=$DELAY; i>0; i--)); do | |
echo -e " $i\b\b\c"; sleep 1 | |
done | |
echo " 0${textreset}" | |
# Go $HOME and Start screen capture. | |
cd | |
RESOLUTION=`xrandr |sed -n 's/.*current \([0-9]\+\) x \([0-9]\+\).*/\1x\2/p'` | |
TRAP="echo \"${coloryel}*** See Filename: ${FILENAME}.mkv for output ...${textreset}\"" | |
trap "${TRAP}" INT HUP 2 0 | |
sudo enter-chroot -c $CHROOTS -n $CHROOT host-x11 avconv -f alsa \ | |
-ac 2 -ab 128k -i pulse -f x11grab -r 30 -s $RESOLUTION -i :0.0 \ | |
-vcodec libx264 -preset ultrafast -crf 0 Downloads/${FILENAME}.mkv | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checkout 'VERSHIST' for updated info.
For more in-depth info., click on 'Revisions'.