Open topic with navigation

# Create an Overlay with a Lua Script

The `Overlay` transformation task creates an overlay for a video. This section demonstrates how to draw a custom overlay using a Lua script.

The Lua script that you write must define a function with the name `draw`. The function is passed each record from the input track. For example, the following function draws an ellipse using each record from the `Result` track produced by face detection:

    function draw(record)
       drawEllipse(record.FaceResult.face.ellipse, 3, rgb(255,255,255))
    end

For information about the Lua functions that you can use to draw an overlay, refer to the Media Server Reference.

To create an overlay with a Lua script

1. Create a new configuration to send to Media Server with the `process` action, or open an existing configuration that you want to modify.

2. In the `[Transform]` section, add a new transformation task by setting the `TransformEngineN` parameter. You can give the task any name, for example:

       [Transform]
       TransformEngine0=Overlay

3. Create a new configuration section to contain the task settings and set the following parameters:

   `Type` | The transformation engine to use. Set this parameter to `Overlay`.
   `Input` | The name of the track that contains the metadata to use to draw the overlay. This track does not need to include the video frames.
   `LuaScript` | The path of a Lua script to run to draw the overlay.

   For example:

       [Overlay]
       Type=Overlay
       Input=FaceDemographics.Result
       LuaScript=./configurations/overlayDemographics.lua

4. When you define your encoding task, use the parameter `OverlayInput` to specify the name of the output track from the overlay transformation task. In this example the track is named `Overlay.Output`.

5. Save and close the configuration file. Micro Focus recommends that you save your configuration files in the location specified by the `ConfigDirectory` parameter.

Example configuration to create an overlay using a Lua script

An example configuration file, `overlayFaces.cfg`, is included in the `configurations` folder of your Media Server installation. This example ingests a video file or stream, performs face detection and demographics analysis, and encodes video with an overlay. The overlay is drawn by a Lua script that uses metadata from the demographics task to outline male faces in orange and female faces in purple.

    [Ingest]
    IngestEngine=AV

    [AV]
    Type=libav

    [Analysis]
    AnalysisEngine0=FaceDetect
    AnalysisEngine1=Demographics

    [FaceDetect]
    Type=FaceDetect
    NumParallel=6
    SizeUnit=percent
    MinSize=10

    [Demographics]
    Type=Demographics
    Input=FaceDetect.ResultWithSource
    NumParallel=2

    [Transform]
    TransformEngine0=Overlay

    [Overlay]
    Type=Overlay
    Input=Demographics.Result
    LuaScript=./configurations/overlayDemographics.lua

    [Encoding]
    EncodingEngine0=RollingBuffer

    [RollingBuffer]
    Type=RollingBuffer
    ImageInput=Image_1
    AudioInput=None
    OverlayInput=Overlay.Output
    Stream=stream1

The Lua script, `overlayDemographics.lua` is included below:

    function draw(record)
      local result = record.DemographicsResult

      if ('Male' == result.gender) then
        -- draw orange ellipse
        drawEllipse(result.face.ellipse, 5, rgb(255, 128, 0))

      elseif ('Female' == result.gender) then
        -- draw purple ellipse
        drawEllipse(result.face.ellipse, 5, rgb(64, 0, 128))

      else
        -- draw grey ellipse
        drawEllipse(result.face.ellipse, 5, rgb(128, 128, 128))

      end
    end

© 2018 EntIT Software LLC, a Micro Focus company | Send documentation feedback to Micro Focus Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm