From 9e9ad08123e775a25b9757d6762c4c8345bd206e Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sat, 26 Oct 2024 12:35:34 +0700 Subject: [PATCH] feat: fix audio & video sync (partial solution) --- src/client/voice/player/MediaPlayer.js | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/client/voice/player/MediaPlayer.js b/src/client/voice/player/MediaPlayer.js index 8b02f78..100400a 100644 --- a/src/client/voice/player/MediaPlayer.js +++ b/src/client/voice/player/MediaPlayer.js @@ -26,7 +26,21 @@ const { H264Dispatcher } = require('../dispatcher/AnnexBDispatcher'); const AudioDispatcher = require('../dispatcher/AudioDispatcher'); const { VP8Dispatcher } = require('../dispatcher/VPxDispatcher'); -const FFMPEG_ARGUMENTS = ['-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2']; +const FFMPEG_ARGUMENTS = [ + '-use_wallclock_as_timestamps', + '1', + '-copyts', + '-analyzeduration', + '0', + '-loglevel', + '0', + '-f', + 's16le', + '-ar', + '48000', + '-ac', + '2', +]; /** * Player for a Voice Connection. @@ -135,7 +149,19 @@ class MediaPlayer extends EventEmitter { if (!options?.fps) options.fps = 30; - const args = ['-i', '-', '-analyzeduration', '0', '-flags', 'low_delay', '-r', `${options?.fps}`]; + const args = [ + '-i', + '-', + '-use_wallclock_as_timestamps', + '1', + '-copyts', + '-analyzeduration', + '0', + '-flags', + 'low_delay', + '-r', + `${options?.fps}`, + ]; if (options?.bitrate && typeof options?.bitrate === 'number') { args.push('-b:v', `${options?.bitrate}K`);