commit 7a7a9af57a9e57a3f4cca16d3e43c75673018dfb Author: langfingaz Date: Wed Sep 23 19:51:42 2020 +0200 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..b76e336 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# SplitVideo + +## Usage + +Start the app via desktop entry: + +![](screenshot_start-app.jpeg) + +In the main window, select a source video and enter the time at which you want to split the video into two pieces. The original file will not be modified. + +![](screenshot_main-gui.jpeg) + +You will be informed in a small message window when the conversation is done and there will be two new files (with an appended prefix) next to your source video: + +![](screenshot_success.jpeg) + +## TODO + +* `splitVideoGUI` + - ckeck if `yad` is installed +* `splitVideo` + - check if `ffmpeg` is installed + +* check dependencies in `install.sh` \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..a058ed1 --- /dev/null +++ b/install.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# installation directory (should be included in your PATH variable) +PROGRAM_DIR="/usr/local/bin" +# base path where files to install are located +FILE_LOCATION="." +# names of files to install +# The LAST file must be the executable (with GUI) +FILE_NAMES=( "splitVideo" "splitVideoGUI" ) +# .desktop directory +DESKTOP_DIR="/usr/share/applications" + + + +function createDesktopEntry(){ + + # .desktop categories: + # https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry + + printf "Creating desktop entry for executable %s\n" "$PROGRAM_DIR/${FILE_NAMES[-1]}" + +cat < "$DESKTOP_DIR/${FILE_NAMES[-1]}.desktop" +[Desktop Entry] +Version=1.0 +Name=SplitVideo +Comment=Splits a video up in two parts at specific time +Categories=AudioVideo;Video;Utility; +Exec=${FILE_NAMES[-1]} +Icon=yad +Terminal=false +Type=Application +StartupNotify=true +EOF +} + +function validateDesktopEntry(){ + printf "\n========= Validating Desktop Entry =========\n\n" + desktop-file-validate "$DESKTOP_DIR/${FILE_NAMES[-1]}.desktop" + printf "========= ======================== =========\n\n" +} + +function main(){ + # copy files to /usr/local/bin + # and make them executable + + for FILE_NAME in "${FILE_NAMES[@]}"; do + cp "$FILE_LOCATION/$FILE_NAME" "$PROGRAM_DIR" || exit "$?" + chmod +x "$PROGRAM_DIR/$FILE_NAME" || exit "$?" + done + + createDesktopEntry || exit "$?" + + # update desktop entries + # https://wiki.archlinux.org/index.php/Desktop_entries#Update_database_of_desktop_entries + update-desktop-database "$DESKTOP_DIR" + + # validate desktop entry + # https://wiki.archlinux.org/index.php/Desktop_entries#Validation + validateDesktopEntry + + echo "Installation was successfull" + return 0 +} + +main "$@" diff --git a/screenshot_main-gui.jpeg b/screenshot_main-gui.jpeg new file mode 100644 index 0000000..f2ba988 Binary files /dev/null and b/screenshot_main-gui.jpeg differ diff --git a/screenshot_start-app.jpeg b/screenshot_start-app.jpeg new file mode 100644 index 0000000..af55f1f Binary files /dev/null and b/screenshot_start-app.jpeg differ diff --git a/screenshot_success.jpeg b/screenshot_success.jpeg new file mode 100644 index 0000000..5568900 Binary files /dev/null and b/screenshot_success.jpeg differ diff --git a/splitVideo b/splitVideo new file mode 100755 index 0000000..d3be701 --- /dev/null +++ b/splitVideo @@ -0,0 +1,60 @@ +#!/bin/bash + +function split(){ + local src="$1" + local dst="$2" + local start="$3" + local duration="$4" + + # ffmpeg param "-n" + # Do not overwrite output files, and exit immediately if + # a specified output file already exists. + + + if [ "$4" -gt 0 ] ; then + # Take section from (start) to (start + duration) + ffmpeg -n -i "${src}" -ss "$start" -t "${duration}" -c copy "${dst}" + errno="$?" + else + # $4 is empty or <1 + # Take section from (start) until (end of video) + ffmpeg -n -i "${src}" -ss "$start" -c copy "${dst}" + errno="$?" + fi + + return "$errno" +} + +function isPositiveInt(){ + # https://stackoverflow.com/a/3951175/6334421 + case "$1" in + ''|*[!0-9]*) return 1 ;; + *) return 0 ;; + esac +} + +function main(){ + # TODO: check if ffmpeg installed + + local source="$1" + local seconds="$2" + + # if args are empty -> cancel + if [ "$#" -ne 2 ] || [ -z "$1" ] || [ -z "$2" ] ; then + echo "Error: Expected two non-empty arguments!" + echo "usage: $0 " + exit 1 + fi + + if ! isPositiveInt "$2" ; then + echo "2nd arg must be positive integer" + return 2 + fi + + split "$source" "${source}_a.mkv" "0" "$seconds" || exit "$?" + split "$source" "${source}_b.mkv" "$seconds" + exit "$?" +} + +main "$@" + diff --git a/splitVideoGUI b/splitVideoGUI new file mode 100755 index 0000000..3948ab4 --- /dev/null +++ b/splitVideoGUI @@ -0,0 +1,93 @@ +#!/bin/bash + +# +# Thanks to ... +# the guys at puri.sm for their article about yad: +# * [https://wp.puri.sm/posts/easy-librem-5-app-development-take-a-screenshot/]() +# +# as well as this website: +# * http://smokey01.com/yad/ +# + + +function doStuff(){ + # :param $1: user-input + + # Parse user input + + SRC=`echo $1 | cut -d '|' -f1` + H=`echo $1 | cut -d '|' -f2` + M=`echo $1 | cut -d '|' -f3` + S=`echo $1 | cut -d '|' -f4` + + # Print input to stdout + + printf "SRC:\t%s\n" "$SRC" + printf "Time:\t%s:%s:%s\n" "$H" "$M" "$S" + + # Calculate time in seconds + # H(ours) + M(inutes) + S(econds) -> S(econds) + + HS="$(( 3600 * $H ))" + MS="$(( 60 * $M ))" + S="$(( $HS + $MS + $S ))" + + printf "Seconds: %s\n" "$S" + + # Split Video at specific time + + splitVideo "$SRC" "$S" + errno="$?" + + # inform user of result + + case "$errno" in + "0") + TITLE="SUCCESS" + TEXT="Done! Check out the _a.mkv and _b.mkv files next to your input file." + ;; + *) + TITLE="ERROR" + TEXT="An error occured with code $errno." + ;; + esac + echo "$TEXT" | yad --title="$TITLE" --wrap --text-info + + # return exitCode of splitVideo + return "$errno" +} + +function main(){ + # TODO check if yad installed + + # Get user input via yad (GUI) + + INPUT=`yad --title "splitVideo" --text="Split video at specific time" --form \ + --field=video:SFL \ + --field=hours:NUM \ + --field=minutes:NUM \ + --field=seconds:NUM \ + "splitMeUp.mp4" "1" "15" "5" --focus-field=1` + + case "$?" in + "0") + echo "User pressed 'OK'" + doStuff "$INPUT" + exit "$?" + ;; + "1") + echo "User pressed 'cancel'" + exit 0 + ;; + "252") + echo "User closed window." + exit 0 + ;; + *) + echo "An unexpected error has occurred: Code $?" + exit 1 + ;; + esac +} + +main "$@"