-
Notifications
You must be signed in to change notification settings - Fork 8
/
makeconcat
executable file
·70 lines (62 loc) · 3.08 KB
/
makeconcat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# a script to concat video files into a single file
# load nmaahcmmfunctions into this script
SCRIPT_PATH="${0%/*}"
. "${SCRIPT_PATH}/nmaahcmmfunctions"
[[ -f "${SCRIPT_PATH}/nmaahcmmfunctions" ]] || { echo "Missing '${SCRIPT_PATH}/nmaahcmmfunctions'. Exiting." ; exit 1 ;};
_initialize_make # safe script termination process defined in nmaahcmmfunctions
unset DEPENDENCIES
DEPENDENCIES=(ffmpeg) # list dependencies required by script
_check_dependencies "${DEPENDENCIES[@]}" # defined in nmaahcmmfunctions
## USAGE
_usage(){
echo
echo "$(basename "${0}")"
echo "This application will concatenate multiple video files into a single video file. It takes two or more video files as arguments, all of which must be stored in the same directory. Be sure to list the video files in order. You will be asked to supply the name of the new concatenated file."
echo "Usage: $(basename ${0}) file1 file2 [ file3... ]"
echo
exit
}
[ "${#}" = 0 ] && _usage # if the command is run with no arguments then _usage is called
# getopts loop
OPTIND=1
while getopts ":h" OPT; do
case "${OPT}" in
h) _usage ;; # if the operator runs "[scriptname] -h" then the _usage text above will display in the terminal
*) echo "Invalid option -${OPTARG}" ; _usage ;; # if the operator tries to use an option other than the ones listed above, the _usage text will display in the terminal
esac
done
shift $(( ${OPTIND} - 1 ))
## FUNCTIONS
_makeconcat(){
echo
_report -b "Please enter the name of the concatenated file to be created, for example, SC_0001_20171211_Mangum_R8_01"
_report -b "Enter file name: "
read -r CONCATFILE
## $CONCATFILE will be the name of both the $TXTFILE and the outputed concatenated file. Name well.
echo
while [ "${*}" != "" ] ; do # while the number of arguments is not zero do X
for FILE in ${1} ; do # for the first argument do X
SUFFIX="${FILE##*.}" # set $SUFFIX to whatever the extension of your $FILE is
FILE_PATH="${FILE%/*}" # the $FILE_PATH is set as the dirname of the first argument
TXTFILE="${FILE_PATH}/${CONCATFILE}.txt" # the $TXTFILE will be created in the same dir as the first argument and named after $CONCATFILE
touch "${TXTFILE}" # the $TXTFILE is created, aka "touched"
printf "file '${FILE}'\n" >> "${TXTFILE}" # the first argument is written to $TXTFILE in the appropriate syntax for ffmpeg
shift # the script shifts from the first argument to the second argument. It will do this until there are no more arguments.
done
done
CONCATFILE="${FILE_PATH}/${CONCATFILE}.$SUFFIX"
ffmpeg -f concat -safe 0 -i "${TXTFILE}" -c copy "${CONCATFILE}" # ffmpeg creates the concatenated FILE in the same directory as $FILEs
echo
cowsay "Done. Your concatenated video FILE is ready fo action." # cowsay tells it like it is.
echo
_report -g "Your concatenated file is: ${CONCATFILE}"
}
## SCRIPT ACTIONS
# log script beginning
_log -b
_makeconcat "${@}"
# log script ending
_log -e
_report -g "makeconcat process complete."
exit "$?"