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