-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·90 lines (76 loc) · 2.71 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·90 lines (76 loc) · 2.71 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
#
# Downloads the latest FFmpeg static release from johnvansickle.com and
# stages it under ./build/layer/bin so that `aws cloudformation package`
# can upload it as a Lambda Layer.
#
# Why johnvansickle?
# - Statically-linked single-binary tarballs, refreshed for every
# upstream FFmpeg release.
# - Built against glibc 2.17 so the binary runs unmodified on every
# Lambda runtime including Amazon Linux 2023 (glibc 2.34).
# - Always pulled via the unversioned "release" URL, so this script
# automatically picks up new versions (7.0.2 -> 7.1.x -> 8.x ...).
# - The alternative source, BtbN/FFmpeg-Builds, ships an 8.1 binary
# but at ~200 MB per executable (~387 MB unzipped for ffmpeg +
# ffprobe), which overflows Lambda's 250 MB function-plus-layers
# unzipped quota.
#
# Environment variables:
# ARCH amd64 (default) | arm64
# OUT_DIR output directory (default: ./build/layer)
#
set -euo pipefail
ARCH="${ARCH:-amd64}"
OUT_DIR="${OUT_DIR:-build/layer}"
case "${ARCH}" in
amd64|arm64) ;;
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*)
echo "Unsupported ARCH='${ARCH}'. Use amd64 or arm64." >&2
exit 1
;;
esac
BASE_URL="https://johnvansickle.com/ffmpeg/releases"
TARBALL="ffmpeg-release-${ARCH}-static.tar.xz"
CHECKSUM="${TARBALL}.md5"
echo ">> Cleaning ${OUT_DIR}"
rm -rf "${OUT_DIR}"
mkdir -p "${OUT_DIR}/bin"
TMP="$(mktemp -d)"
trap 'rm -rf "${TMP}"' EXIT
echo ">> Downloading ${BASE_URL}/${TARBALL}"
curl -fsSL "${BASE_URL}/${TARBALL}" -o "${TMP}/${TARBALL}"
curl -fsSL "${BASE_URL}/${CHECKSUM}" -o "${TMP}/${CHECKSUM}"
echo ">> Verifying MD5 checksum"
(
cd "${TMP}"
if command -v md5sum >/dev/null 2>&1; then
md5sum -c "${CHECKSUM}"
else
expected="$(awk '{print $1}' "${CHECKSUM}")"
actual="$(md5 -q "${TARBALL}")"
[ "${expected}" = "${actual}" ] || {
echo "Checksum mismatch: expected=${expected} actual=${actual}" >&2
exit 1
}
fi
)
echo ">> Extracting"
tar -xJf "${TMP}/${TARBALL}" -C "${TMP}"
EXTRACT_DIR="$(find "${TMP}" -maxdepth 1 -type d -name 'ffmpeg-*-static' | head -n 1)"
if [ -z "${EXTRACT_DIR}" ]; then
echo "Could not locate extracted ffmpeg directory" >&2
exit 1
fi
cp "${EXTRACT_DIR}/ffmpeg" "${OUT_DIR}/bin/ffmpeg"
cp "${EXTRACT_DIR}/ffprobe" "${OUT_DIR}/bin/ffprobe"
chmod +x "${OUT_DIR}/bin/ffmpeg" "${OUT_DIR}/bin/ffprobe"
[ -f "${EXTRACT_DIR}/readme.txt" ] && cp "${EXTRACT_DIR}/readme.txt" "${OUT_DIR}/UPSTREAM-README.txt"
[ -f "${EXTRACT_DIR}/GPLv3.txt" ] && cp "${EXTRACT_DIR}/GPLv3.txt" "${OUT_DIR}/UPSTREAM-GPLv3.txt"
echo ">> Layer contents:"
ls -lh "${OUT_DIR}/bin"
echo ">> Binary info:"
file "${OUT_DIR}/bin/ffmpeg" || true
echo ">> Done. Layer staged in '${OUT_DIR}/' (ARCH=${ARCH})."