Spaces:
Running
Running
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import time
|
3 |
+
import os
|
4 |
+
from threading import Thread
|
5 |
+
from datetime import datetime
|
6 |
+
import server
|
7 |
+
import requests
|
8 |
+
def start_livestream(video_path):
|
9 |
+
ffmpeg_command = [
|
10 |
+
"ffmpeg",
|
11 |
+
"-re",
|
12 |
+
"-stream_loop", "-1",
|
13 |
+
"-i", 'video.mp4',
|
14 |
+
"-c:v", "libx264",
|
15 |
+
"-preset", "veryfast",
|
16 |
+
"-maxrate", "3000k",
|
17 |
+
"-bufsize", "6000k",
|
18 |
+
"-pix_fmt", "yuv420p", # Đảm bảo định dạng pixel được hỗ trợ
|
19 |
+
"-vf", "format=yuv420p", # Chuyển đổi video đầu vào sang yuv420p
|
20 |
+
"-g", "50",
|
21 |
+
"-c:a", "aac",
|
22 |
+
"-b:a", "128k",
|
23 |
+
"-ar", "44100",
|
24 |
+
"-f", "flv",
|
25 |
+
f"rtmp://a.rtmp.youtube.com/live2/agmy-bsya-r9j1-up14-fcj0"
|
26 |
+
]
|
27 |
+
return subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
28 |
+
if __name__ == "__main__":
|
29 |
+
start_livestream()
|