Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sudo apt update
- sudo apt install ffmpeg jq
- nano rtmp-wrapper.sh
- ----------------------------
- ----------------------------
- #!/bin/bash
- # Define variables and functions
- RTMP_URL="rtmp://live.vaughnsoft.net/live"
- LOG_DIR="./rtmp_logs"
- CONFIG_FILE="./rtmp-config.json"
- RETRY_LIMIT=5
- RETRY_INTERVAL=10
- TIMESTAMP=$(date +'%Y%m%d_%H%M%S')
- # Create log directory if it doesn't exist
- mkdir -p "$LOG_DIR"
- # Logging function with timestamp
- log() {
- local log_level="$1"
- shift
- echo "$(date +'%Y-%m-%d %H:%M:%S') [$log_level] $@" >> "$LOG_DIR/rtmp_log_${TIMESTAMP}.log"
- }
- # Check if configuration file exists
- if [ ! -f "$CONFIG_FILE" ]; then
- log "ERROR" "Configuration file ($CONFIG_FILE) not found."
- exit 1
- fi
- # Read configuration from JSON
- VIDEO_BITRATE=$(jq -r '.video_bitrate' "$CONFIG_FILE")
- AUDIO_BITRATE=$(jq -r '.audio_bitrate' "$CONFIG_FILE")
- PRESET=$(jq -r '.preset' "$CONFIG_FILE")
- # Check if parameters are valid
- if [ -z "$VIDEO_BITRATE" ] || [ -z "$AUDIO_BITRATE" ] || [ -z "$PRESET" ]; then
- log "ERROR" "Invalid configuration in $CONFIG_FILE"
- exit 1
- fi
- # Check if input file is provided
- if [ -z "$1" ]; then
- log "ERROR" "Usage: $0 <input-file>"
- exit 1
- fi
- INPUT_FILE=$1
- log "INFO" "Starting RTMP stream to $RTMP_URL with input: $INPUT_FILE"
- log "INFO" "Video Bitrate: $VIDEO_BITRATE, Audio Bitrate: $AUDIO_BITRATE, Preset: $PRESET"
- # Retry logic for robustness
- attempt=1
- while [ $attempt -le $RETRY_LIMIT ]; do
- log "INFO" "Attempt $attempt of $RETRY_LIMIT"
- ffmpeg -re -i "$INPUT_FILE" -c:v libx264 -preset "$PRESET" -b:v "$VIDEO_BITRATE" -c:a aac -ar 44100 -b:a "$AUDIO_BITRATE" -f flv "$RTMP_URL" 2>&1 | tee -a "$LOG_DIR/rtmp_log_${TIMESTAMP}.log"
- # Check if ffmpeg succeeded
- if [ $? -eq 0 ]; then
- log "INFO" "Stream successfully started."
- break
- else
- log "ERROR" "Stream failed on attempt $attempt. Retrying in $RETRY_INTERVAL seconds..."
- attempt=$((attempt + 1))
- sleep $RETRY_INTERVAL
- fi
- done
- if [ $attempt -gt $RETRY_LIMIT ]; then
- log "ERROR" "Stream failed after $RETRY_LIMIT attempts."
- exit 1
- fi
- log "INFO" "Streaming finished successfully."
- ----------------------------
- ----------------------------
- Create the Configuration File (rtmp-config.json)
- This configuration file stores the stream settings for easy modification and customization
- {
- "video_bitrate": "1000k",
- "audio_bitrate": "128k",
- "preset": "veryfast"
- }
- chmod +x rtmp-wrapper.sh
- ./rtmp-wrapper.sh /yo/video.mp4
- example output
- 2024-11-08 12:00:00 [INFO] Starting RTMP stream to rtmp://live.vaughnsoft.net/live with input: /path/to/your/video.mp4
- 2024-11-08 12:00:00 [INFO] Video Bitrate: 1000k, Audio Bitrate: 128k, Preset: veryfast
- 2024-11-08 12:00:10 [INFO] Attempt 1 of 5
- 2024-11-08 12:00:20 [INFO] Stream successfully started.
- 2024-11-08 12:00:20 [INFO] Streaming finished successfully.
- This script is designed to be robust, reliable, and professional, making it more suitable for high-stakes environments like the FBI. It includes advanced logging, error handling, and retry logic, allowing for easy debugging and ensuring consistent streaming performance.
- Let me know if you need further enhancements or additional features!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement