This commit is contained in:
root
2026-09-27 15:55:38 +08:00
commit 1b6f2e6831
14 changed files with 1379 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
echo "Restarting VOD after an already-completed atomic media update."
docker compose restart vod
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail
: "${PLAYER_ORIGIN:?Set PLAYER_ORIGIN before running this test}"
base_url=${HLS_BASE_URL:-http://127.0.0.1:8124}
media_path=${TEST_MEDIA_PATH:-aa/1170193193-1-192.mp4}
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
resolve_url() {
local base=$1
local reference=$2
case "$reference" in
http://*|https://*) printf '%s\n' "$reference" ;;
/*) printf '%s%s\n' "$(printf '%s\n' "$base" | sed -E 's#(https?://[^/]+).*#\1#')" "$reference" ;;
*) printf '%s/%s\n' "${base%/*}" "$reference" ;;
esac
}
master_url="${base_url%/}/hls/${media_path}/master.m3u8"
master_headers="$tmpdir/master.headers"
master_playlist="$tmpdir/master.m3u8"
curl --fail --silent --show-error --dump-header "$master_headers" --output "$master_playlist" "$master_url"
tr -d '\r' < "$master_headers" | grep -Fxi "Access-Control-Allow-Origin: $PLAYER_ORIGIN" >/dev/null
tr -d '\r' < "$master_headers" | grep -Fxi 'Cache-Control: no-store' >/dev/null
grep -Fqx '#EXTM3U' "$master_playlist" >/dev/null
child_reference=$(awk 'found { print; exit } /^#EXT-X-STREAM-INF/ { found=1 }' "$master_playlist")
if [[ -z $child_reference ]]; then
child_url=$master_url
else
child_url=$(resolve_url "$master_url" "$child_reference")
fi
child_playlist="$tmpdir/index.m3u8"
curl --fail --silent --show-error --output "$child_playlist" "$child_url"
grep -Fqx '#EXTM3U' "$child_playlist" >/dev/null
segment_reference=$(awk '!/^#/ && NF { print; exit }' "$child_playlist")
if [[ -z $segment_reference ]]; then
echo "No HLS segment was found in $child_url" >&2
exit 1
fi
segment_url=$(resolve_url "$child_url" "$segment_reference")
curl --fail --silent --show-error --output /dev/null "$segment_url"
printf 'HLS smoke test passed: %s\n' "$master_url"
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
set -euo pipefail
media_root=${1:-data}
if ! command -v ffprobe >/dev/null 2>&1; then
echo "ffprobe is required to validate media." >&2
exit 2
fi
if [[ ! -d $media_root ]]; then
printf 'Media directory does not exist: %s\n' "$media_root" >&2
exit 2
fi
valid_count=0
invalid_count=0
validate_file() {
local file=$1
local format_name streams codec type attached_pic
local video_count=0
local audio_count=0
local invalid_reason=
if ! format_name=$(ffprobe -v error -show_entries format=format_name \
-of default=noprint_wrappers=1:nokey=1 "$file"); then
printf 'INVALID: %q: unreadable or corrupt MP4\n' "$file" >&2
return 1
fi
if [[ ,$format_name, != *,mp4,* ]]; then
printf 'INVALID: %q: expected an MP4 container, got %s\n' "$file" "$format_name" >&2
return 1
fi
if ! streams=$(ffprobe -v error \
-show_entries stream=codec_name,codec_type:stream_disposition=attached_pic \
-of csv=p=0 "$file"); then
printf 'INVALID: %q: unable to inspect streams\n' "$file" >&2
return 1
fi
while IFS=, read -r codec type attached_pic; do
case "$type" in
video)
if [[ $attached_pic == 1 ]]; then
continue
fi
if [[ $codec != h264 ]]; then
invalid_reason="unsupported video codec $codec"
fi
((video_count += 1))
;;
audio)
if [[ $codec != aac ]]; then
invalid_reason="unsupported audio codec $codec"
fi
((audio_count += 1))
;;
*)
invalid_reason="unsupported $type track ($codec)"
;;
esac
done <<< "$streams"
if [[ -n $invalid_reason ]]; then
printf 'INVALID: %q: %s\n' "$file" "$invalid_reason" >&2
return 1
fi
if ((video_count != 1 || audio_count != 1)); then
printf 'INVALID: %q: expected one H.264 video and one AAC audio track; found %d video and %d audio\n' \
"$file" "$video_count" "$audio_count" >&2
return 1
fi
printf 'VALID: %s\n' "$file"
}
while IFS= read -r -d '' file; do
if validate_file "$file"; then
((valid_count += 1))
else
((invalid_count += 1))
fi
done < <(find "$media_root" -type f -iname '*.mp4' -print0)
if ((valid_count == 0)); then
echo "No valid MP4 files were found." >&2
exit 1
fi
if ((invalid_count > 0)); then
printf 'Validation failed: %d valid, %d invalid file(s).\n' "$valid_count" "$invalid_count" >&2
exit 1
fi
printf 'Validation passed: %d MP4 file(s).\n' "$valid_count"