mirror of
git://f0xx.org/ac/ac-ms-media-transcode
synced 2026-07-29 04:17:51 +03:00
Add lab restream pipeline with pirate_drift logo and lib/env.sh.
Encode-once/fanout scripts, HLS output, and single overloadable env source. Commits assets/pirate_drift.png as default watermark for cluster runs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
98
lib/common.sh
Normal file
98
lib/common.sh
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
# Shared bootstrap: ROOT, env defaults, encoding presets, pipe helpers.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
export ROOT
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source "${ROOT}/lib/logging.sh"
|
||||
# shellcheck disable=SC1091
|
||||
source "${ROOT}/lib/env.sh"
|
||||
|
||||
apply_encoding_preset() {
|
||||
case "${OUTPUT_PRESET}" in
|
||||
720p)
|
||||
WIDTH=1280
|
||||
HEIGHT=720
|
||||
FASTNESS=veryfast
|
||||
BV=2500k
|
||||
BUFSIZE=5000k
|
||||
;;
|
||||
1080p|*)
|
||||
WIDTH=1920
|
||||
HEIGHT=1080
|
||||
FASTNESS=faster
|
||||
BV=5000k
|
||||
BUFSIZE=10000k
|
||||
;;
|
||||
esac
|
||||
export WIDTH HEIGHT FASTNESS BV BUFSIZE
|
||||
RES="${WIDTH}x${HEIGHT}"
|
||||
PROFILE=high
|
||||
KEYFRAMES_INTL="${FPS}"
|
||||
GOP_INTL=$((KEYFRAMES_INTL * 2))
|
||||
PIX_FMT="-pix_fmt yuv420p"
|
||||
PRESET="-preset ${FASTNESS} -tune zerolatency -profile:v ${PROFILE} ${PIX_FMT} -x264-params keyint=${KEYFRAMES_INTL}:min-keyint=${KEYFRAMES_INTL} -g ${GOP_INTL} -flags +global_header"
|
||||
BITRATE="-b:v ${BV} -maxrate ${BV} -minrate ${BV}"
|
||||
VCODEC="-c:v libx264"
|
||||
ACODEC="-c:a aac -b:a 128k"
|
||||
export RES PROFILE PRESET BITRATE VCODEC ACODEC
|
||||
}
|
||||
|
||||
apply_encoding_preset
|
||||
|
||||
FFMPEG_TS_FLAGS=(
|
||||
-fflags +genpts+igndts
|
||||
-avoid_negative_ts make_zero
|
||||
-sn
|
||||
-movflags +faststart
|
||||
)
|
||||
|
||||
read_rate_flag() {
|
||||
if [[ "${NEAR_REALTIME}" == "1" ]]; then
|
||||
RE_FLAG=(-re)
|
||||
else
|
||||
RE_FLAG=()
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_storage() {
|
||||
mkdir -p "${STORAGE_DIR}" "${RUN_DIR}"
|
||||
}
|
||||
|
||||
ensure_pipe() {
|
||||
if [[ ! -p "${PIPE_PATH}" ]]; then
|
||||
mkfifo "${PIPE_PATH}"
|
||||
if command -v perl >/dev/null 2>&1; then
|
||||
perl -MFcntl -e 'fcntl(STDIN, 1031, shift) or die $!' "${PIPE_FIFO_SIZE}" <> "${PIPE_PATH}" || true
|
||||
fi
|
||||
fi
|
||||
exec 7<> "${PIPE_PATH}"
|
||||
}
|
||||
|
||||
remove_pipe() {
|
||||
exec 7>&- 7<&- 2>/dev/null || true
|
||||
rm -f "${PIPE_PATH}" 2>/dev/null || true
|
||||
}
|
||||
|
||||
next_record_path() {
|
||||
local counter=0 name
|
||||
ensure_storage
|
||||
while true; do
|
||||
name="$(printf "video%04d.%s" "${counter}" "${RECORD_FORMAT}")"
|
||||
if [[ ! -f "${STORAGE_DIR}/${name}" ]]; then
|
||||
echo "${STORAGE_DIR}/${name}"
|
||||
return
|
||||
fi
|
||||
counter=$((counter + 1))
|
||||
done
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"
|
||||
}
|
||||
|
||||
require_logo() {
|
||||
[[ -f "${LOGO_PATH}" ]] || die "logo not found at ${LOGO_PATH} (expected ${ROOT}/assets/pirate_drift.png)"
|
||||
}
|
||||
Reference in New Issue
Block a user