diff --git a/lib/media.js b/lib/media.js index 7df3093..02967f7 100644 --- a/lib/media.js +++ b/lib/media.js @@ -1244,14 +1244,39 @@ module.exports = function(Cam) { }; /** - * CreateOSD - * ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc. We only support Plain Text - * @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 {Cam~GetOSDOptionsCallback} callback - */ + * CreateOSD + * 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 {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 {string} [options.colorspace] Colorspace - RGB or YCbCr. Default RGB. + * @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z. + * @param {float} [options.fontColor.X] For RGB means R value, For YCbCr means Y value. + * @param {float} [options.fontColor.Y] For RGB means G value, For YCbCr means Cb value. + * @param {float} [options.fontColor.Z] For RGB means B value, For YCbCr means Cr value. + * @param {Cam~GetOSDOptionsCallback} callback + * @example + * await cam.createOSD({ + * position: "LowerLeft", + * timeFormat: "HH:mm:ss", + * dateFormat: "YYYY-MM-DD", + * fontSize: 1, + * colorspace: "RGB", + * fontColor: { + * X: 1, + * Y: 0.7, + * Z: 0.9, + * } + * }); + * + */ Cam.prototype.createOSD = function(options, callback) { if (callback === undefined) { callback = options; options = {}; } let mediaType = (this.media2Support ? 'media2' : 'media'); @@ -1259,21 +1284,32 @@ module.exports = function(Cam) { this._request({ service: mediaType , body: this._envelopeHeader() + - ` + ` - ${(options.videoSourceConfiguationToken || this.activeSource.videoSourceConfigurationToken)} - Text - - ${options.position || 'LowerLeft'} - - - Plain - ${options.plaintext} - + ${options.videoSourceConfiguationToken || this.activeSource.videoSourceConfigurationToken} + Text + + ${ typeof options.position === "object" ? "Custom" : options.position ? options.position : "LowerLeft"} + ${typeof options.position === "object" ? '' : ""} + + + ${ options.dateFormat && options.timeFormat ? + `DateAndTime + ${options.dateFormat} + ${options.timeFormat}` + : `Plain + ${options.plaintext}`} + + ${options.fontSize ? `${options.fontSize}` : ""} + ${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ? + ` + + ${ '' } + ` : "" } + ` + - - this._envelopeFooter() + this._envelopeFooter(), }, function(err, data, xml) { if (callback) { callback.call(this, err, err ? null : linerase(data), xml); @@ -1283,7 +1319,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 @@ -1293,7 +1330,14 @@ 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 {string} [options.colorspace] Colorspace - RGB or YCbCr. Default RGB. + * @param {object} [options.fontColor] The color of the text font (OSDColor), should be object with properties - X, Y, Z. + * @param {float} [options.fontColor.X] For RGB means R value, For YCbCr means Y value. + * @param {float} [options.fontColor.Y] For RGB means G value, For YCbCr means Cb value. + * @param {float} [options.fontColor.Z] For RGB means B value, For YCbCr means Cr value. * @param {Cam~GetOSDOptionsCallback} callback + * @see {Cam~createOSD} */ Cam.prototype.setOSD = function(options, callback) { let mediaType = (this.media2Support ? 'media2' : 'media'); @@ -1317,10 +1361,20 @@ module.exports = function(Cam) { ${options.dateFormat} ${options.timeFormat}` : `Plain - ${options.plaintext}`} - - - ` + + ${options.plaintext}`} + ${ + options.fontSize ? + `${options.fontSize}` : '' +} + ${ options.fontColor && options.fontColor.X && options.fontColor.Y && options.fontColor.Z ? + ` + + ${ '' } + ` : "" } + + + ` + + this._envelopeFooter(), }, function(err, data, xml) {