From: Francois Fleuret Date: Fri, 5 Mar 2021 13:08:00 +0000 (+0100) Subject: Initial commit. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=168fb874818be5acaf78953efb56f46db7413131;p=scripts.git Initial commit. --- diff --git a/capslides.sh b/capslides.sh new file mode 100755 index 0000000..ea80a10 --- /dev/null +++ b/capslides.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +######################################################################### +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the version 3 of the GNU General Public License # +# as published by the Free Software Foundation. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# Written by and Copyright (C) Francois Fleuret # +# Contact for comments & bug reports # +######################################################################### + +DESIRABLE_SIZE="1440,1080" +AUDIO_DEV="/dev/dsp1" +WINDOW_NAME="pdfpc - presentation" + +###################################################################### + +SLIDES_WIN=($(xwininfo -root -all | grep "${WINDOW_NAME}" | sed -e 's/^.*\")[\t ]*\([0-9]*\)x\([0-9]*\)+\([-0-9]*\)+\([-0-9]*\)[ \t]*+\([-0-9]*\)+\([-0-9]*\).*$/\1 \2 \3 \4 \5 \6/')) + +if [[ ! "${SLIDES_WIN}" ]] +then + echo "Cannot find a \"${WINDOW_NAME}\" window" + exit 1 +fi + +SLIDES_W=${SLIDES_WIN[0]} +SLIDES_H=${SLIDES_WIN[1]} + +# wmctrl -r "${WINDOW_NAME}" -b add,above,sticky -e "0,-1,-1,${DESIRABLE_SIZE}" + +if [[ "${SLIDES_W},${SLIDES_H}" != "${DESIRABLE_SIZE}" ]] +then + echo "The window is not ${DESIRABLE_SIZE}" + exit 1 +fi + +let SLIDES_X=${SLIDES_WIN[2]}+${SLIDES_WIN[4]} +let SLIDES_Y=${SLIDES_WIN[3]}+${SLIDES_WIN[5]} + +###################################################################### +# Move the window to the front and keep it there +wmctrl -r "${WINDOW_NAME}" -b add,above,sticky +###################################################################### + +echo "Capturing ${SLIDES_W}x${SLIDES_H}+${SLIDES_X}+${SLIDES_Y}" + +TAG_START="$(date +%d%m%y-%H%M%S)" +RECORDING_FILE="wincast-${TAG_START}.mp4" + +# Fancy option to make web browser-friendly videos + +###################################################################### +OPT_WEBCAM=( + "-vf" + "movie=/dev/video0, scale=320:-1, fps=30, setpts=N/(30*TB) [movie]; [in][movie] overlay=main_w-overlay_w-8:main_h-overlay_h-8 [out]" +) +# "movie=/dev/video0:f=video4linux2, scale=320:-1, fps, setpts=PTS-STARTPTS [movie]; [in][movie] overlay=main_w-overlay_w-8:main_h-overlay_h-8 [out]" +###################################################################### + +#OPT_WHITE_FRAME=( '-vf' 'crop=1436:1076:2:2, pad=width=1440:height=1080:x=2:y=2:color=white' ) + +ffmpeg \ + \ + -thread_queue_size 1024 \ + \ + -guess_layout_max 0 -f oss -i "${AUDIO_DEV}" \ + \ + -f x11grab \ + \ + -vsync 1 -async 1 \ + -r 30 -video_size ${SLIDES_W}x${SLIDES_H} -probesize 32M -i :0.0+${SLIDES_X},${SLIDES_Y} \ + -codec:v libx264 -crf 22 -bf 2 -flags +cgop -pix_fmt yuv420p \ + -codec:a aac -strict -2 -b:a 384k -r:a 48000 \ + -movflags faststart \ + \ + "${OPT_WHITE_FRAME[@]}" \ + \ + "${RECORDING_FILE}" + +FINAL_FILE="wincast-${TAG_START}-$(date +%H%M%S).mp4" + +mv "${RECORDING_FILE}" "${FINAL_FILE}" + +###################################################################### + +duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${FINAL_FILE}") + +if [[ $(echo "${duration} < 10" | bc) == 1 ]] +then + echo "Video is less than 10s, moved to /tmp/" + mv "${FINAL_FILE}" /tmp/ +fi + +######################################################################