From 07fa563fa6208bd1fdef9b9c13f1c3e2bd5d3be1 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 23 Nov 2023 09:40:04 +0100 Subject: [PATCH 1/2] vapoursynth: Ignore __aegi_timecodes on single-frame clips The vfr class (understandably) does not like timecode lists with only one element, so the current default script breaks when opening images. So to not bloat the default script too much we just ignore __aegi_timecodes in the provider in these cases. --- src/video_provider_vs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_provider_vs.cpp b/src/video_provider_vs.cpp index a59c583e1e..c0d4322270 100644 --- a/src/video_provider_vs.cpp +++ b/src/video_provider_vs.cpp @@ -209,7 +209,7 @@ VapourSynthVideoProvider::VapourSynthVideoProvider(agi::fs::path const& filename } } - if (numtc != -1) { + if (numtc != -1 && vi->numFrames > 1) { const int64_t *tcs = vs.GetAPI()->mapGetIntArray(clipinfo, tc_key, &err1); const char *tcs_path = vs.GetAPI()->mapGetData(clipinfo, tc_key, 0, &err2); if (err1 && err2) From 928a2d4c6c78e19f05ed94c7057957f62f00c9c8 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 23 Nov 2023 10:00:11 +0100 Subject: [PATCH 2/2] vapoursynth: Fix lwindex parsing when video is not the first stream SubKt my beloved... This was broken in 0d281af269251cf8abd29312c490378cf80fe5eb and is fixed in a more robust way in this commit. --- automation/vapoursynth/aegisub_vs.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index c05e37d26b..65449a42bd 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -123,6 +123,7 @@ def make_keyframes_filename(filename: str) -> str: lwindex_re1 = re.compile(r"Index=(?P-?[0-9]+),POS=(?P-?[0-9]+),PTS=(?P-?[0-9]+),DTS=(?P-?[0-9]+),EDI=(?P-?[0-9]+)") lwindex_re2 = re.compile(r"Key=(?P-?[0-9]+),Pic=(?P-?[0-9]+),POC=(?P-?[0-9]+),Repeat=(?P-?[0-9]+),Field=(?P-?[0-9]+)") streaminfo_re = re.compile(r"Codec=(?P[0-9]+),TimeBase=(?P[0-9\/]+),Width=(?P[0-9]+),Height=(?P[0-9]+),Format=(?P[0-9a-zA-Z]+),ColorSpace=(?P[0-9]+)") +videoindex_re = re.compile(r"(?P[0-9+]+)") class LWIndexFrame: pts: int @@ -152,13 +153,19 @@ def info_from_lwindex(indexfile: str) -> Dict[str, List[int]]: with open(indexfile, encoding="latin1") as f: index = f.read().splitlines() + videoindex_str = next(l for l in index if l.startswith("")) + videoindex_match = videoindex_re.match(videoindex_str) + if not videoindex_match: + raise ValueError("Invalid lwindex format: Invalid ActiveVideoStreamIndex line") + videoindex = int(videoindex_match.group("VideoStreamIndex")) + # The picture list starts after the last tag indexstart, indexend = (len(index) - index[::-1].index("")), index.index("") 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 = [f for f in frames if f.index == videoindex] # select the first stream frames.sort(key=int) - streaminfo = streaminfo_re.match(index[index.index("") + 1]) # info of first stream + streaminfo = streaminfo_re.match(index[index.index(f"") + 1]) # info of first stream if not streaminfo: raise ValueError("Invalid lwindex format")