
是否可以使用 ffmpeg+pyhton 或結合其他解決方案來解決這個問題。我需要一個伺服器解決方案,所以Vmix、obs等不適合。 (例如:我有兩個(和/或更多)流
rtmp://host/live/input_stream_1
rtmp://host address/live/input_stream_2
ect
是否可以組織流的「路由」(選擇優先順序即時視訊串流並根據邏輯對其應用層:
有input_stream_1
- 它是預設的和本地的 - 來自網頁資料夾的影片透過 ffmpeg 打包並飛到rtmp://host address/live/output_stream_1A
(+覆蓋層 -ect 標誌)。
有必要,當input_stream_2
出現傳入流時,將 的內容替換為 的input_stream_1
內容input_stream_2
並發送它,當input_stream_2
停止時,要返回input_stream_1
嗎?
也許它將是 ffmpeg 的組合(如這個線程並在這個線程) 和蟒蛇解決方案。
各層的邏輯可能如下圖所示:PIC
答案1
import subprocess
設定輸入和輸出流
input_stream_1 =“rtmp://host/live/input_stream_1” input_stream_2 =“rtmp://host/live/input_stream_2”output_stream =“rtmp://host/live/output_stream”
設定預設輸入流
當前輸入流=輸入流1
設定要套用於流的覆蓋層
override_layers = "-i logo.png -filter_complex 覆蓋"
使用 while 迴圈連續讀取和路由流
while True: # 使用FFmpeg讀取目前輸入流並寫入輸出流 ffmpeg_command = f"ffmpeg -i {current_input_stream} {overlay_layers} -c copy {output_stream}" subprocess.run(ffmpeg_command, shell=True)
# Check for incoming streams and switch to them if necessary
if incoming_stream_2_is_active():
current_input_stream = input_stream_2
else:
current_input_stream = input_stream_1