KLV Group
   HOME

TheInfoList



OR:

KLV (Key-Length-Value) is a data encoding standard, often used to embed information in video feeds. The standard uses a
type–length–value Within communication protocols, TLV (type-length-value or tag-length-value) is an encoding scheme used for optional informational elements in a certain protocol. A TLV-encoded data stream contains code related to the record type, the record valu ...
encoding scheme. Items are encoded into Key-Length-Value triplets, where key identifies the data, length specifies the data's length, and value is the data itself. It is defined in SMPTE 336M-2007 (Data Encoding Protocol Using Key-Length Value), approved by the
Society of Motion Picture and Television Engineers The Society of Motion Picture and Television Engineers (SMPTE) (, rarely ), founded in 1916 as the Society of Motion Picture Engineers or SMPE, is a global professional association of engineers, technologists, and executives working in the m ...
. Due to KLV's large degree of interoperability, it has also been adopted by the
Motion Imagery Standards Board In physics, motion is the phenomenon in which an object changes its position with respect to time. Motion is mathematically described in terms of displacement, distance, velocity, acceleration, speed and frame of reference to an observer and me ...
.


Byte packing

In a binary stream of data, a KLV set is broken down in the following fashion, with all integer-interpretation being
big endian In computing, endianness, also known as byte sex, is the order or sequence of bytes of a word of digital data in computer memory. Endianness is primarily expressed as big-endian (BE) or little-endian (LE). A big-endian system stores the most sig ...
:


Key field

The first few bytes are the Key, much like a key in a standard hash table data structure. Keys can be 1, 2, 4, or 16 bytes in length. Presumably in a separate specification document you would agree on a key length for a given application. Sixteen byte keys are usually reserved for use as globally registered unique identifiers, and the Value portion of such a packet usually contains a series of more KLV sets with smaller keys.


Length field

Following the bytes for the Key are bytes for the Length field which will tell you how many bytes follow the length field and make up the Value portion. There are four kinds of encoding for the Length field: 1-byte, 2-byte, 4-byte and
Basic Encoding Rules X.690 is an ITU-T standard specifying several ASN.1 encoding formats: * Basic Encoding Rules (BER) * Canonical Encoding Rules (CER) * Distinguished Encoding Rules (DER) The Basic Encoding Rules (BER) were the original rules laid out by the ASN.1 s ...
(BER). The 1-, 2-, and 4-byte variants are pretty straightforward: make an unsigned integer out of the bytes, and that integer is the number of bytes that follow. BER length encoding is a bit more complicated but the most flexible. If the first byte in the length field does not have the high bit set (0x80), then that single byte represents an integer between 0 and 127 and indicates the number of Value bytes that immediately follows. If the high bit is set, then the lower seven bits indicate how many bytes follow that themselves make up a length field. For example if the first byte of a BER length field is binary 10000010, that would indicate that the next two bytes make up an integer that then indicates how many Value bytes follow. Therefore a total of three bytes were taken up to specify a length.


Value field

The remaining bytes are the Value field, and its contents can be whatever you like, including a chain of more KLV sets, as is often the case.


Example

In the following example, the four bytes represent a KLV set where the key is one byte, the length field is one byte (or possibly BER - you cannot tell from the example), and the value is two bytes: a zero and a three. In your application you would have previously agreed to a) use one-byte keys and b) use one-byte length encoding. Also presumably the key value "42" would mean something to you, perhaps it indicates that the value bytes 0x00 and 0x03 are an integer representing the value of your bicycle's odometer.


External links


KLVLib - A C Library for KLV file I/O



ITU version of the KLV specification (ITU-R Recommendation BT.1563) (free)

A Java KLV library in the Public Domain

A Commercial Implementation of the Codec

A Commercial Implementation of the KLV encoder/decoder lib (C++)
{{DEFAULTSORT:Klv Encodings Computer data