mirror of
https://codeberg.org/langfingaz/SplitVideo
synced 2024-11-21 20:43:17 +01:00
initial commit
This commit is contained in:
commit
7a7a9af57a
24
README.md
Normal file
24
README.md
Normal file
@ -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`
|
65
install.sh
Executable file
65
install.sh
Executable file
@ -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 <<EOF > "$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 "$@"
|
BIN
screenshot_main-gui.jpeg
Normal file
BIN
screenshot_main-gui.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
screenshot_start-app.jpeg
Normal file
BIN
screenshot_start-app.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
screenshot_success.jpeg
Normal file
BIN
screenshot_success.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
60
splitVideo
Executable file
60
splitVideo
Executable file
@ -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 <source> <seconds>"
|
||||||
|
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 "$@"
|
||||||
|
|
93
splitVideoGUI
Executable file
93
splitVideoGUI
Executable file
@ -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 "$@"
|
Loading…
Reference in New Issue
Block a user