paretech / klvdata

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

AttributeError: 'UnknownElement' object has no attribute 'structure' #39

Open adamxyzxyz opened 3 years ago

adamxyzxyz commented 3 years ago

Hi,

I am receiving this error when running klvdata_test.py:

AttributeError: 'UnknownElement' object has no attribute 'structure'

I believe it has something to do with the way the klvdata is embedded in the stream: Stream #0:0: Data: bin_data (KLVA / 0x41564C4B)

Are there any adjustments I can make to this script to have it properly parse the data?

Thanks

firestorm22 commented 3 years ago

I have also the same problem.

ayhangenc commented 3 years ago

Hi,

Same problem here, trying to decode a recorded ts stream, here is the output...

Duration: 00:01:25.40, start: 1778.243333, bitrate: 5850 kb/s Program 1 Metadata: service_name : CAMERA 01 service_provider: HC4 Stream #0:0[0x12c]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc Stream #0:1[0x12d]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 256 kb/s Stream #0:2[0x5]: Data: bin_data ([6][0][0][0] / 0x0006) Stream #0:3[0x259]: Data: bin_data (TELM / 0x4D4C4554) Stream #0:4[0x32]: Data: bin_data (CCII / 0x49494343) Stream #0:5[0x258]: Data: klv (KLVA / 0x41564C4B) Output #0, data, to 'pipe:': Metadata: encoder : Lavf58.45.100 Stream #0:0: Data: klv (KLVA / 0x41564C4B) Stream mapping: Stream #0:5 -> #0:0 (copy) Press [q] to stop, [?] for help size= 668kB time=00:01:25.36 bitrate= 64.1kbits/s speed=1.19e+03x
video:0kB audio:0kB subtitle:0kB other streams:668kB global headers:0kB muxing overhead: 0.000000% Traceback (most recent call last): File "./klvdata_test.py", line 3, in for packet in klvdata.StreamParser(sys.stdin.buffer.read()): packet.structure() AttributeError: 'UnknownElement' object has no attribute 'structure'

All4Gis commented 3 years ago

I cannot reproduce this error. Sorry for the delay. Can you specify the steps to reproduce it?

zaidbhat1234 commented 3 years ago

@firestorm22 @adamxyzxyz @ayhangenc Were you guys able to resolve this issue? I am also facing this similar issue and not able to figure out the reason behind it.

patrickjmccarty commented 2 years ago

I hit this as well and resolved it. It happens if your stream has data fields that are not implemented, and you are using code like the sample script from the homepage Quick Start that calls packet.structure(). On a related note I implemented an improvement to nicely print the info about the UnknownElement.

Edit klvdata/klvdata/element.py in two places as follows:

# I changed the __str__ method in the Element class to print hex more clearly, the way MISB does.
    def __str__(self):
        return "{}: ({}, {}, {})".format(self.name, '.'.join('{:02x}'.format(x) for x in self.key), len(self), '.'.join('{:02x}'.format(v) for v in self.value))

# I added a structure method to the UnknownElement class so that it will continue printing when it encounters an unrecognized field.
    def structure(self):
        """Print this unsupported element."""
        print(str(self))