Explorar el Código

将 AUDIO_DEVICE 和 FONT_PATH 放到 setting.py, 可进行配置

reghao hace 8 horas
padre
commit
8230e76da9
Se han modificado 2 ficheros con 9 adiciones y 9 borrados
  1. 7 9
      picam.py
  2. 2 0
      setting.py

+ 7 - 9
picam.py

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

+ 2 - 0
setting.py

@@ -1,3 +1,5 @@
+AUDIO_DEVICE = "hw:1,0"
+FONT_PATH = "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc"
 CAM_NAME = "picam"
 CAM_NAME = "picam"
 RTMP_URL = "rtmp://abc.rtmp.com/abc/picam"
 RTMP_URL = "rtmp://abc.rtmp.com/abc/picam"
 WEBHOOK_URL = "https://oapi.dingtalk.com/robot/send?access_token=1234567890"
 WEBHOOK_URL = "https://oapi.dingtalk.com/robot/send?access_token=1234567890"