public static boolean processSubtitles(TranscodeProfile profile) { // Check variables if (profile.getMediaElement() == null || profile.getCodecs() == null || profile.getFormat() == null) { return false; } // Check this is a video element if (profile.getMediaElement().getType() != MediaElementType.VIDEO) { return false; } // If there are no streams to process we are done if (profile.getMediaElement().getSubtitleStreams() == null) { return true; } // Process each subtitle stream List<SubtitleTranscode> transcodes = new ArrayList<>(); for (SubtitleStream stream : profile.getMediaElement().getSubtitleStreams()) { String codec = null; boolean hardcode = false; if (isSupported(profile.getCodecs(), stream.getFormat()) && isSupported(getCodecsForFormat(profile.getFormat()), stream.getFormat())) { codec = "copy"; } else if (isSupported(SUPPORTED_SUBTITLE_CODECS, stream.getFormat())) { codec = stream.getFormat(); hardcode = true; } // Enable forced subtitles by default if (stream.isForced() && profile.getSubtitleTrack() == null) { profile.setSubtitleTrack(stream.getStream()); } transcodes.add(new SubtitleTranscode(codec, hardcode)); } // Update profile profile.setSubtitleTranscodes(transcodes.toArray(new SubtitleTranscode[transcodes.size()])); return true; }
public Integer getForcedSubtitleIndex(MediaElement element) { // Check this is a video element if (element.getType() != MediaElementType.VIDEO) { return null; } // Get list of subtitle streams for video file List<SubtitleStream> subtitles = element.getSubtitleStreams(); if (subtitles == null) { return null; } // Scan subtitles for forced streams for (SubtitleStream subtitle : subtitles) { if (subtitle.isForced()) { return subtitle.getStream(); } } return null; }