dotfiles

dotfiles.git
git clone git://git.lenczewski.org/dotfiles.git
Log | Files | Refs

screencap (2287B)


      1 #!/bin/sh
      2 
      3 USAGE() {
      4 	echo "Usage: $0 [-o <output>] [-s <stream-url.gpg>]"
      5 	echo "  -h: Print usage information"
      6 	echo "  -a: Use the given audio codec (default: libvorbis)"
      7 	echo "  -d: Record the given display (default: $DISPLAY)"
      8 	echo "  -f: Record the screen with the given framerate (default: 30)"
      9 	echo "  -i: Use the given audio input (default: default)"
     10 	echo "  -o: Output to the given file"
     11 	echo "  -s: Stream the screen capture to url in the given gpg2-encrypted file (ignores any -o options)"
     12 	echo "      This option will require the -a and -v options, depending on the streaming service"
     13 	echo "  -v: Output using the given container format (default: guessed)"
     14 }
     15 
     16 while getopts ":h:a:d:f:i:o:s:v:" cmdarg; do
     17 	case "$cmdarg" in
     18 		h)
     19 			USAGE
     20 			exit 1
     21 			;;
     22 		a)
     23 			ACODEC="$OPTARG"
     24 			;;
     25 		d)
     26 			CAPTURE="$OPTARG"
     27 			;;
     28 		f)
     29 			FRAMERATE="$OPTARG"
     30 			;;
     31 		i)
     32 			AINPUT="$OPTARG"
     33 			;;
     34 
     35 		o)
     36 			OUTPUT="$OPTARG"
     37 			;;
     38 		s)
     39 			STREAMURL="$OPTARG"
     40 			;;
     41 		v)
     42 			CONTAINER="$OPTARG"
     43 			;;
     44 		*)
     45 			echo "Unknown option: $cmdarg"
     46 			USAGE
     47 			exit 1
     48 			;;
     49 	esac
     50 done
     51 
     52 if [ "${STREAMURL:-z}" = "z" ]; then
     53 	[ "${OUTPUT:-z}" = "z" ] && echo "Missing output file!" && USAGE && exit 1
     54 else
     55 	OUTPUT="$(gpg2 -dq $STREAMURL)"
     56 fi
     57 
     58 [ ! "${CONTAINER:-z}" = "z" ] && OUTPUT="-f $CONTAINER $OUTPUT"
     59 
     60 # NOTE: change /dev/dri/renderD128 to whatever your main GPU shows up as
     61 ACCEL_DEV="-init_hw_device vaapi=gpu:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device gpu"
     62 ACCEL="-filter_hw_device gpu -vf format=nv12|vaapi,hwupload"
     63 AUDIO="-f alsa -ac 2 -ar 48000 -a:c pcm_s24le -i ${AINPUT:-hw:4}"
     64 VIDEO="-f x11grab -video_size 1920x1080 -framerate ${FRAMERATE:-30} -i ${CAPTURE:-$DISPLAY}"
     65 CODEC="-c:v h264_vaapi -b:v 10M -maxrate 10M -bf 0 -c:a ${ACODEC:-libvorbis} -af aresample=44100"
     66 
     67 FFMPEG_OPTS="-thread_queue_size 64 $ACCEL_DEV $VIDEO $AUDIO $ACCEL $CODEC $OUTPUT"
     68 
     69 # NOTE: feel free to remove DRI_PRIME=1 and LIBVA_DRIVER_NAME=radeonsi
     70 #       as these are only useful on systems with multiple gpus (with
     71 #       a discrete AMD gpu)
     72 DRI_PRIME=1 LIBVA_DRIVER_NAME=radeonsi \
     73 ffmpeg -y $FFMPEG_OPTS
     74 
     75 # ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=3440^C=1440:format=nv12' -c:v av1_vaapi -q 24 -y output-file.mkv