File size: 1,233 Bytes
40110d6
 
 
 
 
 
 
 
 
 
31f3a1b
40110d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import random
import subprocess
from multiprocessing import Process
import uvicorn
from fastapi import FastAPI

app = FastAPI()

video_directory = "/app"
rtmp_url = "rtmp://live.twitch.tv/app/live_1104664009_xoiSdq7ayaMdFKU4xaCzkCqLw3tYvz"
ffmpeg_command = 'ffmpeg -re -i "{input}" -c:v libx264 -b:v 5000.00k -c:a aac -b:a 128.00k -preset ultrafast -f flv "{output}"'

def get_video_list():
    return [f for f in os.listdir(video_directory) if f.endswith('.mp4')]

def stream_video():
    videos = get_video_list()
    random.shuffle(videos)  # Mezclar videos inicialmente
    while True:
        for video in videos:
            video_path = os.path.join(video_directory, video)
            command = ffmpeg_command.format(input=video_path, output=rtmp_url)
            process = subprocess.Popen(command, shell=True)
            process.wait()
        random.shuffle(videos)  # Volver a mezclar después de reproducir todos los videos

def start_video_streaming():
    video_process = Process(target=stream_video)
    video_process.start()

@app.get("/")
async def read_root():
    return {"message": "Hello World"}

if __name__ == "__main__":
    start_video_streaming()
    uvicorn.run(app, host="0.0.0.0", port=7860)