45 lines
1.2 KiB
Bash
Executable file
45 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
PIDFILE="${XDG_RUNTIME_DIR}/mkchromecast.pid"
|
|
|
|
WIDTH=1440
|
|
HEIGHT=1080
|
|
ASPECT_OFFSET=240
|
|
OUTPUT_NAME='DVI-I-1-1'
|
|
|
|
command() {
|
|
echo "ffmpeg -ac 2 -ar 44100 -frame_size 2048 -fragment_size 2048 -f pulse -ac 2 -i Mkchromecast.monitor -f x11grab -r 30 -s ${WIDTH}x${HEIGHT} -i :0.0+$1,0 -vcodec libx264 -preset veryfast -tune zerolatency -maxrate 10000k -bufsize 20000k -pix_fmt yuv420p -g 60 -f mp4 -vf scale=1280:720 -movflags frag_keyframe+empty_moov -ar 44100 -acodec libvorbis pipe:1"
|
|
}
|
|
|
|
set -x
|
|
|
|
cleanup() {
|
|
xrandr --output DVI-I-1-1 --off
|
|
pid="$(cat ${PIDFILE})"
|
|
rm "${PIDFILE}"
|
|
pkill -35 dwmblocks
|
|
kill -INT "${pid}"
|
|
}
|
|
|
|
run() {
|
|
xrandr --setprovideroutputsource 1 0
|
|
xrandr --addmode DVI-I-1-1 1920x1080
|
|
xrandr --output ${OUTPUT_NAME} --mode 1920x1080 --rate 60 --right-of eDP-1
|
|
|
|
echo $$ > "${PIDFILE}"
|
|
pkill -35 dwmblocks
|
|
offset=$(( "$(xrandr | grep DVI | cut -d ' ' -f 3 | cut -d '+' -f 2)" + ${ASPECT_OFFSET} ))
|
|
systemd-inhibit --what=handle-lid-switch sleep 2592000 &
|
|
exec mkchromecast --video --command "$(command ${offset})"
|
|
}
|
|
|
|
if [ "$1" = "-k" ]; then
|
|
cleanup
|
|
exit 0
|
|
fi
|
|
|
|
if [ -f "${PIDFILE}" ]; then
|
|
cleanup || run
|
|
else
|
|
run
|
|
fi
|