admin
2025-08-22 ec060ce444cdd1c48a54686cadbc8950478eedcf
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
import os
import threading
import time
 
 
def __push(video_path, roomId):
    print(video_path, roomId)
    cmd = f"ffmpeg -re -i {video_path} -c copy -f flv rtmp://127.0.0.1/live/{roomId}"
    print(cmd)
    os.system(cmd)
 
 
def __get_video_file(path, file_set):
    if os.path.isfile(path):
        file_set.add(path)
    else:
        files = os.listdir(path)
        for f in files:
            __get_video_file(f"{path}/{f}", file_set)
 
 
# 初始化数据
def __start_push():
    base_dir = "/root/videos"
    files = set()
    __get_video_file(base_dir, files)
    for file in files:
        t1 = threading.Thread(target=lambda xf=file: __push(xf, xf.split('_')[-1].split('.')[0]))
        t1.setDaemon(True)
        t1.start()
 
 
if __name__ == "__main__":
    __start_push()
    while True:
        time.sleep(1)