mirror of
https://github.com/godotengine/godot-website.git
synced 2026-01-05 10:10:00 +03:00
Deploying to published from @ godotengine/godot-website@d58ff1c4d0 🚀
This commit is contained in:
100
misc/scripts/process_video.sh
Executable file
100
misc/scripts/process_video.sh
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
trap 'exit 1' SIGINT
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||
source "${SCRIPT_DIR%/}/utils.sh"
|
||||
|
||||
GODOT_WEBSITE_VIDEO_FFMPEG="${GODOT_WEBSITE_VIDEO_FFMPEG:-ffmpeg}"
|
||||
QUALITY="2M"
|
||||
INPUT=""
|
||||
OUTPUT=""
|
||||
|
||||
show_help() {
|
||||
echo "Usage: $(basename "$0") [-q=2M] [-h] input output"
|
||||
echo " -q Quality"
|
||||
echo " -s Scale 'N:N', with -1 if you want to keep aspect ratio"
|
||||
echo " -h Help"
|
||||
echo ""
|
||||
echo "Environment variables:"
|
||||
echo " GODOT_WEBSITE_VIDEO_FFMPEG Path to \`ffmpeg\` (detault: 'ffmpeg')"
|
||||
returncode="${1:-0}"
|
||||
exit "$returncode"
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
while getopts 'q:s:h' opt; do
|
||||
case "$opt" in
|
||||
q)
|
||||
QUALITY="$OPTARG"
|
||||
;;
|
||||
s)
|
||||
SCALE="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
show_help
|
||||
;;
|
||||
?)
|
||||
show_help 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
show_help
|
||||
fi
|
||||
|
||||
test_ffmpeg
|
||||
|
||||
INPUT="${*:$OPTIND:1}"
|
||||
OUTPUT="${*:$OPTIND+1:1}"
|
||||
|
||||
if [ -z "$INPUT" ]; then
|
||||
echo_err "Error: no input given"
|
||||
show_help 1
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUT" ]; then
|
||||
echo_err "Error: no output given"
|
||||
show_help 1
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_args "$@"
|
||||
|
||||
declare -a scale_param=()
|
||||
if [ -n "$SCALE" ]; then
|
||||
scale_param+=("-vf" "scale=$SCALE")
|
||||
fi
|
||||
|
||||
set -ex
|
||||
|
||||
local pass_one_args=(
|
||||
"-i" "$INPUT"
|
||||
"-c:v" "libvpx-vp9"
|
||||
"-b:v" "$QUALITY"
|
||||
"-pass" "1"
|
||||
"-an"
|
||||
"${scale_param[@]}"
|
||||
"-f" "null"
|
||||
"$OUTPUT"
|
||||
)
|
||||
|
||||
pass_two_args=(
|
||||
"-i" "$INPUT"
|
||||
"-c:v" "libvpx-vp9"
|
||||
"-b:v" "$QUALITY"
|
||||
"-pass" "2"
|
||||
"-c:a" "libopus"
|
||||
"${scale_param[@]}"
|
||||
"$OUTPUT"
|
||||
)
|
||||
|
||||
"$GODOT_WEBSITE_VIDEO_FFMPEG" "${pass_one_args[@]}"
|
||||
"$GODOT_WEBSITE_VIDEO_FFMPEG" "${pass_two_args[@]}"
|
||||
|
||||
set +ex
|
||||
}
|
||||
|
||||
main "$@"
|
||||
146
misc/scripts/utils.sh
Normal file
146
misc/scripts/utils.sh
Normal file
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
color() {
|
||||
local BLACK="0"
|
||||
local RED="1"
|
||||
local GREEN="2"
|
||||
local YELLOW="3"
|
||||
local BLUE="4"
|
||||
local PURPLE="5"
|
||||
local CYAN="6"
|
||||
local WHITE="7"
|
||||
|
||||
local type="$1"
|
||||
local color="$2"
|
||||
local uppercase_color="${color^^}"
|
||||
|
||||
validate_color() {
|
||||
case "$color" in
|
||||
black | red | green | yellow | blue | purple | cyan | white) ;;
|
||||
?)
|
||||
echo_err "Invalid color: \"$color\""
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
case "$type" in
|
||||
r | reg | regular)
|
||||
if validate_color; then
|
||||
echo -e "\e[0;3${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
b | bold)
|
||||
if validate_color; then
|
||||
echo -e "\e[1;3${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
u | underline)
|
||||
if validate_color; then
|
||||
echo -e "\e[4;3${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
bg | background)
|
||||
if validate_color; then
|
||||
echo -e "\e[4${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
hi | high)
|
||||
if validate_color; then
|
||||
echo -e "\e[0;9${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
hi-b | hi-bold | high-b | high-bold)
|
||||
if validate_color; then
|
||||
echo -e "\e[1;9${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
hi-bg | hi-background | high-bg | high-background)
|
||||
if validate_color; then
|
||||
echo -e "\e[0;10${!uppercase_color}m"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
R | reset)
|
||||
echo -e "\e[0m"
|
||||
;;
|
||||
Rfg | reset-foreground)
|
||||
echo -e "\e[39m"
|
||||
;;
|
||||
Rbg | reset-background)
|
||||
echo -e "\e[49m"
|
||||
;;
|
||||
?)
|
||||
echo_err "Error: invalid color type: \"$type\""
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
echo_err() {
|
||||
local IFS=" "
|
||||
echo "$@" >&2
|
||||
}
|
||||
export -f echo_err
|
||||
|
||||
test_ffmpeg() {
|
||||
local ffmpeg_path="${1:-ffmpeg}"
|
||||
if ! command -v "$ffmpeg_path" >/dev/null 2>&1; then
|
||||
echo_err "Error: did not find '$ffmpeg_path', ffmpeg is required"
|
||||
show_help 1
|
||||
fi
|
||||
}
|
||||
export -f test_ffmpeg
|
||||
|
||||
join_list() {
|
||||
local IFS="$1"
|
||||
shift
|
||||
echo "$*"
|
||||
}
|
||||
export -f join_list
|
||||
|
||||
parse_int() {
|
||||
if [[ "$#" -gt "1" ]]; then
|
||||
echo_err "Too many arguments passed to \`${FUNCNAME[0]}\`"
|
||||
return 1
|
||||
fi
|
||||
printf "%d" "$1" 2>/dev/null
|
||||
}
|
||||
export -f parse_int
|
||||
|
||||
to_lower() {
|
||||
local IFS=" "
|
||||
local arg=""
|
||||
local -a results=()
|
||||
for arg in "$@"; do
|
||||
results+=("$(echo "$arg" | awk "{print tolower($1)}")")
|
||||
shift
|
||||
done
|
||||
echo "${results[@]}"
|
||||
}
|
||||
export -f to_lower
|
||||
|
||||
to_upper() {
|
||||
local IFS=" "
|
||||
local arg=""
|
||||
local -a results=()
|
||||
for arg in "$@"; do
|
||||
results+=("$(echo "$arg" | awk "{print toupper(\$1)}")")
|
||||
done
|
||||
echo "${results[@]}"
|
||||
}
|
||||
export -f to_upper
|
||||
Reference in New Issue
Block a user