KLV
Encyclopedia
KLV is a data encoding standard, often used to embed information in video feeds. 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
Society of Motion Picture and Television Engineers
The Society of Motion Picture and Television Engineers The Society of Motion Picture and Television Engineers The Society of Motion Picture and Television Engineers (SMPTE , founded in 1916 as the Society of Motion Picture Engineers or SMPE, is an international professional association, based in...

. Due to KLV's large degree of interoperability, it has also been adopted by the Motion Imagery Standards Board
Motion Imagery Standards Board
The Motion Imagery Standards Board is an official standards body that is responsible for reviewing, recommending, and overseeing standards for motion imagery, associated metadata, audio, and related systems. These standards are used by the United States Department of Defense , Intelligence...

.

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:

Key Field

The first few bytes are the Key, much like a key in a standard hashtable 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
Basic Encoding Rules
The Basic Encoding Rules is one of the encoding formats defined as part of the ASN.1 standard specified by the ITU in X.690.-Description:...

(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.
Key Length Value
42 2 0 3

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK