tit.stm / main.py
alptangall's picture
Create main.py
5c9d912 verified
raw
history blame contribute delete
999 Bytes
import time,os,sys
import subprocess
import gradio as gr
stream_url = "rtmp://a.rtmp.youtube.com/live2/your_stream_key"
def get_latest_video(directory):
video_files = [f for f in os.listdir(directory) if f.endswith('.mp4')]
if not video_files:
return None
latest_video = max(video_files, key=lambda f: os.path.getctime(os.path.join(directory, f)))
return os.path.join(directory, latest_video)
def stream_video(video_path):
if video_path:
print(f"Đang phát video mới nhất: {video_path}")
subprocess.run([
'ffmpeg', '-re', '-i', video_path, '-c:v', 'libx264', '-preset', 'veryfast',
'-maxrate', '3000k', '-bufsize', '6000k', '-pix_fmt', 'yuv420p', '-g', '60',
'-c:a', 'aac', '-b:a', '128k', '-f', 'flv', stream_url
])
else:
print("Không tìm thấy video nào.")
while True:
latest_video = get_latest_video('/home/user/app/finals')
print(latest_video)
stream_video(latest_video)