Program: 47224
Project: 47224
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<>();
  String filterOption="String_Node_Str";
  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 subsFilename=null;
      if (configuration.isFFmpegFontConfig()) {
        subsFilename=getSubtitles(dlna,media,params,configuration).getAbsolutePath();
      }
 else {
        subsFilename=params.sid.isEmbedded() ? dlna.getSystemName() : params.sid.getExternalFile().getAbsolutePath();
      }
      if (subsFilename != null) {
        StringBuilder s=new StringBuilder();
        CharacterIterator it=new StringCharacterIterator(subsFilename);
        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);
if (params.sid.isExternal() && params.sid.getType() != SubtitleType.ASS || configuration.isFFmpegFontConfig()) {
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()) {
filterOption="String_Node_Str";
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 {
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)) {
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(filterOption);
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<>();
  String filterOption="String_Node_Str";
  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 subsFilename=null;
      if (configuration.isFFmpegFontConfig()) {
        subsFilename=getSubtitles(dlna,media,params,configuration).getAbsolutePath();
      }
 else {
        subsFilename=params.sid.isEmbedded() ? dlna.getSystemName() : params.sid.getExternalFile().getAbsolutePath();
      }
      if (subsFilename != null) {
        StringBuilder s=new StringBuilder();
        CharacterIterator it=new StringCharacterIterator(subsFilename);
        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);
if (params.sid.isExternal() && params.sid.getType() != SubtitleType.ASS || configuration.isFFmpegFontConfig()) {
subsFilter.append("String_Node_Str");
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()) {
filterOption="String_Node_Str";
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 {
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)) {
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(filterOption);
videoFilterOptions.add(StringUtils.join(filterChain,"String_Node_Str"));
}
return videoFilterOptions;
}