Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set font size and color in setOSD and createOSD methods. #326

Merged
merged 6 commits into from
Jun 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 50 additions & 19 deletions lib/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,17 @@ module.exports = function(Cam) {

/**
* CreateOSD
* ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc. We only support Plain Text
* ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc.
* Support - Plain Text, DateAndTime, Font size and Font color.
* @param {Object} [options]
* @param {string} [options.videoSourceConfigurationToken] Token of the Video Source Configuration, which has associated OSDs. Defaults to Active Source
* @param {string} [options.plaintext] Text to overlay
* @param {string} [options.position] UpperLeft, UpperRight, LowerLeft or LowerRight. Default LowerLeft (custom mode currently not implemented)
* @param {object|string} [options.position] String options: UpperLeft, UpperRight, LowerLeft or LowerRight. Default LowerLeft. Or an object with x and y position
* @param {number} [options.position.x] x position of OSD, range: -1 to 1, counting from left to right
* @param {number} [options.position.y] y position of OSD, range: -1 to 1, counting from up to down
* @param {string} [options.plaintext] Plain text to overlay
* @param {string} [options.dateFormat] Date to overlay. Must be used with timeFormat, otherwise plaintext will be used.
* @param {string} [options.timeFormat] Time to overlay. Must be used with dateFormat, otherwise plaintext will be used.
* @param {number} [options.fontSize] The text font size.
* @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z.
* @param {Cam~GetOSDOptionsCallback} callback
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add your example here:

* @example
* await cam.createOSD({
*           videoSourceConfigurationToken: "VideoSourceConfigToken-01-0",
*           OSDToken: "OSDDateTimeToken-0",
*           position: "LowerLeft",
*           timeFormat: "HH:mm:ss",
*           dateFormat: "YYYY-MM-DD",
*           fontSize: 1,
*           fontColor: {
*             X: 82,
*             Y: 90,
*             Z: 240,
*           }
* });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added example to create osd.

*/
Cam.prototype.createOSD = function(options, callback) {
Expand All @@ -1259,21 +1265,31 @@ module.exports = function(Cam) {
this._request({
service: mediaType
, body: this._envelopeHeader() +
`<wsdl:CreateOSD xmlns:wsdl="${mediaNS}" xmlns:sch="http://www.onvif.org/ver10/schema">
`<wsdl:CreateOSD xmlns:wsdl="${mediaNS}" xmlns:sch="http://www.onvif.org/ver10/schema">
<wsdl:OSD token="">
<sch:VideoSourceConfigurationToken>${(options.videoSourceConfiguationToken || this.activeSource.videoSourceConfigurationToken)}</sch:VideoSourceConfigurationToken>
<sch:Type>Text</sch:Type>
<sch:Position>
<sch:Type>${options.position || 'LowerLeft'}</sch:Type>
</sch:Position>
<sch:TextString IsPersistentText="false">
<sch:Type>Plain</sch:Type>
<sch:PlainText>${options.plaintext}</sch:PlainText>
</sch:TextString>
<sch:VideoSourceConfigurationToken>${options.videoSourceConfiguationToken || this.activeSource.videoSourceConfigurationToken}</sch:VideoSourceConfigurationToken>
<sch:Type>Text</sch:Type>
<sch:Position>
<sch:Type>${ typeof options.position === "object" ? "Custom" : options.position ? options.position : "LowerLeft"}</sch:Type>
${typeof options.position === "object" ? '<sch:Pos x="' + options.position.x + '" y="' + options.position.y + '"/>' : ""}
</sch:Position>
<sch:TextString IsPersistentText="false">
${ options.dateFormat && options.timeFormat ?
`<sch:Type>DateAndTime</sch:Type>
<sch:DateFormat>${options.dateFormat}</sch:DateFormat>
<sch:TimeFormat>${options.timeFormat}</sch:TimeFormat>`
: `<sch:Type>Plain</sch:Type>
<sch:PlainText>${options.plaintext}</sch:PlainText>`}

${options.fontSize ? `<sch:FontSize>${options.fontSize}</sch:FontSize>` : ""}
${options.fontColor ? `
<sch:FontColor>
${'<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '"/>'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add Colorspace="http://www.onvif.org/ver10/colorspace/RGB" here? Or add optional param to choose between YCbCr and RGB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new options parameter - colorspace.
Supporting YCbCr and RGB.

</sch:FontColor>` : ""}
</sch:TextString>
</wsdl:OSD>
</wsdl:CreateOSD>` +

this._envelopeFooter()
this._envelopeFooter(),
}, function(err, data, xml) {
if (callback) {
callback.call(this, err, err ? null : linerase(data), xml);
Expand All @@ -1283,7 +1299,8 @@ module.exports = function(Cam) {

/**
* SetOSD
* ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc. Both Plain Text and DateAndTime are supported.
* ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc.
* Support - Plain Text, DateAndTime, Font size and Font color.
* @param {Object} options
* @param {Object} options.OSDToken
* @param {string} [options.videoSourceConfigurationToken] Token of the Video Source Configuration, which has associated OSDs. Defaults to Active Source
Expand All @@ -1293,6 +1310,8 @@ module.exports = function(Cam) {
* @param {string} [options.plaintext] Plain text to overlay
* @param {string} [options.dateFormat] Date to overlay. Must be used with timeFormat, otherwise plaintext will be used.
* @param {string} [options.timeFormat] Time to overlay. Must be used with dateFormat, otherwise plaintext will be used.
* @param {number} [options.fontSize] The text font size.
* @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z.
* @param {Cam~GetOSDOptionsCallback} callback
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here link to createOSD method:

* @see {Cam~createOSD}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the link to create osd method.

*/
Cam.prototype.setOSD = function(options, callback) {
Expand All @@ -1317,7 +1336,20 @@ module.exports = function(Cam) {
<sch:DateFormat>${options.dateFormat}</sch:DateFormat>
<sch:TimeFormat>${options.timeFormat}</sch:TimeFormat>`
: `<sch:Type>Plain</sch:Type>
<sch:PlainText>${options.plaintext}</sch:PlainText>`}
<sch:PlainText>${options.plaintext}</sch:PlainText>`}

${
options.fontSize ?
`<sch:FontSize>${options.fontSize}</sch:FontSize>` : ''
}
${
options.fontColor ?
`
<sch:FontColor>
${'<sch:Color Z="' + options.fontColor.Z + '" Y="' + options.fontColor.Y + '" X="' + options.fontColor.X + '"/>'}
</sch:FontColor>
` : ''
}
</sch:TextString>
</wsdl:OSD>
</wsdl:SetOSD>` +
Expand All @@ -1330,7 +1362,6 @@ module.exports = function(Cam) {
}.bind(this)
);
};

/**
* Delete OSD
* @param {string} token
Expand Down