3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois@fleuret.org> for comments & bug reports #
18 #########################################################################
20 DESIRABLE_SIZE="1440,1080"
22 WINDOW_NAME="pdfpc - presentation"
24 ######################################################################
26 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/'))
28 if [[ ! "${SLIDES_WIN}" ]]
30 echo "Cannot find a \"${WINDOW_NAME}\" window"
34 SLIDES_W=${SLIDES_WIN[0]}
35 SLIDES_H=${SLIDES_WIN[1]}
37 # wmctrl -r "${WINDOW_NAME}" -b add,above,sticky -e "0,-1,-1,${DESIRABLE_SIZE}"
39 if [[ "${SLIDES_W},${SLIDES_H}" != "${DESIRABLE_SIZE}" ]]
41 echo "The window is not ${DESIRABLE_SIZE}"
45 let SLIDES_X=${SLIDES_WIN[2]}+${SLIDES_WIN[4]}
46 let SLIDES_Y=${SLIDES_WIN[3]}+${SLIDES_WIN[5]}
48 ######################################################################
49 # Move the window to the front and keep it there
50 wmctrl -r "${WINDOW_NAME}" -b add,above,sticky
51 ######################################################################
53 echo "Capturing ${SLIDES_W}x${SLIDES_H}+${SLIDES_X}+${SLIDES_Y}"
55 TAG_START="$(date +%d%m%y-%H%M%S)"
56 RECORDING_FILE="wincast-${TAG_START}.mp4"
58 # Fancy option to make web browser-friendly videos
60 ######################################################################
63 "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]"
65 # "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]"
66 ######################################################################
68 #OPT_WHITE_FRAME=( '-vf' 'crop=1436:1076:2:2, pad=width=1440:height=1080:x=2:y=2:color=white' )
72 -thread_queue_size 1024 \
74 -guess_layout_max 0 -f oss -i "${AUDIO_DEV}" \
79 -r 30 -video_size ${SLIDES_W}x${SLIDES_H} -probesize 32M -i :0.0+${SLIDES_X},${SLIDES_Y} \
80 -codec:v libx264 -crf 22 -bf 2 -flags +cgop -pix_fmt yuv420p \
81 -codec:a aac -strict -2 -b:a 384k -r:a 48000 \
84 "${OPT_WHITE_FRAME[@]}" \
88 FINAL_FILE="wincast-${TAG_START}-$(date +%H%M%S).mp4"
90 mv "${RECORDING_FILE}" "${FINAL_FILE}"
92 ######################################################################
94 duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${FINAL_FILE}")
96 if [[ $(echo "${duration} < 10" | bc) == 1 ]]
98 echo "Video is less than 10s, moved to /tmp/"
99 mv "${FINAL_FILE}" /tmp/
102 ######################################################################