mirror of
git://f0xx.org/ac/ac-ms-media-transcode
synced 2026-07-29 02:58:05 +03:00
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>
83 lines
2.2 KiB
Bash
Executable File
83 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Single encode: ingest → filter (logo/delogo) → tee → local file + named pipe (+ optional HLS).
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/lib/common.sh"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/lib/source.sh"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/lib/filters.sh"
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT}/lib/outputs.sh"
|
|
|
|
resolve_source "${1:-}"
|
|
require_cmd "${FFMPEG_BIN}"
|
|
require_logo
|
|
ensure_storage
|
|
ensure_pipe
|
|
|
|
compute_layout() {
|
|
local idx=0
|
|
VIDEO_INPUT="${idx}:v"
|
|
if [[ "${USE_YTDLP}" == "1" ]]; then
|
|
idx=0
|
|
else
|
|
idx=0
|
|
fi
|
|
if [[ ${#AUDIO_INPUT_ARGS[@]} -gt 0 ]]; then
|
|
AUDIO_MAP_INPUT=$((idx + 1))
|
|
LOGO_INPUT=$((idx + 2))
|
|
else
|
|
AUDIO_MAP_INPUT="${idx}"
|
|
LOGO_INPUT=$((idx + 1))
|
|
fi
|
|
}
|
|
|
|
compute_layout
|
|
RECORD_PATH="$(next_record_path)"
|
|
LOG_FILE="${STORAGE_DIR}/encode.log"
|
|
build_filter_complex "${VIDEO_INPUT}" "${LOGO_INPUT}:v"
|
|
TEE_SPEC="$(build_encode_tee_spec "${RECORD_PATH}" "${PIPE_PATH}")"
|
|
MAP_V="$(map_video_out)"
|
|
MAP_A="$(map_audio_out)"
|
|
|
|
run_ffmpeg() {
|
|
"${FFMPEG_BIN}" -hide_banner -loglevel info \
|
|
-rtbufsize 256M -probesize 100M -analyzeduration 250M \
|
|
"$@" \
|
|
-i "${LOGO_PATH}" \
|
|
"${FFMPEG_TS_FLAGS[@]}" \
|
|
-filter_complex "${FILTER_COMPLEX}" \
|
|
-map "${MAP_V}" -map "${MAP_A}" \
|
|
-threads "${THREADS}" -framerate "${FPS}" -r "${FPS}" \
|
|
-s "${RES}" ${VCODEC} ${PRESET} ${BITRATE} ${ACODEC} -bufsize "${BUFSIZE}" \
|
|
-f tee "${TEE_SPEC}" >> "${LOG_FILE}" 2>&1
|
|
}
|
|
|
|
cleanup() {
|
|
remove_pipe
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
log "recording → ${RECORD_PATH}"
|
|
log "pipe → ${PIPE_PATH}"
|
|
[[ -n "${HLS_OUTPUT_DIR}" ]] && log "HLS → ${HLS_OUTPUT_DIR}"
|
|
|
|
if [[ "${USE_YTDLP}" == "1" ]]; then
|
|
require_cmd "${YTDLP_BIN}"
|
|
mapfile -d '' -t YTDLP_CMD < <(build_ytdlp_pipeline)
|
|
"${YTDLP_CMD[@]}" 2>>"${LOG_FILE}" | \
|
|
run_ffmpeg -thread_queue_size "${THREAD_QUEUE_SIZE}" -i pipe:0 \
|
|
"${AUDIO_INPUT_ARGS[@]}"
|
|
else
|
|
read_rate_flag
|
|
run_ffmpeg \
|
|
"${RE_FLAG[@]}" \
|
|
-thread_queue_size "${THREAD_QUEUE_SIZE}" \
|
|
-reconnect_on_network_error 1 -reconnect_streamed 1 -reconnect_delay_max 5 \
|
|
-i "${SOURCE_URL}" \
|
|
"${AUDIO_INPUT_ARGS[@]}"
|
|
fi
|