Skip to content

Commit a51fd1d

Browse files
committed
fix(aws-lambda): 10-bit x265 in the arm64 ffmpeg, checked by output format
x265 now builds the 10-bit library and links it into the 8-bit one, so HDR renders get yuv420p10le instead of a silent 8-bit fallback. The check asserts the encoded pixel format rather than a successful command, and its ffprobe calls terminate options with -- like every other caller.
1 parent f43fc69 commit a51fd1d

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎packages/aws-lambda/image/build-ffmpeg.sh‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ git -C "$SRC/x264" checkout -q "$x264_commit"
3030
license x264 "$SRC/x264/COPYING"
3131

3232
fetch x265_4.1.tar.gz
33+
# 8-bit x265 with the 10-bit library linked in (x265's multilib layout): HDR renders encode yuv420p10le.
3334
# SVE2 kernels need -march=armv9-a, which the base's gcc 11 does not know (x86 ignores the flag).
34-
cmake -S "$SRC/x265_4.1/source" -B "$SRC/x265-build" -DCMAKE_BUILD_TYPE=Release \
35-
-DCMAKE_INSTALL_PREFIX="$DEPS" -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DENABLE_SVE2=OFF
36-
cmake --build "$SRC/x265-build" -j"$JOBS"
37-
cmake --install "$SRC/x265-build"
35+
x265=(-S "$SRC/x265_4.1/source" -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DENABLE_SVE2=OFF)
36+
cmake "${x265[@]}" -B "$SRC/x265-10" -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF
37+
cmake --build "$SRC/x265-10" -j"$JOBS"
38+
cmake "${x265[@]}" -B "$SRC/x265-8" -DCMAKE_INSTALL_PREFIX="$DEPS" -DLINKED_10BIT=ON \
39+
-DEXTRA_LIB="$SRC/x265-10/libx265.a"
40+
cmake --build "$SRC/x265-8" -j"$JOBS"
41+
cmake --install "$SRC/x265-8"
42+
printf 'CREATE %s\nADDLIB %s\nADDLIB %s\nSAVE\nEND\n' "$DEPS/lib/libx265.a" \
43+
"$SRC/x265-8/libx265.a" "$SRC/x265-10/libx265.a" | ar -M
3844
license x265 "$SRC/x265_4.1/COPYING"
3945

4046
fetch libvpx-1.15.0.tar.gz

‎packages/aws-lambda/image/check-ffmpeg.sh‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Prints a deterministic summary to stdout; the artifact stage keeps it.
44
set -euo pipefail
55
ff() { /opt/hf-media/bin/ffmpeg -hide_banner -loglevel error -nostdin "$@"; }
6-
probe() { /opt/hf-media/bin/ffprobe -hide_banner -loglevel error "$@"; }
6+
probe() { local input=$1; shift; /opt/hf-media/bin/ffprobe -hide_banner -loglevel error "$@" -- "$input"; }
77
listed() { # listed <ffmpeg list flag> <awk field> <name...>
88
local names
99
names=$(/opt/hf-media/bin/ffmpeg -hide_banner "$1" | awk -v f="$2" '{ print $f }')
1010
for name in "${@:3}"; do grep -qx -- "$name" <<<"$names" || { echo "missing $1 $name" >&2; exit 1; }; done
1111
echo "${1#-}: ${*:3}"
1212
}
13-
frames() { probe -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 "$@"; }
13+
frames() { probe "$1" -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 "${@:2}"; }
1414

1515
cd "$(mktemp -d)"
1616
listed -encoders 2 libx264 libx265 libvpx-vp9 libopus prores_ks aac png mjpeg
@@ -27,7 +27,7 @@ ff -f lavfi -i "sine=d=1" -c:a aac -b:a 192k aac.m4a
2727
ff "${src[@]}" -frames:v 1 frame.png
2828
for f in h264.mp4 h265.mp4 prores.mov; do [ "$(frames "$f")" = 25 ] || { echo "decode $f" >&2; exit 1; }; done
2929
for f in opus.webm aac.m4a; do ff -i "$f" -f null -; done
30-
[ "$(probe -show_entries stream=width -of csv=p=0 frame.png)" = 320 ]
30+
[ "$(probe frame.png -show_entries stream=width -of csv=p=0)" = 320 ]
3131
echo "encode+decode: h264 h265 prores opus aac png"
3232

3333
# VP9 with alpha: left half transparent, decoded through libvpx-vp9 as the engine does.
@@ -43,9 +43,10 @@ echo "vp9 alpha: encode+decode"
4343
# The engine's HDR to SDR chain (core/src/hdrToneMap.ts) on tagged 10-bit HEVC.
4444
ff "${src[@]}" -c:v libx265 -pix_fmt yuv420p10le -color_primaries bt2020 -color_trc smpte2084 \
4545
-colorspace bt2020nc -x265-params log-level=error hdr.mp4
46+
[ "$(probe hdr.mp4 -select_streams v:0 -show_entries stream=pix_fmt -of csv=p=0)" = yuv420p10le ]
4647
ff -i hdr.mp4 -vf "zscale=t=linear:npl=100,tonemap=hable:desat=0,zscale=p=bt709:t=bt709:m=bt709:r=tv" \
4748
-f null -
48-
echo "hdr tonemap: zscale"
49+
echo "hdr: 10-bit hevc encode, zscale tonemap"
4950

5051
# TLS against the system trust store: a trusted host passes, a wrong host name is refused.
5152
exec 4< <(node -e '
@@ -55,6 +56,6 @@ exec 4< <(node -e '
5556
server=$!
5657
trap 'kill $server' EXIT
5758
read -r -t 30 -u 4 ready && [ "$ready" = ready ]
58-
[ "$(frames -tls_verify 1 https://localhost:8443/h264.mp4)" = 25 ]
59-
if frames -tls_verify 1 https://127.0.0.1:8443/h264.mp4 2>/dev/null; then echo "tls accepted a wrong host" >&2; exit 1; fi
59+
[ "$(frames https://localhost:8443/h264.mp4 -tls_verify 1)" = 25 ]
60+
if frames https://127.0.0.1:8443/h264.mp4 -tls_verify 1 2>/dev/null; then echo "tls accepted a wrong host" >&2; exit 1; fi
6061
echo "tls: verified, wrong host refused"

0 commit comments

Comments
 (0)