[COMPLETE GUIDE] How define motion detection regions using ONLY the HTTP API



I figured out how to define motion detection regions with the API.

General description

Grandstream uses a bit packed 32bit value, with the upper 16 bits representing the X, and the lower 16 bits representing the Y value. They use this single value to set the “leftup” and “rightdown” x,y coordinates.

Bit packing function

val = ((X<<16)|(Y&65535));

Resolution mapping
The MAX X and Y values for region definition are 704, 576. No matter what the resolution of your stream is, it needs to be scaled to 704x576 to use it for finding pixel coordinates for region definition.

Complete example
Use VLC to open the rtsp stream to your camera and take a screenshot of JUST the stream portion, do not include the player window. Open that screenshot in GIMP, or Photoshop.

You can do this on the command line with the following command

cvlc rtsp://user:pass@XXX.XXX.XXX.XXX --video-filter=scene --scene-prefix=gs-camera- --scene-path=./ --vout=dummy --run-time 1  --scene-format png vlc://quit

If you run that command, you should get a image in the directory you ran it under called gs-camera-00001.png.

Here is a screenshot from VLC that I will be using for this example.

Now we must resize the image to match the max X,Y resolution (704x576).

For this example, I want to make a region that covers the instruments hanging on the wall. I have scaled my previous screenshot to 704x576 and drawn a box with GIMP covering that region, and identified the x,y pixel locations for the top left, and lower right corners. These values will be encoded to our leftup and rightdown respectively.

So now lets run the packing formula on the two coordinate sets we have:

leftup = ((490<<16)|(5&65535)) = 32112645
rightdown = ((660<<16)|(480&65535)) = 43254240 

and finally we can make the API call to define a region index 0 to cover the box:


Now if I use a virtual machine running windows and the grandstream firefox plugin, I can verify that my region has been defined and matches what I had previously drawn in GIMP.

You can turn on motion detection, upload, video call out etc. using the API as well:


Hopefully that helps some of you out there who also either HATE, or are unable to use the Grandstream plugin to administer your IP cameras :slight_smile:

For more information, the HTTP API documentation (what exists to the best of my knowledge) can be found at https://www.grandstream.com/products/surveillance/general/documents/grandstream_http_api.pdf

How I can set Motion Detect on Linux PC? (GXV3611_HD)


Would you please provide the bit packing function?

Thanks and best,


@eric.tamme - this is excellent material - if you would please provide the bit packing function I would greatly appreciate it.



looks like grandstream broke my post, and wiped the code sections when they updated their forums … blerg.

trying to get the original docs from their support team to fix it.


@snort2root the post has been fixed - please re-read including the code blocks to get the info you want.