Skip empty subtitle elements when transcoding subtitle files
This commit is contained in:
parent
7274867035
commit
5a3bf98150
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
package net.filebot.subtitle;
|
package net.filebot.subtitle;
|
||||||
|
|
||||||
|
|
||||||
public class SubtitleElement {
|
public class SubtitleElement {
|
||||||
|
|
||||||
private final long start;
|
private final long start;
|
||||||
@ -9,28 +8,27 @@ public class SubtitleElement {
|
|||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
|
|
||||||
public SubtitleElement(long start, long end, String text) {
|
public SubtitleElement(long start, long end, String text) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getStart() {
|
public long getStart() {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getEnd() {
|
public long getEnd() {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return start >= end || text.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -353,9 +353,16 @@ public final class SubtitleUtilities {
|
|||||||
// convert to target format and target encoding
|
// convert to target format and target encoding
|
||||||
try (SubRipWriter out = new SubRipWriter(writer)) {
|
try (SubRipWriter out = new SubRipWriter(writer)) {
|
||||||
for (SubtitleElement it : decodeSubtitles(file)) {
|
for (SubtitleElement it : decodeSubtitles(file)) {
|
||||||
|
if (it.isEmpty()) {
|
||||||
|
debug.warning(message("Subtitle element is empty", it));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjust offset if necessary
|
||||||
if (outputTimingOffset != 0) {
|
if (outputTimingOffset != 0) {
|
||||||
it = new SubtitleElement(Math.max(0, it.getStart() + outputTimingOffset), Math.max(0, it.getEnd() + outputTimingOffset), it.getText());
|
it = new SubtitleElement(Math.max(0, it.getStart() + outputTimingOffset), Math.max(0, it.getEnd() + outputTimingOffset), it.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
out.write(it);
|
out.write(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user