Adds option to select video camera.

This commit is contained in:
Llewellyn van der Merwe 2023-01-09 03:12:12 +02:00
parent 18a2dcd919
commit 49f7a0532a
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -1,9 +1,116 @@
#!/bin/bash #!/bin/bash
# Program name
PROGRAM_NAME="Frameless"
# PROGRAM_CODE="frameless"
# PROGRAM_VERSION="1.0.0"
PROGRAM_V="1.0"
# PROGRAM_URL="https://git.vdm.dev/llewellyn/${PROGRAM_CODE}"
# 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=''
# main function
function main() {
# select the video to use
selectVideoDevice
# open the menu
mainMenu
exit 0;
}
# 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
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
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 &
disown
}
# MAIN MENU # MAIN MENU
function mainMenu() { function mainMenu() {
local CHOICE=''
# select your position # select your position
local CHOICE=$(zenity --list \ CHOICE=$(zenity --list \
--title="Tutorial Video Player" --radiolist --width=400 --height=300 \ --title="Tutorial Video Player" --radiolist --width=400 --height=300 \
--text "Select where you wnat the video to display" \ --text "Select where you wnat the video to display" \
--radiolist --column "Select" --column "Value" --column="Position Options" \ --radiolist --column "Select" --column "Value" --column="Position Options" \
@ -12,13 +119,13 @@ function mainMenu() {
FASLE right "Right Corner" \ FASLE right "Right Corner" \
FASLE topleft "Top Left Corner" \ FASLE topleft "Top Left Corner" \
FASLE topright "Top Right Corner" \ FASLE topright "Top Right Corner" \
FASLE quit "Quit" \ FASLE camera "Select Camera" \
--hide-column=2 2>/dev/null) --hide-column=2 --cancel-label "Close")
# alwasy first stop videos playing # always first stop videos playing
stopVideo stopVideo
# triger the choise acction # trigger the choose action
case $CHOICE in case $CHOICE in
"large") "large")
showLarge showLarge
@ -35,7 +142,10 @@ function mainMenu() {
"topright") "topright")
showTopright showTopright
;; ;;
"quit") quitProgram ;; "camera")
selectVideoDevice
;;
*) exit 0;;
esac esac
# menu loop # menu loop
@ -45,46 +155,43 @@ function mainMenu() {
# show large center video # show large center video
function showLarge() { function showLarge() {
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \ mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
-vf mirror -xy 2 tv:// -tv device=/dev/video4 -screen 1 & -vf mirror -xy 2 tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen 1 &
disown
} }
# show video on bottom left # show video on bottom left
function showLeft() { function showLeft() {
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \ mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
-geometry 320x240+30+780 -vf mirror tv:// -tv device=/dev/video4 -screen 1 & -geometry 320x240+30+780 -vf mirror tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen 1 &
disown
} }
# show video on bottom right # show video on bottom right
function showRight() { function showRight() {
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \ mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
-geometry 320x240+1570+780 -vf mirror tv:// -tv device=/dev/video4 -screen 1 & -geometry 320x240+1570+780 -vf mirror tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen 1 &
disown
} }
# show video on top left # show video on top left
function showTopleft() { function showTopleft() {
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \ mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
-geometry 320x240+30+30 -vf mirror tv:// -tv device=/dev/video4 -screen 1 & -geometry 320x240+30+30 -vf mirror tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen 1 &
disown
} }
# show video on top right # show video on top right
function showTopright() { function showTopright() {
mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \ mplayer -zoom -ontop -noborder -nosound -vo gl:nomanyfmts \
-geometry 320x240+1570+30 -vf mirror tv:// -tv device=/dev/video4 -screen 1 & -geometry 320x240+1570+30 -vf mirror tv:// -tv driver=v4l2:device="/dev/${DEVICE}" -screen 1 &
} disown
# show video on top right
function quitProgram() {
stopVideo
# end loop
exit 0;
} }
# stop videos playing # stop videos playing
function stopVideo() { function stopVideo() {
ps aux | grep mplayer | awk '{print $2}' | xargs kill pkill mplayer
sleep 1 sleep 1
} }
# start program # start program
mainMenu main