Advertisement
Sweetening

vaughnsoft wrapper

Nov 8th, 2024 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. sudo apt update
  2. sudo apt install ffmpeg jq
  3. nano rtmp-wrapper.sh
  4.  
  5. ----------------------------
  6. ----------------------------
  7.  
  8. #!/bin/bash
  9.  
  10. # Define variables and functions
  11. RTMP_URL="rtmp://live.vaughnsoft.net/live"
  12. LOG_DIR="./rtmp_logs"
  13. CONFIG_FILE="./rtmp-config.json"
  14. RETRY_LIMIT=5
  15. RETRY_INTERVAL=10
  16. TIMESTAMP=$(date +'%Y%m%d_%H%M%S')
  17.  
  18. # Create log directory if it doesn't exist
  19. mkdir -p "$LOG_DIR"
  20.  
  21. # Logging function with timestamp
  22. log() {
  23. local log_level="$1"
  24. shift
  25. echo "$(date +'%Y-%m-%d %H:%M:%S') [$log_level] $@" >> "$LOG_DIR/rtmp_log_${TIMESTAMP}.log"
  26. }
  27.  
  28. # Check if configuration file exists
  29. if [ ! -f "$CONFIG_FILE" ]; then
  30. log "ERROR" "Configuration file ($CONFIG_FILE) not found."
  31. exit 1
  32. fi
  33.  
  34. # Read configuration from JSON
  35. VIDEO_BITRATE=$(jq -r '.video_bitrate' "$CONFIG_FILE")
  36. AUDIO_BITRATE=$(jq -r '.audio_bitrate' "$CONFIG_FILE")
  37. PRESET=$(jq -r '.preset' "$CONFIG_FILE")
  38.  
  39. # Check if parameters are valid
  40. if [ -z "$VIDEO_BITRATE" ] || [ -z "$AUDIO_BITRATE" ] || [ -z "$PRESET" ]; then
  41. log "ERROR" "Invalid configuration in $CONFIG_FILE"
  42. exit 1
  43. fi
  44.  
  45. # Check if input file is provided
  46. if [ -z "$1" ]; then
  47. log "ERROR" "Usage: $0 <input-file>"
  48. exit 1
  49. fi
  50.  
  51. INPUT_FILE=$1
  52.  
  53. log "INFO" "Starting RTMP stream to $RTMP_URL with input: $INPUT_FILE"
  54. log "INFO" "Video Bitrate: $VIDEO_BITRATE, Audio Bitrate: $AUDIO_BITRATE, Preset: $PRESET"
  55.  
  56. # Retry logic for robustness
  57. attempt=1
  58. while [ $attempt -le $RETRY_LIMIT ]; do
  59. log "INFO" "Attempt $attempt of $RETRY_LIMIT"
  60. 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"
  61.  
  62. # Check if ffmpeg succeeded
  63. if [ $? -eq 0 ]; then
  64. log "INFO" "Stream successfully started."
  65. break
  66. else
  67. log "ERROR" "Stream failed on attempt $attempt. Retrying in $RETRY_INTERVAL seconds..."
  68. attempt=$((attempt + 1))
  69. sleep $RETRY_INTERVAL
  70. fi
  71. done
  72.  
  73. if [ $attempt -gt $RETRY_LIMIT ]; then
  74. log "ERROR" "Stream failed after $RETRY_LIMIT attempts."
  75. exit 1
  76. fi
  77.  
  78. log "INFO" "Streaming finished successfully."
  79. ----------------------------
  80. ----------------------------
  81. Create the Configuration File (rtmp-config.json)
  82. This configuration file stores the stream settings for easy modification and customization
  83.  
  84. {
  85. "video_bitrate": "1000k",
  86. "audio_bitrate": "128k",
  87. "preset": "veryfast"
  88. }
  89.  
  90.  
  91. chmod +x rtmp-wrapper.sh
  92. ./rtmp-wrapper.sh /yo/video.mp4
  93.  
  94.  
  95. example output
  96.  
  97. 2024-11-08 12:00:00 [INFO] Starting RTMP stream to rtmp://live.vaughnsoft.net/live with input: /path/to/your/video.mp4
  98. 2024-11-08 12:00:00 [INFO] Video Bitrate: 1000k, Audio Bitrate: 128k, Preset: veryfast
  99. 2024-11-08 12:00:10 [INFO] Attempt 1 of 5
  100. 2024-11-08 12:00:20 [INFO] Stream successfully started.
  101. 2024-11-08 12:00:20 [INFO] Streaming finished successfully.
  102.  
  103. 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.
  104.  
  105. Let me know if you need further enhancements or additional features!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement