Advertisement
Guest User

Untitled

a guest
May 26th, 2013
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.75 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$1" = --help ]
  4. then
  5.     echo "Usage: $0 [-m] [OUTPUT_FILE]"
  6.     echo "Casts the screen to the given file. -m turns on the microphone."
  7. fi
  8.  
  9. if [ "$1" = -m ]
  10. then
  11.     MIC=true
  12.     shift
  13. else
  14.     MIC=false
  15. fi
  16.  
  17. OUTFILE="$1"
  18.  
  19. if [ x = "x$OUTFILE" ]
  20. then
  21.     OUTFILE=screencast_`date +%Y-%m-%d_%H.%M.%S`.mp4
  22. fi
  23.  
  24. COMBINED_SINK_NAME="combined"
  25. SOURCE_MIC=$(LANG=C pactl stat | sed -n -e "s/Default Source: \(.*\)/\1/p")
  26. SOURCE_OUTPUT=$(LANG=C pactl list | grep -A2 '^Source #' | grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1)
  27.  
  28. module_combine_sources() {
  29.     echo "Seting up null sink"
  30.     LOADED_MODULES+=($(LANG=C pactl load-module module-null-sink \
  31.         sink_name="$COMBINED_SINK_NAME"))
  32.     echo "Connecting VoIP source to null sink"
  33.     LOADED_MODULES+=($(LANG=C pactl load-module module-loopback \
  34.         source_dont_move=true sink_dont_move=true \
  35.         sink="$COMBINED_SINK_NAME" source="$SOURCE_OUTPUT"))
  36.     if $MIC
  37.     then
  38.         echo "Connecting Default source to null sink"
  39.         LOADED_MODULES+=($(LANG=C pactl load-module module-loopback \
  40.             source_dont_move=true sink_dont_move=true \
  41.             sink="$COMBINED_SINK_NAME" source="$SOURCE_MIC"))
  42.     fi
  43. }
  44.  
  45. unload_modules() {
  46.     set +e
  47.     for each in ${LOADED_MODULES[@]}; do
  48.         pactl unload-module $each
  49.     done
  50. }
  51. OUTRES="1366x768"
  52. FPS="20" # target FPS for x11grab
  53. QUAL="medium"  # one of the many FFMPEG preset
  54.  
  55. trap unload_modules EXIT
  56. module_combine_sources
  57. /opt/libav/bin/avconv \
  58.  -f x11grab -s 1366x768  -r "25" -i :0.0 \
  59.  -f pulse -i "$COMBINED_SINK_NAME.monitor" \
  60.  -vcodec libx264 -s $OUTRES -preset $QUAL -acodec libmp3lame -ar 44100 -threads 4 -qscale 3 -b 712000 \
  61.  -bufsize 512k -f mp4 "$OUTFILE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement