Skip empty subtitle elements when transcoding subtitle files

This commit is contained in:
Reinhard Pointner 2017-07-24 23:20:11 +08:00
parent 7274867035
commit 5a3bf98150
2 changed files with 10 additions and 5 deletions

View File

@ -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() {

View File

@ -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);
}
}