#!/bin/bash set -u RTSP_URL="rtsp://*****:******@*******:554/stream1" RTMP_URL="rtmp://live.restream.io/live/re_**********" MUBERT_URL="https://stream.mubert.com/b2b/v2?playlist=6.4.3&****************" # Defaults for prompts (can override via env) STREAM_DAYS="${STREAM_DAYS:-0}" STREAM_HOURS="${STREAM_HOURS:-0}" STREAM_MINS="${STREAM_MINS:-1}" # ======================================================== SCRIPT_PATH="$0" SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)" LOG_FILE="$HOME/stream.log" # live == persistent (same file, like your original) CUR_LOG="$LOG_FILE" # Colors (green = view logs, red = kill) if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then C_RED="$(tput setaf 1)"; C_GREEN="$(tput setaf 2)"; T_BOLD="$(tput bold)"; T_RESET="$(tput sgr0)" else C_RED=""; C_GREEN=""; T_BOLD=""; T_RESET="" fi # Pick a writable place for helper if [ -w "$SCRIPT_DIR" ]; then LOG_HELPER="$SCRIPT_DIR/stream-log" else LOG_HELPER="$HOME/stream-log" fi # ---------- Preflight: only kill prior ffmpeg we named ---------- pkill -f 'ffmpeg stream' 2>/dev/null || true sleep 0.2 pkill -9 -f 'ffmpeg stream' 2>/dev/null || true # ---------- Prompts ---------- echo "--- Stream Duration ---" read -p "Enter duration in DAYS (default: ${STREAM_DAYS}): " DAYS_INPUT || true read -p "Enter duration in HOURS (default: ${STREAM_HOURS}): " HOURS_INPUT || true read -p "Enter duration in MINUTES (default: ${STREAM_MINS}): " MINS_INPUT || true DAYS=${DAYS_INPUT:-$STREAM_DAYS} HOURS=${HOURS_INPUT:-$STREAM_HOURS} MINS=${MINS_INPUT:-$STREAM_MINS} for vname in DAYS HOURS MINS; do vval="${!vname}" [[ "$vval" =~ ^[0-9]+$ ]] || { echo "Invalid ${vname}: ${vval}"; exit 1; } done TOTAL_SECONDS=$((DAYS*86400 + HOURS*3600 + MINS*60)) [ "$TOTAL_SECONDS" -le 0 ] && { echo "Error: Total duration must be greater than zero."; exit 1; } # ---------- Prepare log ---------- : > "$LOG_FILE" # ---------- Helper to tail logs (viewer only) ---------- cat > "$LOG_HELPER" <<'EOF' #!/bin/bash CUR_LOG="$HOME/stream.log" if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then C_GREEN="$(tput setaf 2)"; T_BOLD="$(tput bold)"; T_RESET="$(tput sgr0)" else C_GREEN=""; T_BOLD=""; T_RESET="" fi echo "${C_GREEN}${T_BOLD}Live log:${T_RESET} $CUR_LOG" echo echo "Press Ctrl+C to stop VIEWING the logs (the stream continues)." exec tail -F "$CUR_LOG" EOF chmod +x "$LOG_HELPER" 2>/dev/null || true # ---------- Info ---------- echo echo "IMPORTANT: This stream ignores hotkeys (Ctrl+C / Ctrl+Z) and will detach now." echo "Stop immediately: ${C_RED}${T_BOLD}pkill -f 'ffmpeg stream'${T_RESET}" echo echo "How to monitor and control this stream:" echo " ${C_GREEN}${T_BOLD} • View logs now:${T_RESET} $LOG_HELPER (recommended; opens tail immediately)" echo " ${C_GREEN}${T_BOLD} • View live log only:${T_RESET} tail -F \"$CUR_LOG\"" echo " • Check active process: ps ax | grep 'ffmpeg stream'" echo echo " ${C_RED}${T_BOLD}TO STOP IMMEDIATELY:${T_RESET} pkill -f 'ffmpeg stream'" echo echo "Stream will run for ${DAYS} day(s), ${HOURS} hour(s), and ${MINS} minute(s)." echo echo "Detaching now. All further output goes to $LOG_FILE." # ---------- Launch stream (double-fork + nohup) ---------- # - Keeps your original ffmpeg line, adding only safe thread queues and HTTP reconnects. # - Removed unsupported -rw_timeout (that caused your error). ( exec /dev/null 2>&1 nohup bash -c "exec -a 'ffmpeg stream' timeout ${TOTAL_SECONDS}s ffmpeg \ -rtsp_transport tcp -fflags nobuffer \ -use_wallclock_as_timestamps 1 -fflags +genpts \ -thread_queue_size 512 -i \"$RTSP_URL\" \ -reconnect 1 -reconnect_streamed 1 -reconnect_at_eof 1 \ -reconnect_on_network_error 1 -reconnect_on_http_error 4xx,5xx -reconnect_delay_max 2 \ -thread_queue_size 512 -i \"$MUBERT_URL\" \ -map 0:v:0 -map 1:a:0 \ -fps_mode passthrough -copytb 1 \ -c:v copy \ -c:a aac -b:a 128k -ar 44100 -ac 2 \ -muxpreload 0 -muxdelay 0 \ -f flv \"$RTMP_URL\"" >> "$LOG_FILE" 2>&1 & disown ) & # ---------- Tail viewer (Ctrl+C stops viewing only) ---------- exec "$LOG_HELPER" ## #!/bin/bash ## # Companion log viewer for stream-x1c. Tails both live and error logs. ## ## CUR_LOG="$HOME/stream.current.log" ## LOG_FILE="$HOME/stream.log" ## ## # Optional green headings if interactive ## if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then ## C_GREEN="$(tput setaf 2)"; T_BOLD="$(tput bold)"; T_RESET="$(tput sgr0)" ## else ## C_GREEN=""; T_BOLD=""; T_RESET="" ## fi ## ## # Follow both files, even if rotated/recreated ## exec tail -F "$CUR_LOG" "$LOG_FILE" ########### make stream-log file with this content without ## comments for block above for this to work in /usr/local/bin