Converting subtitle formats
Quick guide explaining how to convert subtitle formats via Bitmovin Encoding API
Introduction
If your encoding workflow handles ingestion of separate subtitle input files and you're interested in converting them to another subtitle format by generating an output file with a different subtitle type, such conversion can be programatically achieved via Bitmovin's Encoding API
Example
For example, if you have a TTML input file containing your original subtitles and want to convert them to WebVTT and generate .vtt files out of it, you could do something like this:
//define a fileInputStream object to read the subtitle input file, in this example a TTML one
FileInputStream fileInputStream = new FileInputStream();
fileInputStream.setFileType(FileInputStreamType.TTML); //allowed values are TTML, SRT and WEBVTT
fileInputStream.setInputId(s3Input.getId());
fileInputStream.setInputPath("sampleTTML.xml");
fileInputStream = bitmovinApi.encoding.encodings.inputStreams.file.create(encoding.getId(), fileInputStream);
//define a WebVTT configuration
WebVttConfiguration webVttConfiguration = new WebVttConfiguration();
webVttConfiguration.setName("WebVTT_sample");
webVttConfiguration = bitmovinApi.encoding.configurations.subtitles.webvtt.create(webVttConfiguration);
//create a Stream object to apply the conversion
Stream stream = new Stream();
stream.setCodecConfigId(webVttConfiguration.getId()); //applies WebVTT configuration
StreamInput stream_streamInput = new StreamInput();
stream_streamInput.setInputStreamId(fileInputStream.getId()); //takes subtitle TTML input file
stream_streamInput.setSelectionMode(StreamSelectionMode.AUTO);
stream.setInputStreams(List.of(stream_streamInput));
stream = bitmovinApi.encoding.encodings.streams.create(encoding.getId(), stream);
//mux the WebVTT subtitles writing them to .vtt file in your desired output
TextMuxing textMuxing = new TextMuxing();
textMuxing.setFilename("subtitle.vtt");
EncodingOutput textMuxing_encodingOutput = new EncodingOutput();
AclEntry textMuxing_encodingOutput_aclEntry = new AclEntry();
textMuxing_encodingOutput_aclEntry.setPermission(AclPermission.PUBLIC_READ); //or PRIVATE
textMuxing_encodingOutput.setAcl(List.of(textMuxing_encodingOutput_aclEntry));
textMuxing_encodingOutput.setOutputId(s3Output.getId());
textMuxing_encodingOutput.setOutputPath("yourOutputPath/subtitles/webvtt/");
textMuxing.setOutputs(List.of(textMuxing_encodingOutput));
textMuxing.setStreamConditionsMode(StreamConditionsMode.DROP_MUXING);
MuxingStream textMuxing_muxingStream = new MuxingStream();
textMuxing_muxingStream.setStreamId(stream.getId());
textMuxing.setStreams(List.of(textMuxing_muxingStream));
textMuxing = bitmovinApi.encoding.encodings.muxings.text.create(encoding.getId(), textMuxing);Limitations
- At the moment we can only read TTML, SRT and WEBVTT input file formats as part of FileInputStream object
- Supported subtitle conversion combinations are quite limited at the moment as outlined here, so in doubt or in case of issues with your specific use case, please don't hesitate to reach out to our Support team.
Updated about 7 hours ago