import sys p = sys.argv[1] if len(sys.argv) > 1 else '/tmp/cap.flv' d = open(p, 'rb').read() print('size', len(d)) if d[:3] != b'FLV': print('NOT FLV, first bytes:', d[:16].hex()); sys.exit(0) off = int.from_bytes(d[5:9], 'big') print('sig', d[:3], 'ver', d[3], 'flags', hex(d[4]), 'dataoffset', off) i = off + 4 # skip PrevTagSize0 n = 0 while i + 11 <= len(d) and n < 14: ttype = d[i] & 0x1f dsize = int.from_bytes(d[i+1:i+4], 'big') body = d[i+11:i+11+dsize] info = '' if ttype == 9 and body: b0 = body[0]; isEx = (b0 & 0x80) != 0 if isEx: ft = (b0 >> 4) & 7; pt = b0 & 0xf; fourcc = bytes(body[1:5]) info = f'video EX frameType={ft} packetType={pt} fourcc={fourcc} head={body[:14].hex()}' else: cid = b0 & 0xf; ft = (b0 >> 4) & 0xf; avcpt = body[1] if len(body) > 1 else -1 info = f'video LEGACY codecId={cid} frameType={ft} avcPacketType={avcpt} head={body[:14].hex()}' elif ttype == 18: info = 'script/meta' elif ttype == 8: info = 'audio' print(f'tag#{n} type={ttype} dsize={dsize} {info}') i = i + 11 + dsize + 4 n += 1