From 64c3ecbe4080658b5c1b13db4a689ecf5461bb79 Mon Sep 17 00:00:00 2001
From: Snehaa Giridharan <snehaa@multicorewareinc.com>
Date: Thu, 10 Nov 2022 16:59:20 +0530
Subject: [PATCH] Fix encoder crash with histogram scenecut

---
 source/encoder/slicetype.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp
index 5a1500716..78977bed8 100644
--- a/source/encoder/slicetype.cpp
+++ b/source/encoder/slicetype.cpp
@@ -2864,7 +2864,7 @@ bool Lookahead::histBasedScenecut(Lowres **frames, int p0, int p1, int numFrames
             if (frames[cp1 + 1]->bHistScenecutAnalyzed == true)
                 continue;
 
-            if (detectHistBasedSceneChange(frames, cp1, cp1 + 1, cp1 + 2))
+            if (frames[cp1 + 2] != NULL && detectHistBasedSceneChange(frames, cp1, cp1 + 1, cp1 + 2))
             {
                 /* If current frame is a Scenecut from p0 frame as well as Scenecut from
                  * preceeding frame, mark it as a Scenecut */
-- 
2.37.2.windows.2

