From d0418793c134fe943098f5f0700ae87fcd4c8557 Mon Sep 17 00:00:00 2001 From: ashok2013 Date: Tue, 4 Aug 2026 15:24:26 +0530 Subject: [PATCH] Foveated encode fix --- source/abrEncApp.cpp | 23 +++++++++++++++++++---- source/x265cli.cpp | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp index e45d9e34f..d9b2cedec 100644 --- a/source/abrEncApp.cpp +++ b/source/abrEncApp.cpp @@ -883,13 +883,28 @@ namespace X265_NS { if (m_foveaGazeFileFP) { - /* Try to read gaze for this frame; reuse previous on failure */ + /* Try to read gaze for this frame; reuse previous on failure. + * The frame number lets the gaze track resynchronize with the + * video (e.g. after --seek, or if the track has gaps): entries + * behind the current frame are stale and dropped, and an entry + * for a future frame is pushed back until its frame arrives. */ int frameNum; float fx, fy; - if (fscanf(m_foveaGazeFileFP, "%d %f %f", &frameNum, &fx, &fy) == 3) + int curFrame = (int)(m_cliopt.seek + inFrameCount) - 1; + long linePos; + while ((linePos = ftell(m_foveaGazeFileFP)), + fscanf(m_foveaGazeFileFP, "%d %f %f", &frameNum, &fx, &fy) == 3) { - gazeX = fx; - gazeY = fy; + if (frameNum < curFrame) + continue; + if (frameNum > curFrame) + fseek(m_foveaGazeFileFP, linePos, SEEK_SET); + else + { + gazeX = fx; + gazeY = fy; + } + break; } } else diff --git a/source/x265cli.cpp b/source/x265cli.cpp index 992333afb..b8d314332 100755 --- a/source/x265cli.cpp +++ b/source/x265cli.cpp @@ -489,7 +489,7 @@ namespace X265_NS { output->release(); output = NULL; - if (param->foveaGazeFile) + if (param && param->foveaGazeFile) free(param->foveaGazeFile); if (param && api)