eKr*_*nak 5 linux ffmpeg alsa raspberry-pi systemd
在带有官方 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
Run Code Online (Sandbox Code Playgroud)
脚本从控制台启动没有问题。它从 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
Run Code Online (Sandbox Code Playgroud)
重新启动 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)
Run Code Online (Sandbox Code Playgroud)
并且不会开始流式传输到 UDP 目标。但是,如果我手动登录 SSH 并发出systemctl stop Streaming,然后systemctl start Streaming, Ffmpeg 会成功启动。开机自动启动服务有什么不同?
在脚本请求时设置“睡眠超时”不会有帮助。然而,从 FFmpeg 配置中删除音频流似乎可以解决启动时自动启动的问题。
使用
After=network-online.target
Run Code Online (Sandbox Code Playgroud)
github ffmpeg显示选择输出时出现错误。
choose_output函数选择流的输出。
由于您尝试通过网络进行流式传输,因此在启动 ffmpeg 之前您需要完全配置网络。
您的 systemd 脚本中有一个小问题。network.target和之间有区别network-online.target
network.target 在启动期间没有什么意义。
network-online.target 是一个主动等待网络“启动”的目标
现在您知道为什么您的脚本在启动时无法在 systemd 中工作但在服务重新启动后它开始工作吗?
请发表评论以获取任何需要的更多说明。
| 归档时间: |
|
| 查看次数: |
3788 次 |
| 最近记录: |