Here's a batch script that captures RTSP stream screenshots every hour while skipping the period from 11 AM to midnight (12 AM):
@echo off
setlocal enabledelayedexpansion
:: Configuration
set RTSP_URL=rtsp://your_camera_rtsp_stream
set OUTPUT_FOLDER=C:\CCTV_Screenshots
set FFMPEG_PATH=C:\ffmpeg\bin\ffmpeg.exe
:: Create output folder if it doesn't exist
if not exist "%OUTPUT_FOLDER%" mkdir "%OUTPUT_FOLDER%"
:: Get current time components
for /f "tokens=1-3 delims=: " %%a in ('echo %time%') do (
set /a "hour=%%a"
set /a "minute=%%b"
set /a "second=%%c"
)
:: Skip if between 11 AM (11) and Midnight (0)
if %hour% geq 11 if %hour% leq 23 (
echo Skipping capture between 11 AM and Midnight
exit /b
)
if %hour% equ 0 (
echo Skipping Midnight capture
exit /b
)
:: Generate timestamp for filename
for /f "tokens=1-3 delims=/ " %%d in ('echo %date%') do (
set year=%%d
set month=%%e
set day=%%f
)
set timestamp=%year%%month%%day%_%hour%%minute%%second%
:: Capture frame with ffmpeg
"%FFMPEG_PATH%" -y -i "%RTSP_URL%" -frames:v 1 -q:v 2 "%OUTPUT_FOLDER%\%timestamp%.jpg" 2>nul
if errorlevel 1 (
echo Failed to capture frame at %time%
) else (
echo Captured frame: %OUTPUT_FOLDER%\%timestamp%.jpg
)
Important Notes:
Replace RTSP_URL
with your camera's actual RTSP stream URL
Adjust FFMPEG_PATH
to match your ffmpeg installation location
Modify OUTPUT_FOLDER
to your desired save location
Test the time format on your system by running echo %time%
and echo %date%
in cmd
The script uses 24-hour format (0-23 where 0=Midnight)
The script will skip captures between 11:00:00 and 23:59:59, plus Midnight (00:00:00)
To Schedule:
Save as cctv_capture.bat
Open Task Scheduler (taskschd.msc)
Create a new task:
Trigger: Hourly (repeat every hour)
Action: Start a program → select your batch file
Run whether user is logged in or not
Troubleshooting Tips:
Test the RTSP URL directly with ffmpeg first
Verify your time format matches the script's parsing
Check folder permissions for the output location
Consider adding error logging if needed
Test during active hours (1-10 AM) to verify captures work
The script will now capture images every hour except between 11 AM and Midnight (12 AM), which matches your requirement for the timelapse project.