Controlling a PTZ Camera Using a Batch Script - EmpireTech/Dahua

Post Reply
Make-n-it
Posts: 2
Joined: Tue Aug 13, 2024 10:39 pm

Controlling a PTZ Camera Using a Batch Script - EmpireTech/Dahua

Post by Make-n-it »

This guide will walk you through the process of controlling your PTZ (Pan-Tilt-Zoom) camera using a simple batch script. This script has been tested with an Empire Tech PTZ Camera and should work with Dahua cameras as well. By running this script, you can move the camera to a specific preset position without logging into the camera's web interface or using any control software. It’s particularly useful for integrating with automation tools like StreamDeck.

What the Script Does
    The batch script leverages the curl command to send an HTTP request to the camera’s CGI API, instructing it to move to a specific preset position. This example script is configured to move the camera to preset 5.

    How It Works
      Minimizing the Script Window: The script checks if it is already running in a minimized state. If not, it re-runs itself in a minimized window to keep your screen clean.
        Sending the Command: The core of the script is the curl command, which sends a request to the camera's API to move it to a preset position.

        Batch Script Start
        @echo off
        rem Check if the script is already running minimized
        if "%1"=="minimized" goto run

        rem Re-run the script minimized
        start /min cmd /c "%~f0" minimized
        goto :eof

        :run

        :: Move the camera to preset 5
        curl --digest -u username:password "http://192.168.1.1/cgi-bin/ptz.cgi?acti ... 2=5&arg3=0"

        Batch Script End


        What You Need to Change

        Username and Password:
        • Replace username:password with your camera’s login credentials.
          Example: admin:mysecurepassword
        Camera IP Address:
        • Replace 192.168.1.1 with the actual IP address of your camera.
          Example: 192.168.0.100
        Preset Position:
        • The arg2=5 part specifies the preset position to which the camera will move. Change the number 5 to the desired preset number.
          Example: To move to preset 3, change arg2=5 to arg2=3.
        Usage

        Create the Batch File:
        • Copy the script into a text file and save it with a .bat extension, e.g., MoveCamera.bat.
        Run the Script:
        • Double-click the batch file to execute it. The camera will move to the specified preset position.
        Integration with StreamDeck:
        • You can assign this batch file to a button in StreamDeck for quick and easy camera control.
        Conclusion

        This simple batch script is a powerful tool for controlling your PTZ camera with ease. By customizing the username, password, IP address, and preset values, you can quickly adapt it to your setup. Whether you’re using it for home security, live streaming, or any other purpose, this script offers a convenient way to automate your camera movements.
        User avatar
        TimG
        Posts: 2675
        Joined: Tue Jun 18, 2019 10:45 am
        Location: Nottinghamshire, UK.

        Re: Controlling a PTZ Camera Using a Batch Script - EmpireTech/Dahua

        Post by TimG »

        Very interesting. Thank you for posting it.
        Forum Moderator.
        Problem ? Ask and we will try to assist, but please check the Help file.
        User avatar
        Pogo
        Posts: 652
        Joined: Tue Jul 18, 2023 7:21 pm
        Location: Reportedly in the Area

        Re: Controlling a PTZ Camera Using a Batch Script - EmpireTech/Dahua

        Post by Pogo »

        Pretty cool, but...

        Considering the limitations of such a single batch file for a single static preset, I'm not understanding why you wouldn't just point the camera to the desired position and tighten it down with a screwdriver in the first place since there doesn't seem to be any obvious means to move it back to its original or home position without additional batch files in the mix to handle any additional movement.

        The real question is how would one effectively use such an approach for an active or tracking PTZ camera..., easily. It would seem that the number of batch files required would rapidly become rather cumbersome, not to mention integrating any number of other significant considerations such as scheduling, etc.

        I presume StreamDeck is the central component to all of this, somehow in favor of just executing everything via ONVIF / other common PTZ protocols instead?
        Post Reply