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))

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:

  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:

  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. HPE recommends that you save your configuration files in the location specified by the ConfigDirectory parameter.