101 lines
1.7 KiB
Bash
101 lines
1.7 KiB
Bash
#!/bin/env bash
|
|
|
|
set -e
|
|
|
|
LONG_ARGUMENTS=(
|
|
"output:"
|
|
"debug"
|
|
"help"
|
|
)
|
|
SHORT_ARGUMENTS=(
|
|
"o:"
|
|
"d"
|
|
"h"
|
|
)
|
|
OPTS=$(getopt \
|
|
--longoptions "$(printf "%s," "${LONG_ARGUMENTS[@]}")" \
|
|
--options "$(printf "%s," "${SHORT_ARGUMENTS[@]}")" \
|
|
--name "$(basename "${0}")" \
|
|
-- "${@}"
|
|
)
|
|
|
|
eval set -- "${OPTS}"
|
|
|
|
### Utility functions ###
|
|
print_help() {
|
|
echo "$(basename "${0}") [FLAGS...] FOLDER
|
|
|
|
<description>
|
|
|
|
Parameters:
|
|
-d --debug Enable debug output
|
|
-h --help This very help
|
|
"
|
|
}
|
|
|
|
err() {
|
|
echo "${@}" >&2
|
|
}
|
|
|
|
create_demuxer_file() {
|
|
local demuxer_file="$(mktemp)"
|
|
local entry_template=<<EOF
|
|
file '${FILE_PATH}'
|
|
duration ${DURATION_SECOND}
|
|
EOF
|
|
local last_entry_template=<<EOF
|
|
file '${FILE_PATH}'
|
|
duration ${DURATION_SECOND}
|
|
file '${FILE_PATH}'
|
|
EOF
|
|
local last_img=""
|
|
for img_to_demux in "${INPUT_FOLDER}"/*.jpeg "${INPUT_FOLDER}"/*.jpg "${INPUT_FOLDER}"/*.png
|
|
do
|
|
last_img="${img_to_demux}"
|
|
local random_duration=$((${RANDOM}%${MAX_PHOTO_DURATION_SECONDS}))
|
|
echo <<EOF >> "${demuxer_file}"
|
|
file '${img_to_demux}'
|
|
duration ${random_duration}
|
|
EOF
|
|
done
|
|
|
|
echo "file '${last_img}'" >> "${demuxer_file}"
|
|
}
|
|
########################
|
|
|
|
|
|
### Config ###
|
|
VIDEO_TITLE="output"
|
|
MAX_PHOTO_DURATION_SECONDS=10
|
|
##############
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "${1}" in
|
|
--debug)
|
|
set -x
|
|
shift 1
|
|
;;
|
|
-d)
|
|
set -x
|
|
shift 1
|
|
;;
|
|
--help)
|
|
print_help
|
|
exit 0
|
|
;;
|
|
-h)
|
|
print_help
|
|
exit 0
|
|
;;
|
|
--)
|
|
shift 1
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
INPUT_FOLDER="${1}"
|
|
shift 1
|
|
|