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} ***")