Advertisement
devinteske

vizproc.sh

Apr 14th, 2018
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.21 KB | None | 0 0
  1. #!/bin/sh
  2. ############################################################ IDENT(1)
  3. #
  4. # $Title: Script to render dwatch(1) gource-proc output into mp4 output $
  5. # $Copyright: 2017-2018 Devin Teske. All rights reserved. $
  6. # $FrauBSD$
  7. #
  8. ############################################################ INFORMATION
  9. #
  10. # Target host must be FreeBSD 12.0-CURRENT with https://pastebin.com/bXVrfqdG
  11. # saved to /usr/local/libexec/dwatch/gource-proc
  12. #
  13. ############################################################ CONFIGURATION
  14.  
  15. GOURCE_OPTIONS="
  16.     --auto-skip-seconds 1 --bloom-intensity 0.25
  17.     --dir-name-depth 5 --file-idle-time 0 --log-format custom
  18.     --highlight-users --key --hide mouse,progress
  19. " # END-QUOTE
  20.  
  21. FFMPEG_OPTIONS="
  22.     -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264
  23.     -preset ultrafast -pix_fmt yuv420p -crf 1
  24. " # END-QUOTE
  25.  
  26. ############################################################ GLOBALS
  27.  
  28. pgm="${0##*/}" # Program basename
  29.  
  30. #
  31. # Defaults
  32. #
  33. : ${DEFAULT_SIZE=1280x800}
  34. : ${LOGFILE=${pgm%.*}.log}
  35. : ${MP4FILE=${pgm%.*}.mp4}
  36.  
  37. #
  38. # Command-line options
  39. #
  40. APPEND=         # -a
  41. CONSOLE=        # -y
  42. CONSOLE_FORCE=      # -y
  43. [ -t 1 ] && CONSOLE=1   # -y
  44. DEBUG=          # -d
  45. NOGOURCE=       # -n
  46. PLAYLOG=        # -l
  47. QUIET=          # -q
  48. REALTIME=       # -R
  49. RENDER=         # -r
  50. SECONDS_PER_DAY=    # -s seconds
  51. SIZE=$DEFAULT_SIZE  # -S WxH
  52. TITLE=          # -t title
  53. VERBOSE=        # -v
  54.  
  55. ############################################################ FUNCTIONS
  56.  
  57. usage()
  58. {
  59.     exec >&2
  60.     echo "Usage(gource): $pgm [-adqrRvy] [GOURCE OPTIONS] ssh_host"
  61.     echo "               $pgm -l [-dqrRy] [GOURCE OPTIONS] [logfile]"
  62.     echo "  (no-gource): $pgm -n [-adqvy] ssh_host"
  63.     echo "               $pgm -ln [-dqy] [logfile]"
  64.     local fmt="\t%-12s %s\n"
  65.     echo "OPTIONS:"
  66.     printf "$fmt" "-a" "Append to log $LOGFILE (ignored by \`-l')."
  67.     printf "$fmt" "-d" "Debug. Create $LOGFILE"
  68.     printf "$fmt" "-l" "Play log file. Default $LOGFILE"
  69.     printf "$fmt" "-n" "Do not run gource (disables \`-r')."
  70.     printf "$fmt" "-q" "Quiet. Hide dwatch info."
  71.     printf "$fmt" "-r" "Render output $MP4FILE (disables \`-n)."
  72.     printf "$fmt" "-R" "Pass --realtime to Gource (disables \`-n')."
  73.     printf "$fmt" "-v" "Verbose dwatch output."
  74.     printf "$fmt" "-y" "Always use color."
  75.     echo "GOURCE OPTIONS:"
  76.     printf "$fmt" "-s seconds" \
  77.         "Pass \`--seconds-per-day seconds' to gource."
  78.     printf "$fmt" "-S WxH" \
  79.         "Gource vieo size. Default $DEFAULT_SIZE (disables \`-n')."
  80.     printf "$fmt" "-t text" "Pass \`--title text' to gource."
  81.     exit 1
  82. }
  83.  
  84. log_debug()
  85. {
  86.     awk -F\| -v console=$CONSOLE -v debug=$DEBUG -v nogource=$NOGOURCE '
  87.         !debug && !nogource { next }
  88.         !console { print; next }
  89.         { color = $3=="A" ? 32 : $3=="D" ? 31 : $3=="M" ? 33 : 0 }
  90.         color { sub(/.*/, "\033[" color "m&\033[0m") }
  91.         { print; fflush() }
  92.     ' # END-QUOTE
  93. }
  94.  
  95. gource()
  96. {
  97.     command gource $GOURCE_OPTIONS ${TITLE:+--title "$TITLE"} "$@"
  98. }
  99.  
  100. ############################################################ MAIN
  101.  
  102. #
  103. # Process command-line options
  104. #
  105. while getopts adlnqrRs:S:t:vy flag; do
  106.     case "$flag" in
  107.     a) APPEND=1 ;;
  108.     d) DEBUG=1 ;;
  109.     l) PLAYLOG=1 ;;
  110.     n) NOGOURCE=1 RENDER= ;;
  111.     q) QUIET=1 ;;
  112.     r) RENDER=1 NOGOURCE= ;;
  113.     R) REALTIME=1 NOGOURCE= ;;
  114.     s) SECONDS_PER_DAY="$OPTARG" ;;
  115.     S) SIZE="$OPTARG" NOGOURCE= ;;
  116.     t) TITLE="$OPTARG" ;;
  117.     v) VERBOSE=1 ;;
  118.     y) CONSOLE=1 CONSOLE_FORCE=1 ;;
  119.     *) usage # NOTREACHED
  120.     esac
  121. done
  122. shift $(( $OPTIND - 1 ))
  123.  
  124. #
  125. # Check command-line arguments
  126. #
  127. [ $# -gt 0 -o "$PLAYLOG" ] || usage # NOTREACHED
  128.  
  129. #
  130. # Debugging
  131. #
  132. if [ "$DEBUG" -o "$APPEND" ]; then
  133.     log_out="$LOGFILE"
  134. else
  135.     log_out=/dev/null
  136. fi
  137. if [ "$DEBUG" ]; then
  138.     cons_out="/dev/stderr"
  139. else
  140.     cons_out=/dev/null
  141. fi
  142.  
  143. #
  144. # Gource options
  145. #
  146. GOURCE_OPTIONS="--$SIZE $GOURCE_OPTIONS"
  147. [ "$REALTIME" ] && GOURCE_OPTIONS="$GOURCE_OPTIONS --realtime"
  148. [ "$SECONDS_PER_DAY" ] &&
  149.     GOURCE_OPTIONS="$GOURCE_OPTIONS --seconds-per-day $SECONDS_PER_DAY"
  150.  
  151. #
  152. # Gource
  153. #
  154. exec 3>&1
  155. if [ "$PLAYLOG" ]; then
  156.     [ $# -gt 0 ] && LOGFILE="$1"
  157.     if [ "$DEBUG" ]; then
  158.         data=$( cat "$LOGFILE" ) || exit
  159.         echo "$data" | log_debug
  160.         [ "$NOGOURCE" ] && exit
  161.         if [ "$RENDER" ]; then
  162.             GOURCE_OPTIONS="$GOURCE_OPTIONS --output-ppm-stream -"
  163.             echo "$data" | gource - |
  164.                 ffmpeg $FFMPEG_OPTIONS "$MP4FILE"
  165.         else
  166.             echo "$data" | gource -
  167.         fi
  168.     else
  169.         [ "$NOGOURCE" ] && exit
  170.         if [ "$RENDER" ]; then
  171.             GOURCE_OPTIONS="$GOURCE_OPTIONS --output-ppm-stream -"
  172.             gource "$LOGFILE" | ffmpeg $FFMPEG_OPTIONS "$MP4FILE"
  173.         else
  174.             gource "$LOGFILE"
  175.         fi
  176.     fi
  177.     exit
  178. fi
  179. if [ "$RENDER" ]; then
  180.     [ "$NOGOURCE" ] && exit
  181.     GOURCE_OPTIONS="$GOURCE_OPTIONS --output-ppm-stream -"
  182.     ssh "$@" dwatch ${QUIET:+-q} ${VERBOSE:+-v} -X gource-proc |
  183.         tee ${APPEND:+-a} "$log_out" | (
  184.             tee /dev/stderr | log_debug >&3
  185.         ) 2>&1 | gource - | ffmpeg $FFMPEG_OPTIONS "$MP4FILE"
  186. else
  187.     if [ "$NOGOURCE" ]; then
  188.         ssh "$@" dwatch ${QUIET:+-q} ${VERBOSE:+-v} -X gource-proc |
  189.             tee ${APPEND:+-a} "$log_out" | log_debug
  190.     else
  191.         ssh "$@" dwatch ${QUIET:+-q} ${VERBOSE:+-v} -X gource-proc |
  192.             tee ${APPEND:+-a} "$log_out" | (
  193.                 tee /dev/stderr | log_debug >&3
  194.             ) 2>&1 | gource -
  195.     fi
  196. fi
  197.  
  198. ################################################################################
  199. # END
  200. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement