282 lines
6.7 KiB
Bash
Executable File
282 lines
6.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Program name
|
|
PROGRAM_NAME="Frameless"
|
|
PROGRAM_V="2.0"
|
|
|
|
# Make sure the required packages are installed
|
|
command -v mplayer >/dev/null 2>&1 || {
|
|
echo >&2 "[error] We require mplayer for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting."
|
|
exit 1
|
|
}
|
|
command -v zenity >/dev/null 2>&1 || {
|
|
echo >&2 "[error] We require zenity for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting."
|
|
exit 1
|
|
}
|
|
dpkg -l | grep v4l-utils >/dev/null 2>&1 || {
|
|
echo >&2 "[error] We require v4l-utils for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting."
|
|
exit 1
|
|
}
|
|
|
|
# to install the needed packages :)
|
|
# sudo apt-get install mplayer zenity v4l-utils
|
|
|
|
# the device name
|
|
DEVICE=''
|
|
|
|
# the screen number
|
|
SCREEN_NUMBER=''
|
|
|
|
# the mplayer PID ID
|
|
MPLAYER_PID
|
|
|
|
# main function
|
|
function main() {
|
|
# select the video to use
|
|
selectVideoDevice
|
|
|
|
# select the screen to use
|
|
selectScreen
|
|
|
|
# open the menu
|
|
mainMenu
|
|
|
|
exit 0;
|
|
}
|
|
|
|
# select the screen
|
|
function selectScreen() {
|
|
local screen_count
|
|
local screen_index
|
|
# get the screens
|
|
local screens=''
|
|
screens=$(getScreens)
|
|
|
|
# check the number of screens
|
|
screen_count=$(echo "$screens" | wc -l)
|
|
|
|
if [ "$screen_count" -eq 1 ]; then
|
|
# only one screen is available, so set the screen number to 0
|
|
SCREEN_NUMBER=0
|
|
else
|
|
# get the selection
|
|
local selected=""
|
|
|
|
while [ -z "$selected" ]; do
|
|
# Display the list of screens using Zenity
|
|
# shellcheck disable=SC2086
|
|
selected=$(zenity --list --title "Select a Screen" --column "Index" --column "Screen Name" $screens)
|
|
# Check the exit status of Zenity
|
|
if [ $? -eq 1 ]; then
|
|
# The user clicked the "Cancel" button, exit the loop
|
|
exit 0
|
|
elif [ -z "$selected" ]; then
|
|
# No screen was selected, display an error message
|
|
zenity --error --text "No screen was selected. Please select a screen."
|
|
fi
|
|
done
|
|
|
|
# Extract the screen index from the selection
|
|
screen_index=$(echo "$selected" | awk '{print $1}')
|
|
|
|
SCREEN_NUMBER="${screen_index}"
|
|
fi
|
|
}
|
|
|
|
# function get screens
|
|
function getScreens() {
|
|
# Get a list of available screens and their index
|
|
local screens
|
|
screens=$(xrandr | grep " connected" | awk '{print NR-1 " " $1}')
|
|
echo "$screens"
|
|
}
|
|
|
|
# select the video camera
|
|
function selectVideoDevice() {
|
|
|
|
# get the cameras
|
|
local cameras=''
|
|
cameras=$(getDevices)
|
|
|
|
# stop all videos
|
|
stopVideo
|
|
|
|
# get the selection
|
|
local selected=""
|
|
|
|
while [ -z "$selected" ]; do
|
|
# Display the list of cameras using Zenity
|
|
# shellcheck disable=SC2086
|
|
selected=$(zenity --list --title "Select a Video Camera" --column "Camera" $cameras)
|
|
# Check the exit status of Zenity
|
|
if [ $? -eq 1 ]; then
|
|
# The user clicked the "Cancel" button, exit the loop
|
|
exit 0
|
|
elif [ -z "$selected" ]; then
|
|
# No camera was selected, display an error message
|
|
zenity --error --text "No camera was selected. Please select a camera."
|
|
fi
|
|
done
|
|
|
|
# Camera was selected, display a preview
|
|
previewDevice "${selected}"
|
|
|
|
DEVICE="${selected}"
|
|
|
|
zenity --question --text "Is this the camera you would like to use?"
|
|
|
|
# Check the exit status of Zenity
|
|
if [ $? -eq 1 ]; then
|
|
selectVideoDevice
|
|
fi
|
|
|
|
# stop all videos
|
|
stopVideo
|
|
}
|
|
|
|
# function get devices
|
|
function getDevices() {
|
|
# Our local values
|
|
local devices=''
|
|
local list=''
|
|
# Get a list of video cameras
|
|
# shellcheck disable=SC2010
|
|
devices=$(ls /dev | grep '^video')
|
|
# Check which devices can be displayed by MPlayer
|
|
for device in $devices; do
|
|
# Use v4l2-ctl to check if the device supports previewing
|
|
if v4l2-ctl --device="/dev/$device" --list-formats | grep -q "YUYV" ; then
|
|
# The device supports previewing, add it to the list
|
|
list="$list $device"
|
|
fi
|
|
done
|
|
|
|
echo "$list"
|
|
}
|
|
|
|
# Function to display a preview of the given video device
|
|
function previewDevice() {
|
|
device=$1
|
|
mplayer tv:// -tv driver=v4l2:device="/dev/$device" -geometry "300x300" -quiet -nolirc -ontop -noborder -nosound -vo xv &
|
|
MPLAYER_PID=$!
|
|
disown
|
|
}
|
|
|
|
# MAIN MENU
|
|
function mainMenu() {
|
|
local CHOICE=''
|
|
# select your position
|
|
CHOICE=$(zenity --list \
|
|
--title="Tutorial Video Player" --radiolist --width=400 --height=300 \
|
|
--text "Select where you want the video to display on (screen-${SCREEN_NUMBER})" \
|
|
--radiolist --column "Select" --column "Value" --column="Position Options" \
|
|
TRUE large "Large Center" \
|
|
FASLE bottomleft "Left Corner" \
|
|
FASLE bottomright "Right Corner" \
|
|
FASLE topleft "Top Left Corner" \
|
|
FASLE topright "Top Right Corner" \
|
|
FASLE camera "Select Camera" \
|
|
--hide-column=2 --cancel-label "Close")
|
|
|
|
# always first stop videos playing
|
|
stopVideo
|
|
|
|
# trigger the choose action
|
|
case $CHOICE in
|
|
"large")
|
|
showLarge
|
|
;;
|
|
"bottomleft")
|
|
showVideo "bottomleft"
|
|
;;
|
|
"bottomright")
|
|
showVideo "bottomright"
|
|
;;
|
|
"topleft")
|
|
showVideo "topleft"
|
|
;;
|
|
"topright")
|
|
showVideo "topright"
|
|
;;
|
|
"camera")
|
|
selectVideoDevice
|
|
;;
|
|
*) exit 0;;
|
|
esac
|
|
|
|
# menu loop
|
|
mainMenu
|
|
}
|
|
|
|
# show large center video
|
|
function showLarge() {
|
|
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
|
|
-vf mirror -xy 2 tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen "${SCREEN_NUMBER}" &
|
|
MPLAYER_PID=$!
|
|
disown
|
|
}
|
|
|
|
# function to get screen dimensions
|
|
function getScreenDimensions() {
|
|
local screen_name
|
|
local dimensions
|
|
local adjusted_screen_number=$(( $1 + 1 ))
|
|
screen_name=$(xrandr | grep " connected" | awk -v screen_number="$adjusted_screen_number" 'NR==screen_number {print $1}')
|
|
dimensions=$(xrandr | grep "$screen_name" | grep -oP '\d+x\d+\+\d+\+\d+' | cut -d'+' -f1)
|
|
echo "$dimensions"
|
|
}
|
|
|
|
# show video at a specified position
|
|
function showVideo() {
|
|
local position=$1
|
|
local dimensions
|
|
local width
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
dimensions=$(getScreenDimensions "${SCREEN_NUMBER}")
|
|
width=$(echo "$dimensions" | cut -d'x' -f1)
|
|
height=$(echo "$dimensions" | cut -d'x' -f2)
|
|
|
|
case $position in
|
|
"topleft")
|
|
x=30
|
|
y=30
|
|
;;
|
|
"topright")
|
|
x=$((width - 320 - 30))
|
|
y=30
|
|
;;
|
|
"bottomleft")
|
|
x=30
|
|
y=$((height - 240 - 30))
|
|
;;
|
|
"bottomright")
|
|
x=$((width - 320 - 30))
|
|
y=$((height - 240 - 30))
|
|
;;
|
|
*)
|
|
echo "Invalid position specified"
|
|
return 1
|
|
;;
|
|
esac
|
|
|
|
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
|
|
-geometry 320x240+"${x}"+"${y}" -vf mirror tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen "${SCREEN_NUMBER}" &
|
|
MPLAYER_PID=$!
|
|
disown
|
|
}
|
|
|
|
# stop videos playing
|
|
function stopVideo() {
|
|
if [ -n "${MPLAYER_PID}" ]; then
|
|
kill "${MPLAYER_PID}"
|
|
unset MPLAYER_PID
|
|
sleep 1
|
|
fi
|
|
}
|
|
|
|
# start program
|
|
main
|