mirror of
https://codeberg.org/langfingaz/SplitVideo
synced 2024-11-21 20:43:17 +01:00
61 lines
1.2 KiB
Plaintext
61 lines
1.2 KiB
Plaintext
|
#!/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 "$@"
|
||
|
|