mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 09:50:09 +00:00
99 lines
1.5 KiB
Bash
Executable File
99 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
#shopt -s extglob
|
|
#shopt -s nullglob
|
|
#shopt -s failglob
|
|
|
|
|
|
DEBUG=${DEBUG:-$DRY_RUN}
|
|
function @ () {
|
|
echo "### $@"
|
|
[ -z $DRY_RUN ] \
|
|
&& "$@"
|
|
}
|
|
|
|
|
|
FPS=${FPS:-8}
|
|
# XXX ffmpeg does not seem to support extglob...
|
|
#PATTERN=${PATTERN:-'*.@(JPG|jpg|JPEG|jpeg|PNG|png)'}
|
|
PATTERN=${PATTERN:-'*.jpeg'}
|
|
|
|
while [[ $# != 0 ]] ; do
|
|
case "$1" in
|
|
-h|--help)
|
|
echo "Usage: $(basename $0) [OPTIONS] [PATTERN]"
|
|
echo
|
|
echo "Options:"
|
|
echo " -h --help - print this message and exit"
|
|
echo " -r --rate FPS - set framerate (default: $FPS)"
|
|
echo " -p --pattern PATTERN"
|
|
echo " - image pattern to use (default: '$PATTERN')"
|
|
echo
|
|
echo "NOTE: option defaults can bbe overriden by coresponding env variables."
|
|
echo
|
|
exit
|
|
;;
|
|
-r|--rate)
|
|
FPS="$2"
|
|
shift 2
|
|
continue
|
|
;;
|
|
-p|--pattern)
|
|
PATTERN="$2"
|
|
shift 2
|
|
continue
|
|
;;
|
|
|
|
# trailing args...
|
|
*)
|
|
PATTERN="$1"
|
|
shift
|
|
continue
|
|
;;
|
|
esac
|
|
done
|
|
|
|
LST=($PATTERN)
|
|
|
|
|
|
# generate name...
|
|
A=${LST[0]}
|
|
A=${A%.*}
|
|
B=${LST[$(( ${#LST[@]} - 1 ))]}
|
|
B=${B%.*}
|
|
|
|
NAME=${NAME:-${A}-${B}}
|
|
|
|
PALETTE=${PALETTE:-.palette.png}
|
|
|
|
|
|
# generate...
|
|
{
|
|
set -o noglob
|
|
# gif palette...
|
|
@ ffmpeg \
|
|
-pattern_type glob \
|
|
-i $PATTERN \
|
|
-vf palettegen \
|
|
"$PALETTE"
|
|
# gif...
|
|
@ ffmpeg \
|
|
-r $FPS \
|
|
-pattern_type glob \
|
|
-i $PATTERN \
|
|
-i "$PALETTE" \
|
|
-filter_complex paletteuse=dither=none \
|
|
"${NAME}".gif
|
|
# cleanup...
|
|
@ rm "$PALETTE"
|
|
|
|
# mkv...
|
|
@ ffmpeg \
|
|
-r $FPS \
|
|
-pattern_type glob \
|
|
-i $PATTERN \
|
|
"${NAME}".mkv
|
|
#set +o noglob
|
|
}
|
|
|