【发布时间】:2020-11-02 21:26:07
【问题描述】:
在带有官方 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
脚本从控制台启动没有问题。它从 USB 声卡获取音频,从 USB 摄像头获取视频,并创建 UDP 流到 IPTV。然后我创建了 Systemd 服务:
[Unit]
Description=Streamer
After=multi-user.target sound.target network.target
[Service]
ExecStart=/home/pi/run.sh
KillMode=control-group
Restart=on-failure
TimeoutSec=1
[Install]
WantedBy=multi-user.target
Alias=streaming.service
重启树莓后,脚本已经启动,但是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 streaming Ffmpeg 启动成功。启动时服务自动启动有什么不同?
在脚本请求时设置“睡眠超时”将无济于事。但是,从 FFmpeg 配置中删除音频流似乎可以解决开机自动启动问题。
【问题讨论】:
-
当你在脚本中将
sleep 30放在 ffmpeg 之前,你是否得到了同样的错误? -
是的,我提到过这个问题。没有区别。
标签: linux ffmpeg raspberry-pi systemd alsa