Encoding MISB metadata into KLV packets

klvencode plugin accepts a JSON packet (tag / value pairs that follows MISB 601.X standard) and outputs meta/x-klv byte array.

Input data

The input data is a JSON string.

{
  "2": "2008-10-24T00:13:29.913Z",
  "3": "MISSION01",
  "13": 60.176822967,
  "14": 128.426759042,
  "15": 14190.72,
  "16": 144.5713,
  "65": 13,
}

Output data

The output data (which can be, for example, passed to the multiplexer) contains a KLV encoded MISB 601.X metadata.
For example, the JSON packet shown above will be encoded into the binary data buffer:
Encoded buffer The above buffer contains the following parts:

  • The UAS Local Set 16-Byte UL “Key”-0x06 0x0E 0x2B 0x34 0x02 0x0B 0x01 0x01 0x0E 0x01 0x03 0x01 0x01 0x00 0x00 0x00
  • Packet length - 0x30
  • Packet data payload - Klv triplets: tag, length and value
  • Checksum (last klv triplet, last 4 bytes)

Usage

klvencode plugin configuration

gstreamer-klv-plugins use the MisbCore library. You MUST set the library path, so the plugins could find it.

Here are the instructions for plugin configuration.

GStreamer 1.0 Pipelines examples

Basic plugin usage.
Get the file ~/packet.json that contains a json packet (like the one shown above), encode according to the MISB 0601.X spec, then encode it to the KLV buffer and output the resulting binary array to the stdout.

gst-launch-1.0 filesrc location=~/packet.json ! klvencode ! fakesink dump=TRUE

More advanced pipeline that encodes test video, adds some MISB metadata from a JSON file (with a 33 ms interval) and creates a valid MSTANAG 4609 file:

gst-launch-1.0 videotestsrc ! 'video/x-raw,format=(string)I420,width=720,height=480,framerate=(fraction)30/1' ! \ 
x264enc bitrate=1500 ! 'video/x-h264, stream-format=(string)byte-stream, alignment=au' ! mpegtsmux alignment=7 name=mux  ! \ 
filesink sync=false async=true location=~/test.ts \
multifilesrc do-timestamp=TRUE location=~/packet.json loop=true ! identity sleep-time=33000 ! \
klvencode ! queue ! 'meta/x-klv' ! mux.

Note, in the above sample, we use a JSON that does not have tag 2 (timestamp). When this tag is not present, the plugin will insert a current time (and the timestamp will increment by about 33 ms with every packet).

Note, the above pipeline was tested with GStreamer 1.16. It may not work with other versions (because of the mpegtsmux issues)

Inspect klvencode

~$ gst-inspect-1.0 klvencode

Factory Details:
  Rank                     none (0)
  Long-name                KlvEncode
  Klass                    MISB KLV Encoder
  Description              MISB KLV Encoder Element
  Author                   info@impleotv.com

Plugin Details:
  Name                     klvencode
  Description              MISB Klv encoder
  Filename                 /home/alexc/Work/gstreamer-klv-plugins/build/gst-plugin/libgstklvencode.so
  Version                  1.0.0
  License                  Proprietary
  Source module            gst-misb-klv
  Binary package           GStreamer MISB KLV
  Origin URL               https://www.impleotv.com

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstKlvEncode

Pad Templates:
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      application/x-json

  SRC template: 'src'
    Availability: Always
    Capabilities:
      meta/x-klv
         parsed: true

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  SINK: 'sink'
    Pad Template: 'sink'
  SRC: 'src'
    Pad Template: 'src'

Element Properties:
  silent              : Produce verbose output ?
                        flags: readable, writable
                        Boolean. Default: false

Application development

Impleo's gstreamer-klv-plugins come with a sample code that shows the basics of GStreamer application programming for STANAG4609 processing.

klv-inject-file is a C++ app sample that demonstrates creating of a STANAG4609 file with the MISB 601 metadata by multiplexing the video with the metadata encoded on-the-fly.

Code Walkthrough

Klvencode plugin debug output

klvencode plugin prints out to console some helpful debug information.
The debug output is controlled with the GST_DEBUG environment variable. For example:

export GST_DEBUG=2,klvencode:6

When set to level 6 (LOG), the klvencode will print out the info on the incoming application/x-json buffer and the encoded meta/x-klv output.

0:00:01.789972743 16367 0x55f3c9573000 LOG  klvencode gstklvencode.c:291:gst_klv_encode_chain: Json received: {
  "2": "2008-10-24T00:13:29.913Z",
  "3": "MISSION01",
  "13": 60.176822967,
  "14": 128.426759042,
  "15": 14190.72,
  "16": 144.5713,
  "65": 13,
  "1": 53482
}

0:00:01.789996503 16367 0x55f3c9573000 LOG  klvencode gstklvencode.c:295:gst_klv_encode_chain: KLV packet encoded. Size 65 

Supported tags

Supported MISB 601 tags