|
|
@@ -2,12 +2,7 @@ import os
|
|
|
import subprocess
|
|
|
import time
|
|
|
import re
|
|
|
-from setting import RTMP_URL
|
|
|
-from setting import CAM_NAME
|
|
|
-
|
|
|
-FONT_PATH = "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc"
|
|
|
-cam_name=CAM_NAME
|
|
|
-push_url=RTMP_URL
|
|
|
+from setting import RTMP_URL, CAM_NAME, AUDIO_DEVICE, FONT_PATH
|
|
|
|
|
|
# --- 配置参数 ---
|
|
|
# 替换为你的 ffmpeg 命令(建议先在终端测试成功)
|
|
|
@@ -22,7 +17,7 @@ FFMPEG_CMD = [
|
|
|
'-thread_queue_size', '8192',
|
|
|
'-f', 'alsa',
|
|
|
'-ac', '1',
|
|
|
- '-i', 'hw:1,0',
|
|
|
+ '-i', AUDIO_DEVICE,
|
|
|
'-vcodec', 'libx264',
|
|
|
'-acodec', 'aac',
|
|
|
'-b:v', '4M',
|
|
|
@@ -33,11 +28,11 @@ FFMPEG_CMD = [
|
|
|
'-tune:v', 'zerolatency',
|
|
|
'-vf', (
|
|
|
f"drawtext=fontfile={FONT_PATH}:"
|
|
|
- f"text='{cam_name} | %{{localtime\\:%Y-%m-%d %H\\\\\\:%M\\\\\\:%S}}':"
|
|
|
+ f"text='{CAM_NAME} | %{{localtime\\:%Y-%m-%d %H\\\\\\:%M\\\\\\:%S}}':"
|
|
|
"x=20:y=20:fontsize=28:fontcolor=yellow:shadowcolor=black:shadowx=2:shadowy=2"
|
|
|
),
|
|
|
'-f', 'flv',
|
|
|
- push_url
|
|
|
+ RTMP_URL
|
|
|
]
|
|
|
|
|
|
RESTART_DELAY = 5 # 重启间隔(秒)
|
|
|
@@ -70,6 +65,9 @@ def monitor_stream():
|
|
|
stats = re.findall(r'(frame=.*?bitrate=.*?speed=.*?x)', line)
|
|
|
if stats:
|
|
|
print(f"\r推流中: {stats[0].strip()}", end="")
|
|
|
+ else:
|
|
|
+ print(f"\n[FFmpeg 日志] {line.strip()}")
|
|
|
+
|
|
|
# 检查进程是否意外退出
|
|
|
if process.poll() is not None:
|
|
|
break
|