From b1f3bfab417fe8c4b9076a317f3e730b965fe470 Mon Sep 17 00:00:00 2001 From: eighh1 <35957748+zx3777@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:16:25 +0800 Subject: [PATCH] Fixes incomplete SRT output when `ts2srt` encounters parsing errors. When extracting subtitles from MPEG-TS files, if parsing encounters an error partway through the file, buffered SRT content is never written to disk. This results in incomplete subtitle files. --- arib/ts2srt.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arib/ts2srt.py b/arib/ts2srt.py index 858085c..7ddbe53 100755 --- a/arib/ts2srt.py +++ b/arib/ts2srt.py @@ -144,7 +144,13 @@ def run(self) -> int: ts.OnTSPacket = self.on_ts_packet ts.OnESPacket = self.on_es_packet - ts.Parse() + try: + ts.Parse() + finally: + # Ensure buffered subtitle data is written to disk even if parsing + # encounters errors partway through the file + if self.srt: + self.srt.finalize() if self.pid < 0 and not self.cfg.quiet: print(f"*** Sorry. No ARIB subtitle content was found in file: {self.cfg.infile} ***")