#!/bin/bash

# Define the directories where your video files are located
VIDEO_DIR="/home/mmrpmm/Videos"
MUSIC_VIDEO_DIR="/home/mmrpmm/Videos/Music_Video_Collection"

# Define the RTMP server URL
RTMP_URL="rtmp://localhost/live/stream"

# Infinite loop to keep streaming videos
while true; do
    # Loop over all video files in the main video directory (both .mkv and .mp4)
    for video in "$VIDEO_DIR"/*.{mkv,mp4}; do
        [ -e "$video" ] || continue # Skip if no files are found
        echo "Streaming $video to $RTMP_URL..."
        ffmpeg -re -i "$video" \
               -c:v copy \
               -c:a aac -b:a 128k -ar 44100 \
               -f flv "$RTMP_URL"
    done
    
    # Loop over all video files in the Music Video Collection directory (both .mkv and .mp4)
    for video in "$MUSIC_VIDEO_DIR"/*.{mkv,mp4}; do
        [ -e "$video" ] || continue # Skip if no files are found
        echo "Streaming $video to $RTMP_URL..."
        ffmpeg -re -i "$video" \
               -c:v copy \
               -c:a aac -b:a 128k -ar 44100 \
               -f flv "$RTMP_URL"
    done
done

