Skip to content

Commit

Permalink
Merge branch 'vapoursynth' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Nov 1, 2023
2 parents fac664a + 0d281af commit 95500b8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions automation/vapoursynth/aegisub_vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ def make_keyframes_filename(filename: str) -> str:
class LWIndexFrame:
pts: int
key: int
index: int

def __init__(self, raw: list[str]):
match1 = lwindex_re1.match(raw[0])
match2 = lwindex_re2.match(raw[1])
if not match1 or not match2:
raise ValueError("Invalid lwindex format")
self.index = int(match1.group("Index"))
self.pts = int(match1.group("PTS"))
self.key = int(match2.group("Key"))

Expand All @@ -150,11 +152,13 @@ def info_from_lwindex(indexfile: str) -> Dict[str, List[int]]:
with open(indexfile, encoding="latin1") as f:
index = f.read().splitlines()

indexstart, indexend = index.index("</StreamInfo>") + 1, index.index("</LibavReaderIndex>")
# The picture list starts after the last </StreamInfo> tag
indexstart, indexend = (len(index) - index[::-1].index("</StreamInfo>")), index.index("</LibavReaderIndex>")
frames = [LWIndexFrame(index[i:i+2]) for i in range(indexstart, indexend, 2)]
frames = [f for f in frames if f.index == 0] # select the first stream
frames.sort(key=int)

streaminfo = streaminfo_re.match(index[indexstart - 2])
streaminfo = streaminfo_re.match(index[index.index("<StreamInfo=0,0>") + 1]) # info of first stream
if not streaminfo:
raise ValueError("Invalid lwindex format")

Expand Down

0 comments on commit 95500b8

Please sign in to comment.