From 3332beece534ed10f76dc524c9efe5a735557edf Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Fri, 2 Sep 2022 21:58:05 +0200 Subject: [PATCH] obs-ffmpeg: Fix seek offset being calculated incorrectly If FFmpeg wrote data and then seeked back to immediately overwrite it, the second seek would be skipped as our virtual offset was incorrectly thinking it hadn't changed. This caused MP4 corruption when seeking back in the file to write the moov atom. Fixes https://github.com/obsproject/obs-studio/issues/7269 Fixes https://github.com/obsproject/obs-studio/issues/7144 --- plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c index abb3913d4..2b97754bd 100644 --- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c +++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c @@ -780,7 +780,12 @@ static void *ffmpeg_mux_io_thread(void *data) if (want_seek) { os_fseeki64(ffm->io.output_file, next_seek_position, SEEK_SET); - current_seek_position = next_seek_position; + + // Update the next virtual position, making sure to take + // into account the size of the chunk we're about to write. + current_seek_position = + next_seek_position + chunk_used; + want_seek = false; }