paretech / klvdata

A Python library for parsing MISB ST 0601 Key Length Value (KLV) metadata.
https://paretech.github.io/klvdata/
MIT License
91 stars 54 forks source link

Interpreting a KLV data packet #46

Closed istabraqruhaili closed 2 years ago

istabraqruhaili commented 2 years ago

Hey. I have the following code that prints out the content of a packet after running the ffmpeg command to extract the KLV data from a .mpg file:

#!/usr/bin/env python3
import sys
import klvdata

for packet in klvdata.StreamParser(sys.stdin.buffer.read()):

    metadata=packet.MetadataList()
    for key, value in metadata.items():
        print(key, value)

and the output is:

2 ('Precision Time Stamp', '', 'User Defined Time Stamp', '2009-06-17 16:53:05.099653+00:00')
65 ('UAS Datalink LS Version Number', 'ESD ICD Version', '', '1.0')
5 ('Platform Heading Angle', 'UAV Heading (INS)', 'Platform Heading Angle', '86.10666056305791')
6 ('Platform Pitch Angle', 'UAV Pitch (INS)', 'Platform Pitch Angle', '3.3594775231177714')
7 ('Platform Roll Angle', 'UAV Roll (INS)', 'Platform Roll Angle', '0.5157628101443521')
11 ('Image Source Sensor', 'Sensor Name', 'Image Source Device', 'EON')
12 ('Image Coordinate System', 'Image Coordinate System', 'Image Coordinate System', 'Geodetic WGS84')
13 ('Sensor Latitude', 'Sensor Latitude', 'Device Latitude', '54.68132328460055')
14 ('Sensor Longitude', 'Sensor Longitude', 'Device Longitude', '-110.1685597701783')
15 ('Sensor True Altitude', 'Sensor Altitude', 'Device Altitude', '1532.2728313115126')
16 ('Sensor Horizontal Field of View', 'Field of View', 'Field of View (FOVHorizontal)', '0.36530098420691237')
17 ('Sensor Vertical Field of View', 'Vertical Field of View', '', '0.2059967956054017')
18 ('Sensor Relative Azimuth Angle', 'Sensor Relative Azimuth Angle', '', '46.10314941175821')
19 ('Sensor Relative Elevation Angle', 'Sensor Relative Elevation Angle', '', '-4.41094972398642')
20 ('Sensor Relative Roll Angle', 'Sensor Relative Roll Angle', '', '358.2026063087868')
21 ('Slant Range', 'Slant Range', 'Slant Range', '10928.624544974562')
22 ('Target Width', 'Target Width', 'Target Width', '69.73373006790266')
23 ('Frame Center Latitude', 'Target Latitude', 'Frame Center Latitude', '54.74912345164881')
24 ('Frame Center Longitude', 'Target Longitude', 'Frame Center Longitude', '-110.0466381153309')
25 ('Frame Center Elevation', 'Frame Center Elevation', '', '-4.52277409018086')
40 ('Target Location Latitude', '', '', '54.74912345164881')
41 ('Target Location Longitude', '', '', '-110.0466381153309')
42 ('Target Location Elevation', '', '', '-4.52277409018086')
56 ('Platform Ground Speed', 'Platform Ground Speed', '', '46.0')
57 ('Ground Range', 'Ground Range', '', '10820.674945325747')
1 ('Checksum', '', '', "b'\\x1c_'")
2 ('Precision Time Stamp', '', 'User Defined Time Stamp', '2009-06-17 16:54:33.850651+00:00')
65 ('UAS Datalink LS Version Number', 'ESD ICD Version', '', '1.0')
5 ('Platform Heading Angle', 'UAV Heading (INS)', 'Platform Heading Angle', '82.89860379949646')
6 ('Platform Pitch Angle', 'UAV Pitch (INS)', 'Platform Pitch Angle', '3.6091189306314284')

and I didn't figure out how to interpret these values. What does the key mean? and what are the values correponding to that key? Thank you in advance.

All4Gis commented 2 years ago

well, you need to read the standards to understand this wonderful world. https://upload.wikimedia.org/wikipedia/commons/1/19/MISB_Standard_0601.pdf

istabraqruhaili commented 2 years ago

Thank you for such a useful resource!

Tom920706 commented 1 year ago

Hello, would you like to ask, are there any particularities in using the ffmpeg version? I tried to use ffmpeg4.2.2 and kept getting errors ffmpeg -i "C:\Users\pengp\Desktop\klv\2.ts" -map data-re -codec copy -f data - | python3 ./klvdata_parse.py >> "${i%.*}.text";

Input #0, mpegts, from 'C:\Users\pengp\Desktop\klv\2.ts': Duration: 00:00:58.76, start: 1964.035822, bitrate: 9684 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080, 29.97 tbr, 90k tbn, 180k tbc Stream #0:1[0x101]: Data: klv (KLVA / 0x41564C4B) [mpegts @ 000001bd18468f00] Invalid stream specifier: data-re. Last message repeated 3 times Stream map 'data-re' matches no streams. To ignore this, add a trailing '?' to the map.

Tom920706 commented 1 year ago

@All4Gis @istabraqruhaili Hello, how to read TS video with klv using ffmpeg, I want to read the klv data in the video stream. Currently, following the tutorial, I keep getting errors.

!/bin/bash

ffmpeg -i "C:\Users\pengp\Desktop\klv\2.ts" -map data-re -codec copy -f data - | python3 ./klvdata_parse.py;

klvdata_parse.py: import klvdata for packet in klvdata.StreamParser(sys.stdin.buffer.read()):

 metadata=packet.MetadataList()
 for key, value in metadata.items():
     print(key, value)

[mpegts @ 00000230874992c0] Invalid stream specifier: data-re. Last message repeated 3 times Stream map 'data-re' matches no streams. To ignore this, add a trailing '?' to the map.