Do not record non-seqential frames
authorHugo Villeneuve <hugo@hugovil.com>
Fri, 6 Oct 2023 03:01:39 +0000 (23:01 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Sat, 7 Oct 2023 15:45:53 +0000 (11:45 -0400)
fgen.sh

diff --git a/fgen.sh b/fgen.sh
index 07507d7..56b162e 100755 (executable)
--- a/fgen.sh
+++ b/fgen.sh
@@ -174,6 +174,8 @@ if [ ${trames} -eq 1 ]; then
     # Will start at frame 2 at first loop iteration
     f=1
 
+    nf=""
+    oldnf=""
     files=""
 
     while read l; do
@@ -195,9 +197,23 @@ if [ ${trames} -eq 1 ]; then
         files="${files} -page ${p} ${src}[${f}]"
 
         if [ x"${nf}" != x"" ]; then
+            # Only check expected frame if oldnf is set...
+            if [ x"${oldnf}" != x"" ]; then
+                expected_nf=$((${oldnf} + 1))
+
+                if [ ${expected_nf} -ne ${nf} ]; then
+                    echo "Error: invalid frame sequence: ${nf}"
+                    echo "  previous: ${oldnf}"
+                    echo "  expected: ${expected_nf}"
+                    files=""
+                    continue
+                fi
+            fi
+
             log_dbg "New frame ID: ${nf}"
             convert -colorspace sRGB -page +0+0 ${dest}/background.png ${files} -background none -layers merge ${dest}/f${nf}.png
             files=""
+            oldnf="${nf}"
         fi
     done <${layers}
 fi