TeamNewPipe/NewPipe · error · IOException

TTML to SRT conversion failed

Error message

TTML to SRT conversion failed

What it means

Thrown by TtmlConverter when SrtFromTtmlWriter.build() throws a non-IOException exception (IOException is re-thrown directly). The catch-all Exception handler wraps the cause in an IOException with the message 'TTML to SRT conversion failed'. This happens during subtitle post-processing when the TTML source is malformed XML, has unexpected structure, or the writer hits a parse/number-format error it does not handle internally.

Source

Thrown at app/src/main/java/us/shandian/giga/postprocessing/TtmlConverter.java:37

    }

    @Override
    int process(SharpStream out, SharpStream... sources) throws IOException {
        // check if the subtitle is already in srt and copy, this should never happen
        String format = getArgumentAt(0, null);
        boolean ignoreEmptyFrames = getArgumentAt(1, "true").equals("true");

        if (format == null || format.equals("ttml")) {
            SrtFromTtmlWriter writer = new SrtFromTtmlWriter(out, ignoreEmptyFrames);

            try {
                writer.build(sources[0]);
            } catch (IOException err) {
                Log.e(TAG, "subtitle conversion failed due to I/O error", err);
                throw err;
            } catch (Exception err) {
                Log.e(TAG, "subtitle conversion failed", err);
                throw new IOException("TTML to SRT conversion failed", err);
            }

            return OK_RESULT;
        } else if (format.equals("srt")) {
            byte[] buffer = new byte[8 * 1024];
            int read;
            while ((read = sources[0].read(buffer)) > 0) {
                out.write(buffer, 0, read);
            }
            return OK_RESULT;
        }

        throw new UnsupportedOperationException("Can't convert this subtitle, unimplemented format: " + format);
    }

}

View on GitHub (pinned to 9e8be09156)

Solutions

  1. Pre-validate the TTML source is well-formed XML before conversion (parse with a forgiving parser, check root element is <tt>).
  2. Inspect the wrapped cause (IOException.getCause()) to identify the specific parse failure and fix that input.
  3. Handle the conversion failure gracefully and fall back to the original subtitle file or no subtitles.
  4. Update the SrtFromTtmlWriter if a specific TTML structure is consistently unhandled.

Example fix

// before — let the wrapped exception propagate
try {
    writer.build(sources[0]);
} catch (IOException err) {
    Log.e(TAG, "subtitle conversion failed due to I/O error", err);
    throw err;
}

// after — inspect cause and degrade gracefully
try {
    writer.build(sources[0]);
} catch (IOException err) {
    Throwable cause = err.getCause();
    Log.e(TAG, "TTML conversion failed: " + (cause != null ? cause.getMessage() : "unknown"), err);
    // fall back: copy original TTML through if conversion is impossible
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate the TTML source is well-formed XML before conversion:
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new InputStreamReader(sources[0]));
try {
    parser.next(); // will throw if not well-formed
} catch (XmlPullParserException e) {
    throw new IOException("TTML source is not well-formed XML", e);
}
sources[0].seek(0); // rewind for the writer

Try / catch

try {
    writer.build(sources[0]);
} catch (IOException err) {
    if ("TTML to SRT conversion failed".equals(err.getMessage())) {
        // unwrap cause for diagnostics, then fall back to raw passthrough
        Log.e(TAG, "TTML parse error: " + err.getCause());
        copyRawTtml(sources[0], out);
    } else throw err;
}

Prevention

When it happens

Trigger: TtmlConverter.process calls writer.build(sources[0]); inside build, an unchecked exception (XmlPullParserException, NumberFormatException, IllegalStateException, NullPointerException, etc.) escapes; the catch-Exception block wraps it. Caused by a TTML file that is not well-formed XML, has missing cue attributes, malformed timestamps, or unexpected element nesting.

Common situations: Subtitle source is truncated/malformed XML; a TTML variant with attributes the parser does not expect; timestamp values in a non-standard format causing NumberFormatException; empty or whitespace-only TTML documents; a provider serving HTML or an error page instead of TTML.

Related errors


AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14). Data as JSON: /api/errors/afab5b15edb62ba2. Report an issue: GitHub.