Spaces:
Paused
Paused
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time,os,sys
|
| 2 |
+
import subprocess
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
stream_url = "rtmp://a.rtmp.youtube.com/live2/your_stream_key"
|
| 6 |
+
|
| 7 |
+
def get_latest_video(directory):
|
| 8 |
+
video_files = [f for f in os.listdir(directory) if f.endswith('.mp4')]
|
| 9 |
+
if not video_files:
|
| 10 |
+
return None
|
| 11 |
+
latest_video = max(video_files, key=lambda f: os.path.getctime(os.path.join(directory, f)))
|
| 12 |
+
return os.path.join(directory, latest_video)
|
| 13 |
+
def stream_video(video_path):
|
| 14 |
+
if video_path:
|
| 15 |
+
print(f"膼ang ph谩t video m峄沬 nh岷: {video_path}")
|
| 16 |
+
subprocess.run([
|
| 17 |
+
'ffmpeg', '-re', '-i', video_path, '-c:v', 'libx264', '-preset', 'veryfast',
|
| 18 |
+
'-maxrate', '3000k', '-bufsize', '6000k', '-pix_fmt', 'yuv420p', '-g', '60',
|
| 19 |
+
'-c:a', 'aac', '-b:a', '128k', '-f', 'flv', stream_url
|
| 20 |
+
])
|
| 21 |
+
else:
|
| 22 |
+
print("Kh么ng t矛m th岷 video n脿o.")
|
| 23 |
+
while True:
|
| 24 |
+
latest_video = get_latest_video('/home/user/app/finals')
|
| 25 |
+
print(latest_video)
|
| 26 |
+
stream_video(latest_video)
|