Program: 47218
Project: 47218
Buggy source:
/** 
 * Returns a list of strings representing the rescale options for this transcode i.e. the ffmpeg -vf options used to show subtitles in either SSA/ASS or picture-based format and resize a video that's too wide and/or high for the specified renderer. If the renderer has no size limits, or there's no media metadata, or the video is within the renderer's size limits, an empty list is returned.
 * @param dlna
 * @param media metadata for the DLNA resource which is being transcoded
 * @param params
 * @return a {@link List} of <code>String</code>s representing the rescale options for this video,or an empty list if the video doesn't need to be resized.
 * @throws java.io.IOException
 */
public List<String> getVideoFilterOptions(DLNAResource dlna,DLNAMediaInfo media,OutputParams params) throws IOException {
  List<String> videoFilterOptions=new ArrayList<>();
  ArrayList<String> filterChain=new ArrayList<>();
  final RendererConfiguration renderer=params.mediaRenderer;
  boolean isMediaValid=media != null && media.isMediaparsed() && media.getHeight() != 0;
  boolean isResolutionTooHighForRenderer=renderer.isMaximumResolutionSpecified() && isMediaValid && (media.getWidth() > renderer.getMaxVideoWidth() || media.getHeight() > renderer.getMaxVideoHeight());
  if (!isDisableSubtitles(params) && !(dlna.getPlayer() instanceof WebPlayer)) {
    StringBuilder subsFilter=new StringBuilder();
    if (params.sid.getType().isText()) {
      String originalSubsFilename;
      String subsFilename;
      if (configuration.isFFmpegFontConfig()) {
        originalSubsFilename=getSubtitles(dlna,media,params,configuration).getAbsolutePath();
      }
 else {
        originalSubsFilename=params.sid.isEmbedded() ? dlna.getSystemName() : params.sid.getExternalFile().getAbsolutePath();
      }
      if (originalSubsFilename != null) {
        StringBuilder s=new StringBuilder();
        CharacterIterator it=new StringCharacterIterator(originalSubsFilename);
        for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
switch (ch) {
case ':':
            s.append("String_Node_Str");
          break;
case '\\':
        s.append("String_Node_Str");
      break;
case ']':
case '[':
    s.append("String_Node_Str");
default :
  s.append(ch);
break;
}
}
subsFilename=s.toString();
subsFilename=subsFilename.replace("String_Node_Str","String_Node_Str");
subsFilter.append("String_Node_Str").append(subsFilename);
int originalWidth=384;
int originalHeight=288;
if (params.sid.isExternal() && params.sid.getType() != SubtitleType.ASS || configuration.isFFmpegFontConfig()) {
getOriginalResolution(originalSubsFilename,originalWidth,originalHeight);
subsFilter.append("String_Node_Str").append(originalWidth).append("String_Node_Str").append(originalHeight);
if (!params.sid.isExternalFileUtf8()) {
String encoding=isNotBlank(configuration.getSubtitlesCodepage()) ? configuration.getSubtitlesCodepage() : params.sid.getExternalFileCharacterSet() != null ? params.sid.getExternalFileCharacterSet() : null;
if (encoding != null) {
subsFilter.append("String_Node_Str").append(encoding);
}
}
}
 else if (params.sid.isEmbedded()) {
subsFilter.append("String_Node_Str").append(media.getSubtitleTracksList().indexOf(params.sid));
}
}
}
 else if (params.sid.getType().isPicture()) {
if (params.sid.getId() < 100) {
subsFilter.append("String_Node_Str").append(media.getSubtitleTracksList().indexOf(params.sid)).append("String_Node_Str");
}
 else {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add(params.sid.getExternalFile().getAbsolutePath());
subsFilter.append("String_Node_Str");
}
}
if (isNotBlank(subsFilter)) {
filterChain.add(subsFilter.toString());
if (params.timeseek > 0) {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str" + params.timeseek + "String_Node_Str");
filterChain.add("String_Node_Str" + params.timeseek + "String_Node_Str");
}
}
}
int scaleWidth=0;
int scaleHeight=0;
if (media.getWidth() > 0 && media.getHeight() > 0) {
scaleWidth=media.getWidth();
scaleHeight=media.getHeight();
}
String overrideVF=renderer.getFFmpegVideoFilterOverride();
if (StringUtils.isNotEmpty(overrideVF)) {
filterChain.add(overrideVF);
}
 else {
boolean keepAR=renderer.isKeepAspectRatio() && !(media.getWidth() == 3840 && media.getHeight() <= 1080 || media.getWidth() == 1920 && media.getHeight() == 2160) && !"String_Node_Str".equals(media.getAspectRatioContainer());
if (isResolutionTooHighForRenderer || (!renderer.isRescaleByRenderer() && renderer.isMaximumResolutionSpecified() && media.getWidth() < 720)) {
filterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
if (keepAR) {
filterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
}
}
 else if (keepAR && isMediaValid) {
if ((media.getWidth() / (double)media.getHeight()) >= (16 / (double)9)) {
filterChain.add("String_Node_Str");
scaleHeight=(int)Math.round(scaleWidth / (16 / (double)9));
}
 else {
filterChain.add("String_Node_Str");
scaleWidth=(int)Math.round(scaleHeight * (16 / (double)9));
}
scaleWidth=convertToMod4(scaleWidth);
scaleHeight=convertToMod4(scaleHeight);
filterChain.add("String_Node_Str" + scaleWidth + "String_Node_Str"+ scaleHeight);
}
}
if (filterChain.size() > 0) {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add(StringUtils.join(filterChain,"String_Node_Str"));
}
return videoFilterOptions;
}

Fixed version (ground truth):
/** 
 * Returns a list of strings representing the rescale options for this transcode i.e. the ffmpeg -vf options used to show subtitles in either SSA/ASS or picture-based format and resize a video that's too wide and/or high for the specified renderer. If the renderer has no size limits, or there's no media metadata, or the video is within the renderer's size limits, an empty list is returned.
 * @param dlna
 * @param media metadata for the DLNA resource which is being transcoded
 * @param params
 * @return a {@link List} of <code>String</code>s representing the rescale options for this video,or an empty list if the video doesn't need to be resized.
 * @throws java.io.IOException
 */
public List<String> getVideoFilterOptions(DLNAResource dlna,DLNAMediaInfo media,OutputParams params) throws IOException {
  List<String> videoFilterOptions=new ArrayList<>();
  ArrayList<String> filterChain=new ArrayList<>();
  ArrayList<String> scalePadFilterChain=new ArrayList<>();
  final RendererConfiguration renderer=params.mediaRenderer;
  boolean isMediaValid=media != null && media.isMediaparsed() && media.getHeight() != 0;
  boolean isResolutionTooHighForRenderer=renderer.isMaximumResolutionSpecified() && isMediaValid && (media.getWidth() > renderer.getMaxVideoWidth() || media.getHeight() > renderer.getMaxVideoHeight());
  int scaleWidth=0;
  int scaleHeight=0;
  if (media.getWidth() > 0 && media.getHeight() > 0) {
    scaleWidth=media.getWidth();
    scaleHeight=media.getHeight();
  }
  boolean keepAR=renderer.isKeepAspectRatio() && !(media.getWidth() == 3840 && media.getHeight() <= 1080 || media.getWidth() == 1920 && media.getHeight() == 2160) && !"String_Node_Str".equals(media.getAspectRatioContainer());
  if (isResolutionTooHighForRenderer || (!renderer.isRescaleByRenderer() && renderer.isMaximumResolutionSpecified() && media.getWidth() < 720)) {
    scalePadFilterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
    if (keepAR) {
      scalePadFilterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
    }
  }
 else   if (keepAR && isMediaValid) {
    if ((media.getWidth() / (double)media.getHeight()) >= (16 / (double)9)) {
      scalePadFilterChain.add("String_Node_Str");
      scaleHeight=(int)Math.round(scaleWidth / (16 / (double)9));
    }
 else {
      scalePadFilterChain.add("String_Node_Str");
      scaleWidth=(int)Math.round(scaleHeight * (16 / (double)9));
    }
    scaleWidth=convertToMod4(scaleWidth);
    scaleHeight=convertToMod4(scaleHeight);
    scalePadFilterChain.add("String_Node_Str" + scaleWidth + "String_Node_Str"+ scaleHeight);
  }
  if (!isDisableSubtitles(params) && !(dlna.getPlayer() instanceof WebPlayer)) {
    StringBuilder subsFilter=new StringBuilder();
    if (params.sid.getType().isText()) {
      String originalSubsFilename;
      String subsFilename;
      if (configuration.isFFmpegFontConfig()) {
        originalSubsFilename=getSubtitles(dlna,media,params,configuration).getAbsolutePath();
      }
 else {
        originalSubsFilename=params.sid.isEmbedded() ? dlna.getSystemName() : params.sid.getExternalFile().getAbsolutePath();
      }
      if (originalSubsFilename != null) {
        StringBuilder s=new StringBuilder();
        CharacterIterator it=new StringCharacterIterator(originalSubsFilename);
        for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
switch (ch) {
case ':':
            s.append("String_Node_Str");
          break;
case '\\':
        s.append("String_Node_Str");
      break;
case ']':
case '[':
    s.append("String_Node_Str");
default :
  s.append(ch);
break;
}
}
subsFilename=s.toString();
subsFilename=subsFilename.replace("String_Node_Str","String_Node_Str");
subsFilter.append("String_Node_Str").append(subsFilename);
int subtitlesWidth=scaleWidth;
int subtitlesHeight=scaleHeight;
if (params.sid.isExternal() && params.sid.getType() != SubtitleType.ASS || configuration.isFFmpegFontConfig()) {
setSubtitlesResolution(originalSubsFilename,subtitlesWidth,subtitlesHeight);
subsFilter.append("String_Node_Str").append(subtitlesWidth).append("String_Node_Str").append(subtitlesHeight);
if (!params.sid.isExternalFileUtf8()) {
String encoding=isNotBlank(configuration.getSubtitlesCodepage()) ? configuration.getSubtitlesCodepage() : params.sid.getExternalFileCharacterSet() != null ? params.sid.getExternalFileCharacterSet() : null;
if (encoding != null) {
subsFilter.append("String_Node_Str").append(encoding);
}
}
}
 else if (params.sid.isEmbedded()) {
subsFilter.append("String_Node_Str").append(media.getSubtitleTracksList().indexOf(params.sid));
}
}
}
 else if (params.sid.getType().isPicture()) {
if (params.sid.getId() < 100) {
subsFilter.append("String_Node_Str").append(media.getSubtitleTracksList().indexOf(params.sid)).append("String_Node_Str");
}
 else {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add(params.sid.getExternalFile().getAbsolutePath());
subsFilter.append("String_Node_Str");
}
}
if (isNotBlank(subsFilter)) {
filterChain.add(subsFilter.toString());
if (params.timeseek > 0) {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add("String_Node_Str" + params.timeseek + "String_Node_Str");
filterChain.add("String_Node_Str" + params.timeseek + "String_Node_Str");
}
}
}
String overrideVF=renderer.getFFmpegVideoFilterOverride();
if (StringUtils.isNotEmpty(overrideVF)) {
filterChain.add(overrideVF);
}
 else {
filterChain.addAll(scalePadFilterChain);
}
if (filterChain.size() > 0) {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add(StringUtils.join(filterChain,"String_Node_Str"));
}
return videoFilterOptions;
}