Video streaming with control value¶
Prerequisites¶
Modules
External Ressource
An RTSP video camera
Checkout branches
git checkout origin/osp-web .
git checkout origin/osp-video-configuration .
git checkout origin/osp-scripts .
Description¶
In this tutorial you will learn how to control a video stream with an external variable.
The control will be performed by a script executed every 5 seconds. If the script found a lookup file command
with a key named control
, he will set the stream controller to true.
In this tutorial you will learn :
How to read a lookup file from scripts
How to set a variable from script
How to create a video dashboard
How to control the stream of a video widget
Structure¶
Steps¶
1. Create the dashboard to visualize the video stream¶
Create a dashboard reading from the controller.
root/dashboard/dashboard.view
{
"configuration": [
{
"type": "VideoPlayer",
"id": "Obj6KetA",
"title": "Camera",
"videoWidgetSettings": {
"videoId": "root.scripts"
}
},
{
"type": "ValueSubscription",
"id": "ormntRfC",
"title": "",
"valueSubscriptions": {
"values": []
}
}
],
"layout": {
"lg": [
{
"w": 5,
"h": 3,
"x": 0,
"y": 0,
"i": "Obj6KetA"
},
{
"w": 7,
"h": 3,
"x": 5,
"y": 0,
"i": "ormntRfC"
}
]
},
"breakpoints": {
"lg": 1200,
"md": 996,
"sm": 768,
"xs": 480,
"xxs": 0
},
"cols": {
"lg": 12,
"md": 10,
"sm": 6,
"xs": 4,
"xxs": 2
}
}
root/dashboard/dashboard.web
{
"moduleId": "modules.web.web-1",
"title": "Example of Camera view",
"description": "",
"tags": []
}
2. Write a script reading the command.lookup¶
root/scripts/check-file.js
main();
function main() {
const is_enabled = lookup.get("command", "control", 0);
log.info("Camera state is {}", is_enabled)
if (is_enabled == 0)
{
return true;
}
else
{
return false;
}
}
root/scripts/owner.scripts
{
"moduleId": "modules.scripts.scripts-1",
"scheduledExecutions": ["0/5 * * ? * * *"],
"accessedValues": [],
"sourceFile": "root/scripts/check-file.js"
}
root/scripts/value.ospp
{
"name": "Service status",
"description": "The status of an external service",
"type": "BOOLEAN"
}
3. Create a video stream controller¶
This file will link the URL and the value (must be a boolean value)
root/scripts/controller.video
{
"streamId": "root.url",
"controllingValue": "root.scripts"
}
4. Create a video stream¶
root/url/owner.video
{
"networkBufferingTime": {
"value": 1,
"unit": "SECONDS"
},
"disableStreamEncoding": true,
"streamType": "STREAM",
"serverId": "root.video.server-1",
"urls": [
"rtsp://user:password@10.10.1.1/axis-media/media.amp?profile=quality_h264&sessiontimeout=60&streamtype=unicast"
]
}
root/url/value.ospp
{
"name" : "Camera 01",
"description" : "The camera",
"type" : "BOOLEAN"
}
5. Open the web view (LOCAL IP:5000)¶
The video should not be displayed yet
6. Set the lookup content to enabled¶
To simulate an external behavior, we will manually create a file inside the scripts container.
Note
This is totally a trick to show this feature. Do not use this in production.
From the command line fetch the container-id
docker container ls | grep scripts
Execute the following command with the previous ID
docker container exec -it [ID] echo "control;1; > /osp/config/lookups/command.lookup"
7. Re-open the web view (LOCAL IP:5000)¶
The video should be displayed (this can take ~1 min depending on the buffering settings of the camera)