我发现openRTSP(Debian 上的livemedia-utils,Arch 上的live-media)获取参数o ...(使用任意RTSP 示例源)
$ openRTSP -r rtsp://109.98.78.106
Created new TCP socket 3 for connection
Connecting to 109.98.78.106, port 554 on socket 3...
...remote connection opened
[...]
o=- 1604163122724055 1 IN IP4 109.98.78.106
[...]
...这似乎是从底层 RTC 流中提取的相机 UTC 系统时间(以微秒为单位)。
例如:
$ date -d@$( echo $(openRTSP -r rtsp://109.98.78.106 2>&1 | grep -Po '(?<=o=-\s)\d+' | head -n1 ) / 1000000 | bc )
Sat Oct 31 05:55:45 PM CET 2020
我们使用的摄像机具有 NTP 功能。因此,我在录制计算机上设置了一个本地 NTP 服务器,作为摄像机的时间源。
从延迟...
time_camera () {
# Returns cameras system time as embedded in the RTC stream in nanoseconds after UNIX 0
echo $(($(openRTSP -r ${STREAM_CAMERA} 2>&1 | grep -Po '(?<=o=-\s)\d+' | head -n1)000))
}
time_local () {
# Returns local system time in nanoseconds after UNIX 0
date +%s%N
}
vdelay=$(($(time_local) - $(time_camera)))
...我可以估计帧到达需要多长时间。
您可以根据自己的需要对其进行微调。
对我来说,它大约是 (900 +- 200) 毫秒,并且非常匹配音频-视频偏移量。
如上所述,我使用 Pulseaudio,因此可以(定期)直接设置输入延迟偏移量,而不必与 ffmpeg 的 -itsoffset 通过:
# See: pacmd list-cards
pacmd set-port-latency-offset <card> <port> $((vdelay/1000))