From 5a3bf98150d2701d9eff6684e7bd4cc4bb34f332 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 24 Jul 2017 23:20:11 +0800 Subject: [PATCH] Skip empty subtitle elements when transcoding subtitle files --- source/net/filebot/subtitle/SubtitleElement.java | 8 +++----- source/net/filebot/subtitle/SubtitleUtilities.java | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/net/filebot/subtitle/SubtitleElement.java b/source/net/filebot/subtitle/SubtitleElement.java index 21af1884..d992eeb2 100644 --- a/source/net/filebot/subtitle/SubtitleElement.java +++ b/source/net/filebot/subtitle/SubtitleElement.java @@ -1,7 +1,6 @@ package net.filebot.subtitle; - public class SubtitleElement { private final long start; @@ -9,28 +8,27 @@ public class SubtitleElement { private final String text; - public SubtitleElement(long start, long end, String text) { this.start = start; this.end = end; this.text = text; } - public long getStart() { return start; } - public long getEnd() { return end; } - public String getText() { return text; } + public boolean isEmpty() { + return start >= end || text.isEmpty(); + } @Override public String toString() { diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index 0461cdac..9485d2d6 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -353,9 +353,16 @@ public final class SubtitleUtilities { // convert to target format and target encoding try (SubRipWriter out = new SubRipWriter(writer)) { for (SubtitleElement it : decodeSubtitles(file)) { + if (it.isEmpty()) { + debug.warning(message("Subtitle element is empty", it)); + continue; + } + + // adjust offset if necessary if (outputTimingOffset != 0) { it = new SubtitleElement(Math.max(0, it.getStart() + outputTimingOffset), Math.max(0, it.getEnd() + outputTimingOffset), it.getText()); } + out.write(it); } }