Program: 47135
Project: 47135
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=isMediaValid && !params.mediaRenderer.isResolutionCompatibleWithRenderer(media.getWidth(),media.getHeight());
  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);
  }
  boolean override=true;
  if (renderer instanceof RendererConfiguration.OutputOverride) {
    RendererConfiguration.OutputOverride or=(RendererConfiguration.OutputOverride)renderer;
    override=or.addSubtitles();
  }
  if (!isDisableSubtitles(params) && override) {
    StringBuilder subsFilter=new StringBuilder();
    if (params.sid != null && params.sid.getType().isText()) {
      String originalSubsFilename=null;
      String subsFilename;
      if (is3D && params.sid.getType() != SubtitleType.ASS) {
        originalSubsFilename=SubtitleUtils.getSubtitles(dlna,media,params,configuration,SubtitleType.ASS).getAbsolutePath();
      }
 else       if (params.sid.isExternal()) {
        originalSubsFilename=params.sid.getExternalFile().getAbsolutePath();
      }
 else       if (params.sid.isEmbedded()) {
        originalSubsFilename=dlna.getSystemName();
      }
      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 '\\':
    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);
if (params.sid.isEmbedded()) {
subsFilter.append("String_Node_Str").append(params.sid.getId());
}
if (!params.sid.isSubsUtf8()) {
String encoding=isNotBlank(configuration.getSubtitlesCodepage()) ? configuration.getSubtitlesCodepage() : params.sid.getSubCharacterSet() != null ? params.sid.getSubCharacterSet() : null;
if (encoding != null) {
subsFilter.append("String_Node_Str").append(encoding);
}
}
if (configuration.isFFmpegFontConfig() && !is3D) {
subsFilter.append("String_Node_Str");
subsFilter.append("String_Node_Str");
if (!is3D) {
subsFilter.append("String_Node_Str").append((int)16 * Double.parseDouble(configuration.getAssScale()));
}
subsFilter.append("String_Node_Str").append(SubtitleUtils.convertColourToASSColourString(configuration.getSubsColor()));
subsFilter.append("String_Node_Str").append(configuration.getAssOutline());
subsFilter.append("String_Node_Str").append(configuration.getAssShadow());
if (!is3D) {
subsFilter.append("String_Node_Str").append(configuration.getAssMargin());
}
;
subsFilter.append("String_Node_Str");
}
}
}
 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)) {
if (params.timeseek > 0) {
filterChain.add("String_Node_Str" + params.timeseek + "String_Node_Str");
}
filterChain.add(subsFilter.toString());
if (params.timeseek > 0) {
filterChain.add("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=isMediaValid && !params.mediaRenderer.isResolutionCompatibleWithRenderer(media.getWidth(),media.getHeight());
  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);
  }
  filterChain.addAll(scalePadFilterChain);
  boolean override=true;
  if (renderer instanceof RendererConfiguration.OutputOverride) {
    RendererConfiguration.OutputOverride or=(RendererConfiguration.OutputOverride)renderer;
    override=or.addSubtitles();
  }
  if (!isDisableSubtitles(params) && override) {
    StringBuilder subsFilter=new StringBuilder();
    if (params.sid != null && params.sid.getType().isText()) {
      String originalSubsFilename=null;
      String subsFilename;
      if (is3D && params.sid.getType() != SubtitleType.ASS) {
        originalSubsFilename=SubtitleUtils.getSubtitles(dlna,media,params,configuration,SubtitleType.ASS).getAbsolutePath();
      }
 else       if (params.sid.isExternal()) {
        originalSubsFilename=params.sid.getExternalFile().getAbsolutePath();
      }
 else       if (params.sid.isEmbedded()) {
        originalSubsFilename=dlna.getSystemName();
      }
      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 '\\':
    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);
if (params.sid.isEmbedded()) {
subsFilter.append("String_Node_Str").append(params.sid.getId());
}
if (!params.sid.isSubsUtf8()) {
String encoding=isNotBlank(configuration.getSubtitlesCodepage()) ? configuration.getSubtitlesCodepage() : params.sid.getSubCharacterSet() != null ? params.sid.getSubCharacterSet() : null;
if (encoding != null) {
subsFilter.append("String_Node_Str").append(encoding);
}
}
if (configuration.isFFmpegFontConfig() && !is3D) {
subsFilter.append("String_Node_Str");
subsFilter.append("String_Node_Str");
if (!is3D) {
subsFilter.append("String_Node_Str").append((int)16 * Double.parseDouble(configuration.getAssScale()));
}
subsFilter.append("String_Node_Str").append(SubtitleUtils.convertColourToASSColourString(configuration.getSubsColor()));
subsFilter.append("String_Node_Str").append(configuration.getAssOutline());
subsFilter.append("String_Node_Str").append(configuration.getAssShadow());
if (!is3D) {
subsFilter.append("String_Node_Str").append(configuration.getAssMargin());
}
;
subsFilter.append("String_Node_Str");
}
}
}
 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)) {
if (params.timeseek > 0) {
filterChain.add("String_Node_Str" + params.timeseek + "String_Node_Str");
}
filterChain.add(subsFilter.toString());
if (params.timeseek > 0) {
filterChain.add("String_Node_Str");
}
}
}
String overrideVF=renderer.getFFmpegVideoFilterOverride();
if (StringUtils.isNotEmpty(overrideVF)) {
filterChain.add(overrideVF);
}
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;
}