Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#!/bin/bash# Normalize every file in raw/ into encoded/ with identical stream parameters,# so the 24/7 loop can concat + stream with -c copy (no live transcoding).# 1280x720 pillarboxed, 30fps, h264 2.5Mbps (VideoToolbox), AAC 128k 48kHz stereo.# Idempotent: skips outputs that already exist and are newer than their source.set -ucd "$(dirname "$0")/.."mkdir -p encoded logs
shopt -s nullglobfail=0for src in raw/*.mp4 raw/*.mkv raw/*.avi raw/*.m4v; do base=$(basename "$src") out="encoded/${base%.*}.mp4" if [[ -f $out && $out -nt $src ]]; then echo "ok $out" continue fi # Policy: no mute films on the channel. A source without an audio track is # skipped and flagged so it can be re-sourced from a scored copy or dropped. if ! ffprobe -v error -select_streams a -show_entries stream=codec_type -of csv=p=0 "$src" | grep -q audio; then echo "NOAUDIO $base (skipped; re-source a scored copy)" | tee -a logs/noaudio.log continue fi # Periodic identification watermark: a branded pill with the film title, # shown for $WM_ON seconds every $WM_EVERY seconds (after the first minute), # burned in here so the live loop stays -c copy. WM_ON=8; WM_EVERY=300 wm="overlays/${base%.*}.png" basevf="scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30" if [[ -f $wm ]]; then vargs=(-i "$wm" -filter_complex "[0:v]${basevf}[v];[v][1:v]overlay=24:main_h-overlay_h-24:enable='gt(t,60)*lt(mod(t,${WM_EVERY}),${WM_ON})'[vout]" -map "[vout]" -map 0:a:0) else echo "note: no overlay pill for '$base'" vargs=(-map 0:v:0 -map 0:a:0 -vf "$basevf") fi echo "encode $out" nice -n 15 ffmpeg -hide_banner -loglevel error -y -i "$src" "${vargs[@]}" \ -c:v h264_videotoolbox -b:v 2500k -maxrate 3000k -bufsize 6000k -profile:v high -g 60 \ -c:a aac -ar 48000 -ac 2 -b:a 128k \ -movflags +faststart \ "$out" || { echo "FAILED $base"; rm -f "$out"; fail=1; }done[[ $fail -eq 0 ]] && echo "All encodes complete." || echo "Some encodes failed."exit $fail