【问题标题】:Systemd service (python loop -> ffmpeg stream)Systemd 服务(python 循环 -> ffmpeg 流)
【发布时间】:2018-06-01 06:52:00
【问题描述】:

我目前正在使用 ffmpeg 通过 icecast2 通过 python sn-p (Fig1 )。我创建了一个 systemd 服务以在启动时运行上述 python 脚本 (Fig2) 并使用自定义目标 (Fig3) 以确保它在所有其他服务加载后加载,主要用于 icecast2

我已经进行了多次测试,如果从 python 代码启动或重新启动附加到它的服务,流可以正常工作。

我的问题是,在系统(重新)启动时,服务运行了大约 15 秒,然后流死了。我已经阅读了很多关于 pythonsystemd 的内容,但我终其一生都无法弄清楚问题出在哪里。我尝试更改我的 python 代码、单元加载顺序以及我在网上找到的任何其他可以提供帮助的内容,但一无所获。

图1 (dxstream.py)

import sys
import time
import subprocess

def start():
    return subprocess.Popen(r’ffpmeg -re -f alsa -ac2 -i hw:1,0 -acodec mp3 -ab 320k -f mp3 icecast://sourcehackme@localhost:8000/stream', shell=True)

testProcess = start()

while True:

    res = testProcess.poll()
    if res is not None:
        testProcess = start()
    time.sleep(1)

Fig2 (dxstream.service)

[Unit]
Description=ffmpeg stream starter
After=multi-user.target
[Service]
Type=idle
Execstart=/usr/bin/python /usr/local/bin/dxstream.py
Restart=on-failure

[Install]
WantedBy=custom.target

Fig3 (custom.target)

[Unit]
Description=Custom Target
Requires=multi-user.target
After=multi-user.target
AllowIsolate=yes

【问题讨论】:

    标签: python ffmpeg stream debian systemd


    【解决方案1】:

    我已将 ffmpeg 流的报告设置为 ON,并跟踪设备的启动过程,它似乎在 IceCast 仍在初始化时过早地创建了指向 IceCast 的链接。我为第一次启动的脚本本身添加了 30 秒的延迟,现在它可以正常工作了。

    结束这个话题!

    【讨论】:

      猜你喜欢
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多