79745829

Date: 2025-08-25 13:39:50
Score: 0.5
Natty:
Report link

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:

  1. Replace RTSP_URL with your camera's actual RTSP stream URL

  2. Adjust FFMPEG_PATH to match your ffmpeg installation location

  3. Modify OUTPUT_FOLDER to your desired save location

  4. Test the time format on your system by running echo %time% and echo %date% in cmd

  5. The script uses 24-hour format (0-23 where 0=Midnight)

  6. The script will skip captures between 11:00:00 and 23:59:59, plus Midnight (00:00:00)

To Schedule:

  1. Save as cctv_capture.bat

  2. Open Task Scheduler (taskschd.msc)

  3. 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:

  1. Test the RTSP URL directly with ffmpeg first

  2. Verify your time format matches the script's parsing

  3. Check folder permissions for the output location

  4. Consider adding error logging if needed

  5. 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.

Reasons:
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: intellsoft