Linux FFmpeg手动启动,但启动时不使用Systemd

Linux FFmpeg手动启动,但启动时不使用Systemd,linux,ffmpeg,raspberry-pi,systemd,alsa,Linux,Ffmpeg,Raspberry Pi,Systemd,Alsa,在带有官方Debian 10图像的Raspberry Pi 4 B 4GB上,我有/home/Pi/run.sh脚本,其中包含以下内容: #!/bin/bash ffmpeg -nostdin -framerate 15 -video_size 1280x720 -input_format yuyv422 -i /dev/video0 -f alsa -i hw:Device \ -af acompressor=threshold=-14dB:ratio=9:attack=10:rel

在带有官方Debian 10图像的Raspberry Pi 4 B 4GB上,我有/home/Pi/run.sh脚本,其中包含以下内容:

#!/bin/bash
ffmpeg -nostdin -framerate 15 -video_size 1280x720 -input_format yuyv422  -i /dev/video0 -f alsa -i hw:Device \
    -af acompressor=threshold=-14dB:ratio=9:attack=10:release=1000 -c:a aac -ac 2 -ar 48000 -ab 160k \
    -c:v libx264 -pix_fmt yuv420p -b:v 3M -bf 1 -g 20 -flags +ilme+ildct -preset ultrafast \
    -streamid 0:0x101 -streamid 1:0x100 -mpegts_pmt_start_pid 4096 -mpegts_start_pid 0x259 -metadata:s:a:0 language="" -mpegts_service_id 131 -mpegts_transport_stream_id 9217 -metadata provider_name="Doesnt matter" -metadata service_name="Doesnt matter" \
    -minrate 3500 -maxrate 3500k -bufsize 4500k -muxrate 4000k  -f mpegts "udp://@239.1.67.13:1234?pkt_size=1316&bitrate=4000000&dscp=34" -loglevel debug < /dev/null > /tmp/ff3.log 2>&1
重新启动Raspberry后,脚本已启动,但FFmpeg挂起日志中的错误失败:

cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
并且不会开始流式传输到UDP目标。但是,如果我手动登录到SSH并发出systemctl stop streaming,然后systemctl start streamingFfmpeg成功启动。开机自动启动服务有什么不同

在脚本请求时设置“睡眠超时”将没有帮助。然而,从FFmpeg配置中删除音频流似乎可以解决开机自动启动问题。

TLDR 使用

逐步找出真正的问题。 1.这个错误告诉了我们什么。 显示选择输出时发生的错误。
choose_output
函数为流选择输出

2.为什么输出没有准备好? 由于您正试图通过网络传输数据,所以在启动ffmpeg之前,您需要完全配置网络

您的systemd脚本中有一个小问题。
网络。target
网络在线。target

跟随

network.target在启动期间几乎没有意义

network-online.target是一个主动等待直到网络“启动”的目标

现在您知道了为什么脚本在启动时不能在systemd中工作,但在服务重新启动后它开始工作了吗


如果需要更多的澄清,请发表评论。

当您在脚本中将
sleep 30
放在ffmpeg之前时,是否也出现了相同的错误?是的,我在问题中提到过。没什么区别,没用。我认为改用网络在线。target应该有类似于在开始时设置睡眠的效果。而且它也不起作用。我甚至尝试记录到文件(.mp4),它不等待网络启动,我在日志中看到了相同的错误。现在唯一的解决方法是从配置中删除音频ALSA音频流,然后它将成功启动。检查您的sound.target是否包含对USB声卡的依赖项。你能为设备添加日志吗?
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (257) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (256) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
After=network-online.target