How to se threefive to validate the CRC_32 of a SCTE35 message #102
-
Hi. How would you go about validating the CRC_32 of a SCTE35 message? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
Let me ask you this, what do you plan on doing when you find a bad crc? How would you handle it and why would you handle it? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I was such a dick yesterday, I assumed you giving me shit and I just wasn't in the mood. I apologize. Just decode and then encode man, see if the strings match. When threefive encodes, it calculates everything that it can, lengths, types, and crc32. Here's all you have to do. >>>> from threefive import Cue
>>>> c = Cue('/DAgAAAAAAAAAP/wDwUAAAEDf0//MqD0yAEDAAAAAHXkvig=')
>>>> c.decode()
True
>>>> c.encode()
'/DAgAAAAAAAAAP/wDwUAAAEDf0//MqD0yAEDAAAAAHXkvig=' here's the Cue you had >>>> cue = Cue('/DA3AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAFwIVQ1VFSQAAAAB/yAAAKTLgAQEwMAAAlDpDfA==')
>>>> cue.decode()
True
>>>> cue.encode()
'/DA5AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAGQIXQ1VFSQAAAAB/yAAAKTLgAQEwMAAAAACRUPll' |
Beta Was this translation helpful? Give feedback.
-
I was worried about false negatives. As I mentioned, threefive re-calculates everything it can when encoding, and also fixes several common errors I've seen over and over. I decided to check the crc32 from the raw bites, much like you thinking with the hex. a@fu:~$ python3
>>> from threefive import Cue
>>> cue=Cue('/DA3AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAFwIVQ1VFSQAAAAB/yAAAKTLgAQEwMAAAlDpDfA==')
>>> cue.decode()
True
>>> cue.info_section.crc
'0x943a437c'
>>> from threefive.crc import crc32
>>> hex(crc32(cue.bites[:-4]))
'0x943a437c'
>>> cue.info_section.descriptor_loop_length
23
>>> cue.encode()
'/DA5AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAGQIXQ1VFSQAAAAB/yAAAKTLgAQEwMAAAAACRUPll'
>>> cue.info_section.crc
'0x9150f965'
>>> cue.info_section.descriptor_loop_length
25 One of the more common mistakes that threefive corrects is when people leave off sub_segment_num and'sub_segments_expected from a segmentation descriptor, they are used depending on the value of segmentation_type_id.
I just saved you a month worth of aggravation trying to figure that one out. You owe me a favor. try this instead: Updated!#!/usr/bin/env python3
from threefive import Cue
from threefive.crc import crc32
cue_list = [
"/aBadCue",
"/DAgAAAAAAAAAP/wDwUAAAEDf0//MqD0yAEDAAAAAHXkvig=",
"/DA3AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAFwIVQ1VFSQAAAAB/yAAAKTLgAQEwMAAAlDpDfA==",
"/DA3AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAFwIVQ1VFSQAAAAB/yAAAKTLgAQEwMAAAlDpDfA==",
]
def vrfy(data):
stats = {
"decoded": False,
"valid_crc": False,
"complete": False,
}
cue = Cue(data)
try:
cue.decode()
except:
return data, stats
stats["decoded"] = True
in_crc = cue.info_section.crc
stuff = cue.bites[: len(cue.bites) - 4]
stats["valid_crc"] = (False, True)[hex(crc32(stuff)) == in_crc]
cue.encode()
stats["complete"] = (False, True)[cue.info_section.crc == in_crc]
return data, stats
def do(cue_list):
"""
do return a dict of cue, valid
"""
cue_list = set(cue_list) # remove duplicates
results = {out[0]: out[1] for out in [vrfy(data) for data in cue_list]}
return results
if __name__ == "__main__":
print(do(cue_list))
a@fu:~$ pypy3 vrfy.py
{'/DAgAAAAAAAAAP/wDwUAAAEDf0//MqD0yAEDAAAAAHXkvig=': {'decoded': True, 'valid_crc': True, 'complete': True}, '/DA3AAAAAAAAAP/wDwUAAAAAf//+AClWCAIrAAAAFwIVQ1VFSQAAAAB/yAAAKTLgAQEwMAAAlDpDfA==': {'decoded': True, 'valid_crc': True, 'complete': False}}
|
Beta Was this translation helpful? Give feedback.
-
2022 is out of date man. There have been big changes since then. I still for the life of me can't figure out what kind of math middleman is doing, https://iodisco.com/cgi-bin/scte35decoder uses threefive. |
Beta Was this translation helpful? Give feedback.
I was worried about false negatives. As I mentioned, threefive re-calculates everything it can when encoding, and also fixes several common errors I've seen over and over. I decided to check the crc32 from the raw bites, much like you thinking with the hex.