Need samples for PTZ integration in c# ASP.NET

Hi,

We want to build a PTZ service which would perform PTZ operations on camera configured in the Milestone.

I have found only this url for PTZ sample - https://github.com/milestonesys/mipsdk-samples-component/tree/main/PTZandPresets

But the above is a UI based example. How do I send request for Pan/Tilt/Zoom to a camera without an UI, preferably using SDK functions.

Please help.

Please see following link, there are PTZ commands in the page, it might be helpful.

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_messaging_1_1_message_id_1_1_control.html&tree=tree_search.html?search=videoos.platform.messaging.messageid.

I still see the sample as highly relevant. You can ignore the UI part and extract the part that sends the command.

If for example you want to do a “goto preset” you ignore the UI and extract the command:

VideoOS.Platform.Messaging.Message triggerMessage =

               new VideoOS.Platform.Messaging.Message(MessageId.Control.TriggerCommand);

EnvironmentManager.Instance.SendMessage(triggerMessage, item.FQID);

There is no sample that is ASP.NET, but we hope you will see how you can still use the samples by extracting or transforming bits of it. In general the samples should give you ideas how it works.

@Rie Kiuchi (Milestone Systems)​

Thanks for your response. I will go through thins link.

Is there any document available for all PTZ functions such as what parameters are required to perform Pan/Tilt/Zoom.

We would create a web-api in ASP.NET which will expose REST endpoint to our user-interface. Our user-interface has PTZ buttons already enabled such as up-down-left-right-zoom in/out.

Each click of the button would send a request to the Web-API

Regards,

Alok Kumar

My colleague Rie did supply a link to the documentation.

All PTZ messages and the data to use with them is documented. Let us know if there is something missing, something you don’t find.

@Bo Ellegård Andersen (Milestone Systems)​ @Rie Kiuchi (Milestone Systems)​

I have gone through the samples. I have found 2 different ways of performing PTZ.

One example I found here - https://github.com/milestonesys/mipsdkmobile-samples-dotnet/blob/main/.NET%20Framework/PtzSample/FormLivePtz.cs

Here the method below is used for performing PTZ, this is using MIPSDK Moble

private async void ProcessPtzMoveOnCamera(PtzParamsHelper.PtzMoves move)
        {
            var response = await _connection.Ptz.ControlPtzAsync(
                new PtzParams()
                {
                    CameraId = _activeCameraId,
                    PtzMoveType = PtzParamsHelper.PtzMoveTypes.Step,
                    PtzMove = move,
                },
                _maxTimeout);
 
            ProcessMoveResponse(response);
        }

Another way is the example mentioned by @Rie Kiuchi (Milestone Systems)​ earlier in the responses.

Are both of these valid correct? If yes, which one should I use. In our use-case, we already have a PTZ web-ui where user can do up/down/left/right/zoom-in/out etc.

Thanks

There are methods in the MIP SDK and there in the Mobile SDK. I can understand the confusion now.

When you have a web-UI I suspect Mobile SDK is the better choice, my clear recommendation is; if you get video using Mobile SDK then do PTZ using Mobile SDK.

https://doc.developer.milestonesys.com/mipsdkmobile/index.html?base=reference/protocols/mobile_command.html&tree=tree_1.html

We are getting video using a encoder such as Wowza to our web-page. Mobile SDK is not used to get video from Milestone. We only want to perform PTZ. But I also think mobile SDK would be more suitable as it has direct functions to send up/down/left/right requests.

There are advantages to both using a Mobile Server and using the direct approach.

The Mobile Server can be placed in a DMZ, on the other hand if direct methods are used the Mobile Server might not be needed at all and your customers can choose not to install it.

PTZ in “steps” is also possible with the direct methods, those are the ones in the sample used on the buttons with arrows.

Example.

private void buttonUp_Click(object sender, EventArgs e)
{
	VideoOS.Platform.Messaging.Message msg = new VideoOS.Platform.Messaging.Message(MessageId.Control.PTZMoveCommand, VideoOS.Platform.Messaging.PTZMoveCommandData.Up);
	EnvironmentManager.Instance.PostMessage(msg, _camera.FQID);
}

I hope I have given you information so that you can choose between Mobile and direct.

I am curious, the way I envision what you have described you must be feeding Wowsa from either Mobile Server or direct from the VMS/recording servers.

Thanks for your precise sample for using PTZ with direct methods. As I understand, the direct methods doesn’t require an additional installation of mobile server. So it has less dependency as some customers may not have mobile server installed.

For your query, we utilize RTSP streams from camera/VMS and ingest them into Wowza to get HLS/WebRTC streams which play in all modern HTML5 browsers natively.

Hi @Bo Ellegård Andersen (Milestone Systems)​, @R & L Admin​ I tried using the sample shared by you but it seems PTZ operation is not working. I don’t receive any errors as well.

I am able to log into the management server successfully but PTZ command sent to the camera isn’t working. Here is the code

private static void loginToMileStone()
        {
         
            Uri uri = new Uri("http://172.30.41.171");
 
            bool secureOnly = false;
            CredentialCache cc =
                VideoOS.Platform.Login.Util.
                BuildCredentialCache(uri, "user", "******", "Basic");
            VideoOS.Platform.SDK.Environment.AddServer(secureOnly, uri, cc);
            try
            {
                VideoOS.Platform.SDK.Environment.Login(uri);
                VideoOS.Platform.Messaging.Message msg =
               new VideoOS.Platform.Messaging.Message(MessageId.Control.PTZMoveCommand,
               VideoOS.Platform.Messaging.PTZMoveCommandData.Right);
                FQID cameraFQID = new FQID();
                cameraFQID.ObjectId = Guid.Parse("78e0957a-80f8-46d4-a8f2-b08d57c56481");
                EnvironmentManager.Instance.PostMessage(msg, cameraFQID);
            }
            catch (ServerNotFoundMIPException snfe)
            {
                Console.WriteLine("Server does not exist");
            }
            catch (InvalidCredentialsMIPException ice)
            {
                Console.WriteLine("Invalid credentials");
            }
            catch (Exception)
            {
                Console.WriteLine("Other exception");
            }
 
            Console.WriteLine("logged in successfully to Milestone");
 
         
        }

Even if I enter a wrong camera GUID, the code flow doesn’t reach to the last Exception block. Am I missing to include some events before performing the PTZ operation

Please do not construct the FQID, I suspect it will not be valid. Instead get it from the configuration.

Item item = Configuration.Instance.GetItem(Guid.Parse("78e0957a-80f8-46d4-a8f2-b08d57c56481"), Kind.Camera);
EnvironmentManager.Instance.PostMessage(msg, item.FQID);

PS. I assume the unmodified sample works for you.

Yes @Bo Ellegård Andersen (Milestone Systems)​ I figured the same yesterday and I was able to get the FQID using the same way you mentioned. I am now able to do Zoom/Tilt/Pan.

However I could not find any command to set the camera to PTZ HOME options. I have also posted a question here - https://developer.milestonesys.com/s/feed/0D53X0000C19yJzSQI

Is there any command available in SDK to send PTZ home option?