MySQL query to find time difference based on a condition
SELECT MIN(`time`) time_from,
       MAX(`time`) time_till
FROM ( SELECT *, 
              @group := @group + CASE WHEN NOT sp AND @prev THEN 1 ELSE 0 END group_num, 
              @prev:=sp
       FROM test, (SELECT @prev:=-1, @group:=0) variable
       WHERE ign = 1
       ORDER BY `time` ) temp
WHERE NOT sp
GROUP BY group_num;


fiddle