aboutsummaryrefslogtreecommitdiffstats
path: root/remove-duplicate-frames.py
blob: c6451d86db67ddd5de207dffcbb77c38bf271896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
#
# This script removes duplicate frames from a RAW ETI file.
# It reads FCT from etisnoop output and only copies the
# frames if the FCT is increasing by one.
#
# usage:
# etisnoop -v -i in.eti | remove-duplicate-frames.py in.eti out.eti

import sys
import re

regex = re.compile(r'Frame Count \[([0-9]+)\]')

if len(sys.argv) < 3:
    print("usage: etisnoop -vi in.eti | {} in.eti out.eti".format(sys.argv[0]))
    sys.exit(1)


eti_in = open(sys.argv[1], "rb")
eti_out = open(sys.argv[2], "wb")

lastfct = -1
while True:
    line = sys.stdin.readline()
    if line == '':
        break

    fct = 0

    m = regex.search(line)
    if m is None:
        continue
    else:
        fct = int(m.groups()[0])

    if lastfct == 0 and fct == 249:
        print("Ignore {} duplicate rollover".format(fct))
        eti_in.read(6144)
    elif fct > lastfct:
        print("Take {}".format(fct))
        eti_out.write(eti_in.read(6144))
        lastfct = fct
    elif lastfct == 249 and fct == 0:
        print("Take {} because rollover".format(fct))
        eti_out.write(eti_in.read(6144))
        lastfct = fct
    else:
        print("Ignore {}".format(fct))
        eti_in.read(6144)