iSpy for PTZ Tracking - Dahua

networkcameracritic

Getting the hang of it
Mar 10, 2014
717
203
I tried to implement PTZ tracking with iSpy but not sure it's possible with Dahua cameras. The reason is they have commands for left/right/up/down but it requires a start command to get it going, then a stop command to stop it and iSpy did not seem to have provisions for this. So when it detected movement, it issued a pan right command which sent it in circles. If anyone got it working with Dahua, please let me know.

For starters, the new Dahua cameras seem to have a different URL string for RTSP which like this, no parameters like before - rtsp://admin:admin@192.168.1.100:554/

This is what I setup in their PTZ2.xml file that contains the URL instruction for each camera. I just put Left/Right commands for testing, but you can see action=start in the instruction, but that just starts panning, you have to issue the same command with action=stop to stop the motion.

Code:
[FONT=Courier New] <Camera id="199">
    <Makes>
      <Make Name="Dahua" Model="SD59230S" />
    </Makes>
    <CommandURL>/cgi-bin/</CommandURL>
    <Commands>
      <Left>ptz.cgi?action=start&amp;channel=0&amp;code=Left&amp;arg1=0&amp;arg2=1&amp;arg3=0</Left>
      <Right>ptz.cgi?action=start&amp;channel=0&amp;code=Right&amp;arg1=0&amp;arg2=1&amp;arg3=0</Right>
    </Commands>
<ExtendedCommands>
      <Command Name="action=Preset 1">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=1&amp;arg3=0</Command>
      <Command Name="action=Preset 2">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=2&amp;arg3=0</Command>
      <Command Name="action=Preset 3">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=3&amp;arg3=0</Command>
    </ExtendedCommands>
  </Camera>
[/FONT]
 
There are position relative commands that will do what you want, listed in the Dahua API. Unfortunately all those API commands have a lot of overhead that adds as much as 1/2 second delay on some cameras compared to controlling it through the camera's web interface. But it might be good enough to work anyway. On the big white 30x it is only 70ms extra processing time per command to use that API, but it is 200ms+ on the little 12x I got. Auto tracking works best if latency is at at the minimum amount of course. For that reason you may consider trying an mjpeg sub stream. I would think that would be the least latency on the video feed side of things.

It might also be possible to set up an ispy PTZ profile that works with start/stop commands. I haven't ever used ispy for more than a few minutes so I don't know for sure.
 
I got feedback back from iSpy and putting a stop command in their XML file did the trick. Here's a tested XML section to include in the iSpy PTZ2.xml file and submitted it to them so hopefully they'll just include it in future releases. I don't have the camera up anymore, but tested it on my desk. It tracked my hand. PTZ even at 30fps was very responsive and accurate, more so than from the browser interface. As long as you hold the arrow keys in iSpy it went in that direction. I set the speed slow, but if you want faster PTZing or tracking, change arg2 to higher number where 1 is the slowest, 8 is the fastest.

<Camera id="199">
<Makes>
<Make Name="Dahua" Model="SD59230S" />
</Makes>
<CommandURL>/cgi-bin/</CommandURL>
<Commands>
<Left>ptz.cgi?action=start&amp;channel=0&amp;code=Left&amp;arg1=0&amp;arg2=1&amp;arg3=0</Left>
<Right>ptz.cgi?action=start&amp;channel=0&amp;code=Right&amp;arg1=0&amp;arg2=1&amp;arg3=0</Right>
<Stop>ptz.cgi?action=stop&amp;channel=0&amp;code=Right&amp;arg1=0&amp;arg2=1&amp;arg3=0</Stop>
<Up>ptz.cgi?action=start&amp;channel=0&amp;code=Up&amp;arg1=0&amp;arg2=1&amp;arg3=0</Up>
<Down>ptz.cgi?action=start&amp;channel=0&amp;code=Down&amp;arg1=0&amp;arg2=1&amp;arg3=0</Down>
<ZoomOut>ptz.cgi?action=start&amp;channel=0&amp;code=ZoomWide&amp;arg1=0&amp;arg2=1&amp;arg3=0</ZoomOut>
<ZoomIn>ptz.cgi?action=start&amp;channel=0&amp;code=ZoomTele&amp;arg1=0&amp;arg2=1&amp;arg3=0</ZoomIn>
<LeftDown>ptz.cgi?action=start&amp;channel=0&amp;code=LeftDown&amp;arg1=0&amp;arg2=1&amp;arg3=0</LeftDown>
<RightDown>ptz.cgi?action=start&amp;channel=0&amp;code=RightDown&amp;arg1=0&amp;arg2=1&amp;arg3=0</RightDown>
<LeftUp>ptz.cgi?action=start&amp;channel=0&amp;code=LeftUp&amp;arg1=0&amp;arg2=1&amp;arg3=0</LeftUp>
<RightUp>ptz.cgi?action=start&amp;channel=0&amp;code=RightUp&amp;arg1=0&amp;arg2=1&amp;arg3=0</RightUp>
</Commands>
<ExtendedCommands>
<Command Name="action=Preset 1">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=1&amp;arg3=0</Command>
<Command Name="action=Preset 2">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=2&amp;arg3=0</Command>
<Command Name="action=Preset 3">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=3&amp;arg3=0</Command>
</ExtendedCommands>
</Camera>
 
  • Like
Reactions: Thomas B McNeill
I got feedback back from iSpy and putting a stop command in their XML file did the trick. Here's a tested XML section to include in the iSpy PTZ2.xml file and submitted it to them so hopefully they'll just include it in future releases. I don't have the camera up anymore, but tested it on my desk. It tracked my hand. PTZ even at 30fps was very responsive and accurate, more so than from the browser interface. As long as you hold the arrow keys in iSpy it went in that direction. I set the speed slow, but if you want faster PTZing or tracking, change arg2 to higher number where 1 is the slowest, 8 is the fastest.

As I was searching for PTZ commands that would work on a Lorex LNZ32P4B, I found that the Dahua code you provided was included in iSpy and it was the only section that worked on my camera. After some experimenting, I made some refinements to allow better control over the zoom functions. Not sure if they are backwards compatible with the Dahua but likely it won't hurt. FWIW I'll post it here.

Code:
<Camera id="199">
    <Makes>
      <Make Name="Dahua" Model="SD59230S" />
      <Make Name="Lorex" Model="LNZ32P4B" />
    </Makes>
    <CommandURL>/cgi-bin/</CommandURL>
    <Commands>
      <Left>ptz.cgi?action=start&amp;channel=0&amp;code=Left&amp;arg1=0&amp;arg2=1&amp;arg3=0</Left>
      <LeftUp>ptz.cgi?action=start&amp;channel=0&amp;code=LeftUp&amp;arg1=0&amp;arg2=1&amp;arg3=0</LeftUp>
      <Right>ptz.cgi?action=start&amp;channel=0&amp;code=Right&amp;arg1=0&amp;arg2=1&amp;arg3=0</Right>
      <RightUp>ptz.cgi?action=start&amp;channel=0&amp;code=RightUp&amp;arg1=0&amp;arg2=1&amp;arg3=0</RightUp>
      <Up>ptz.cgi?action=start&amp;channel=0&amp;code=Up&amp;arg1=0&amp;arg2=1&amp;arg3=0</Up>
      <Down>ptz.cgi?action=start&amp;channel=0&amp;code=Down&amp;arg1=0&amp;arg2=1&amp;arg3=0</Down>
      <LeftDown>ptz.cgi?action=start&amp;channel=0&amp;code=LeftDown&amp;arg1=0&amp;arg2=1&amp;arg3=0</LeftDown>
      <RightDown>ptz.cgi?action=start&amp;channel=0&amp;code=RightDown&amp;arg1=0&amp;arg2=1&amp;arg3=0</RightDown>
      <Stop>ptz.cgi?action=stop&amp;channel=0&amp;code=ZoomWide&amp;arg1=0&amp;arg2=1&amp;arg3=0</Stop>
      <ZoomIn>ptz.cgi?action=start&amp;channel=0&amp;code=ZoomTele&amp;arg1=0&amp;arg2=1&amp;arg3=0</ZoomIn>
      <ZoomOut>ptz.cgi?action=start&amp;channel=0&amp;code=ZoomWide&amp;arg1=0&amp;arg2=1&amp;arg3=0</ZoomOut>
    </Commands>
    <ExtendedCommands>
      <Command Name="action=Preset 1">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=1&amp;arg3=0</Command>
      <Command Name="action=Preset 2">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=2&amp;arg3=0</Command>
      <Command Name="action=Preset 3">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=3&amp;arg3=0</Command>
      <Command Name="action=Preset 4">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=4&amp;arg3=0</Command>
      <Command Name="action=Preset 5">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=5&amp;arg3=0</Command>
      <Command Name="action=Preset 6">ptz.cgi?action=start&amp;channel=0&amp;code=GotoPreset&amp;arg1=0&amp;arg2=6&amp;arg3=0</Command>
      <Command Name="action=DigZoom Y">configManager.cgi?action=setConfig&amp;VideoInZoom[0][0].DigitalZoom=true</Command>
      <Command Name="action=DigZoom N">configManager.cgi?action=setConfig&amp;VideoInZoom[0][0].DigitalZoom=false</Command>
    </ExtendedCommands>
  </Camera>
 
  • Like
Reactions: TL1096r