Live lipsync from different inputs and RTCSTART in (a)setpts
Hello! I am trying to deal with syncing audio and video from different sources for live streaming. Need to mention that video source PTS cannot be fully trusted there, some duplicates or drops should be made to maintain PTS in sync with wall clock. One way to synchronise the sources is by ensuring the input PTS are aligned for audio and video. Input PTS can be updated by setpts/asetpts filters. And wallclock could be the common clock source to rely on as inputs cannot reference one another. But there is a problem, that RTCSTART field (that is "The wallclock (RTC) time at the start of the movie in microseconds.") doesn't contain the exact wallclock when the PTS of the input is started (initiated). It contains the time when the setpts/asetpts filter is initiated. It differs from the timestamp from which PTS is offseted and so it cannot be used as a trusted timing reference source. At least for precision required to ensure lip-sync. And I didn't find any other parameter that could give system time from which components PTS time is offseted to rely on. One way to pass desired wallclock value to RTCSTART parameter is to create a patch that: 1) adds extra field containing wallclock of the input start to InputFile, AVFrame, AVPacket, 2) sets RTCSTART from the AVFrame upon first frame passing through the setpts/asetpts filter, like it is done for STARTPTS and STARTT variables. Tested and that works fine at least for my use case. Kinda don't really like the "dragging" of extra field in AVFrame and AVPacket that are needed only for initialisation. Some thoghts on other (maybe better) ways how the lip-sync could be achieved? Or wallclock time value passed from input to setpts filter? Best regards, Vilnis
On 2025-01-13 08:39 pm, Vilnis Bicevskis wrote:
Or wallclock time value passed from input to setpts filter?
For each input, you can add `-use_wallclock_as_timestamps true` Regards, Gyan
Le 13 janv. 2025 à 19:03, Gyan Doshi <ffmpeg@gyani.pro> a écrit :
On 2025-01-13 08:39 pm, Vilnis Bicevskis wrote: Or wallclock time value passed from input to setpts filter?
For each input, you can add `-use_wallclock_as_timestamps true`
Unfortunatelly that didn’t solve the problem for me. As there are some 127 msec difference between intitialisation of video and audio, this difference is kept onwards ending video always having some 3-4 frames in buffer and thus being guilty for some 3-4 frame large lip-sync error. You can see that in logs where in “demuxer+ffmpeg” lines pkt_pts and pkt_pts_time are aligned, but in “demuxer” lines there is this > 120 msec difference in pkt_pts between audio and video. Any ideas how to overcome that? Relevant log lines: 1736836667.268472 test04 stream[975228]: demuxer -> ist_index:2 type:audio next_dts:1638396 next_dts_time:1.6384 next_pts:1638396 next_pts_time:1.6384 pkt_pts:1736836667264586 pkt_pts_time:1.73684e+09 pkt_dts:1736836667264586 pkt_dts_time:1.73684e+09 duration:85333 duration_time:0.085333 off:-1736836665630634 off_time:-1.73684e+09 start_time:NOPTS 1736836667.268528 test04 stream[975228]: demuxer+ffmpeg -> ist_index:2 type:audio pkt_pts:1633952 pkt_pts_time:1.63395 pkt_dts:1633952 pkt_dts_time:1.63395 duration:85333 duration_time:0.085333 off:-1736836665630634 off_time:-1.73684e+09 1736836667.270123 test04 stream[975228]: demuxer -> ist_index:1 type:video next_dts:1600019 next_dts_time:1.60002 next_pts:1600019 next_pts_time:1.60002 pkt_pts:1736836667102651 pkt_pts_time:1.73684e+09 pkt_dts:1736836667102651 pkt_dts_time:1.73684e+09 duration:40000 duration_time:0.04 off:-1736836665502741 off_time:-1.73684e+09 start_time:NOPTS 1736836667.270264 test04 stream[975228]: demuxer+ffmpeg -> ist_index:1 type:video pkt_pts:1599910 pkt_pts_time:1.59991 pkt_dts:1599910 pkt_dts_time:1.59991 duration:40000 duration_time:0.04 off:-1736836665502741 off_time:-1.73684e+09 1736836667.273893 test04 stream[975228]: demuxer -> ist_index:1 type:video next_dts:1639910 next_dts_time:1.63991 next_pts:1639910 next_pts_time:1.63991 pkt_pts:1736836667102651 pkt_pts_time:1.73684e+09 pkt_dts:1736836667142678 pkt_dts_time:1.73684e+09 duration:40000 duration_time:0.04 off:-1736836665502741 off_time:-1.73684e+09 start_time:NOPTS 1736836667.273893 test04 stream[975228]: demuxer+ffmpeg -> ist_index:1 type:video pkt_pts:1639937 pkt_pts_time:1.63994 pkt_dts:1639937 pkt_dts_time:1.63994 duration:40000 duration_time:0.04 off:-1736836665502741 off_time:-1.73684e+09 Regards, Vilnis
Regards, Gyan _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
participants (2)
-
Gyan Doshi -
Vilnis Bicevskis