Program: 47211
Project: 47211
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<>();
  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 is3D=media.is3d() && !media.stereoscopyIsAnaglyph();
  boolean keepAR=renderer.isKeepAspectRatio() && !media.is3dFullSbsOrOu() && !"String_Node_Str".equals(media.getAspectRatioContainer());
  if (isResolutionTooHighForRenderer || (!renderer.isRescaleByRenderer() && renderer.isMaximumResolutionSpecified() && media.getWidth() < 720)) {
    if (media.is3dFullSbsOrOu()) {
      scalePadFilterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
    }
 else {
      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=convertToModX(scaleWidth,4);
    scaleHeight=convertToModX(scaleHeight,4);
    if (scaleHeight > renderer.getMaxVideoHeight() || scaleWidth > renderer.getMaxVideoWidth()) {
      scaleHeight=renderer.getMaxVideoHeight();
      scaleWidth=renderer.getMaxVideoWidth();
    }
    scalePadFilterChain.add("String_Node_Str" + scaleWidth + "String_Node_Str"+ scaleHeight);
  }
  if (!isDisableSubtitles(params) && !params.sid.isStreamable() && !(dlna.getPlayer() instanceof WebPlayer)) {
    StringBuilder subsFilter=new StringBuilder();
    if (params.sid.getType().isText()) {
      String originalSubsFilename;
      String subsFilename;
      if (params.sid.isEmbedded() || configuration.isFFmpegFontConfig() || is3D) {
        originalSubsFilename=SubtitleUtils.getSubtitles(dlna,media,params,configuration,SubtitleType.ASS).getAbsolutePath();
      }
 else {
        originalSubsFilename=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()) {
if (subtitlesWidth > 0 && subtitlesHeight > 0) {
if (params.sid.getType() == SubtitleType.ASS) {
setSubtitlesResolution(originalSubsFilename,subtitlesWidth,subtitlesHeight);
}
if (!is3D) {
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.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 (is3D && media.get3DLayout() != null && isNotBlank(params.mediaRenderer.getOutput3DFormat()) && !media.get3DLayout().toString().toLowerCase().equals(params.mediaRenderer.getOutput3DFormat().trim())) {
filterChain.add("String_Node_Str" + media.get3DLayout().toString().toLowerCase() + "String_Node_Str"+ params.mediaRenderer.getOutput3DFormat().trim().toLowerCase());
}
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 is3D=media.is3d() && !media.stereoscopyIsAnaglyph();
  boolean keepAR=renderer.isKeepAspectRatio() && !media.is3dFullSbsOrOu() && !"String_Node_Str".equals(media.getAspectRatioContainer());
  if (isResolutionTooHighForRenderer || (!renderer.isRescaleByRenderer() && renderer.isMaximumResolutionSpecified() && media.getWidth() < 720)) {
    if (media.is3dFullSbsOrOu()) {
      scalePadFilterChain.add(String.format("String_Node_Str",renderer.getMaxVideoWidth(),renderer.getMaxVideoHeight()));
    }
 else {
      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=convertToModX(scaleWidth,4);
    scaleHeight=convertToModX(scaleHeight,4);
    if (scaleHeight > renderer.getMaxVideoHeight() || scaleWidth > renderer.getMaxVideoWidth()) {
      scaleHeight=renderer.getMaxVideoHeight();
      scaleWidth=renderer.getMaxVideoWidth();
    }
    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 (params.sid.isEmbedded() || configuration.isFFmpegFontConfig() || is3D) {
        originalSubsFilename=SubtitleUtils.getSubtitles(dlna,media,params,configuration,SubtitleType.ASS).getAbsolutePath();
      }
 else {
        originalSubsFilename=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()) {
if (subtitlesWidth > 0 && subtitlesHeight > 0) {
if (params.sid.getType() == SubtitleType.ASS) {
setSubtitlesResolution(originalSubsFilename,subtitlesWidth,subtitlesHeight);
}
if (!is3D) {
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.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 (is3D && media.get3DLayout() != null && isNotBlank(params.mediaRenderer.getOutput3DFormat()) && !media.get3DLayout().toString().toLowerCase().equals(params.mediaRenderer.getOutput3DFormat().trim())) {
filterChain.add("String_Node_Str" + media.get3DLayout().toString().toLowerCase() + "String_Node_Str"+ params.mediaRenderer.getOutput3DFormat().trim().toLowerCase());
}
if (filterChain.size() > 0) {
videoFilterOptions.add("String_Node_Str");
videoFilterOptions.add(StringUtils.join(filterChain,"String_Node_Str"));
}
return videoFilterOptions;
}