How to find consecutive non zero values from a column
Test something like
WITH cte AS ( SELECT *, SUM(CASE WHEN counts=0 THEN 1 ELSE 0 END) OVER (ORDER BY timestamp) grp
              FROM sourcetable )
SELECT MIN(timestamp) start_time, MAX(timestamp) end_time, SUM(counts) total_count
FROM cte
WHERE grp = 0

DEMO fiddle (MySQL 8 used)