Program: 47282
Project: 47282
Buggy source:
@Override public ProcessWrapper launchTranscode(String fileName,DLNAResource dlna,DLNAMediaInfo media,OutputParams params) throws IOException {
  int nThreads=configuration.getNumberOfCpuCores();
  List<String> cmdList=new ArrayList<String>();
  RendererConfiguration renderer=params.mediaRenderer;
  setAudioAndSubs(fileName,media,params,configuration);
  boolean avisynth=avisynth();
  cmdList.add(executable());
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  if (params.timeseek > 0) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + params.timeseek);
  }
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str" + nThreads);
  final boolean isTsMuxeRVideoEngineEnabled=configuration.getEnginesAsList(PMS.get().getRegistry()).contains(TsMuxeRVideo.ID);
  ac3Remux=false;
  dtsRemux=false;
  if (configuration.isRemuxAC3() && params.aid != null && params.aid.isAC3() && !avisynth() && params.mediaRenderer.isTranscodeToAC3()) {
    ac3Remux=true;
  }
 else {
    dtsRemux=isTsMuxeRVideoEngineEnabled && configuration.isDTSEmbedInPCM() && params.aid != null && params.aid.isDTS() && !avisynth() && params.mediaRenderer.isDTSPlayable();
  }
  String frameRateRatio=null;
  String frameRateNumber=null;
  if (media != null) {
    frameRateRatio=media.getValidFps(true);
    frameRateNumber=media.getValidFps(false);
  }
  cmdList.add("String_Node_Str");
  if (avisynth && !fileName.toLowerCase().endsWith("String_Node_Str")) {
    File avsFile=AviSynthFFmpeg.getAVSScript(fileName,params.sid,params.fromFrame,params.toFrame,frameRateRatio,frameRateNumber);
    cmdList.add(ProcessUtil.getShortFileNameIfWideChars(avsFile.getAbsolutePath()));
  }
 else {
    cmdList.add(fileName);
  }
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str" + Integer.toString(params.aid.getId() + 1));
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str" + nThreads);
  if (params.timeend > 0) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + params.timeend);
  }
  cmdList.addAll(getRescaleOptions(renderer,media));
  int defaultMaxBitrates[]=getVideoBitrateConfig(configuration.getMaximumBitrate());
  int rendererMaxBitrates[]=new int[2];
  if (renderer.getMaxVideoBitrate() != null) {
    rendererMaxBitrates=getVideoBitrateConfig(renderer.getMaxVideoBitrate());
  }
  if ((defaultMaxBitrates[0] == 0 && rendererMaxBitrates[0] > 0) || rendererMaxBitrates[0] < defaultMaxBitrates[0] && rendererMaxBitrates[0] > 0) {
    defaultMaxBitrates=rendererMaxBitrates;
  }
  if (params.mediaRenderer.getCBRVideoBitrate() == 0 && defaultMaxBitrates[0] > 0) {
    defaultMaxBitrates[0]=1000 * defaultMaxBitrates[0];
    defaultMaxBitrates[0]=defaultMaxBitrates[0] / 2;
    int bufSize=1835;
    if (media.isHDVideo()) {
      bufSize=defaultMaxBitrates[0] / 3;
    }
    if (bufSize > 7000) {
      bufSize=7000;
    }
    if (defaultMaxBitrates[1] > 0) {
      bufSize=defaultMaxBitrates[1];
    }
    if (params.mediaRenderer.isDefaultVBVSize() && rendererMaxBitrates[1] == 0) {
      bufSize=1835;
    }
    defaultMaxBitrates[0]=defaultMaxBitrates[0] - configuration.getAudioBitrate();
    defaultMaxBitrates[0]=defaultMaxBitrates[0] / 1000 * 1000;
    bufSize=bufSize * 1000;
    defaultMaxBitrates[0]=defaultMaxBitrates[0] * 1000;
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + bufSize);
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + defaultMaxBitrates[0]);
  }
  int channels;
  if (ac3Remux) {
    channels=params.aid.getAudioProperties().getNumberOfChannels();
  }
 else   if (dtsRemux) {
    channels=2;
  }
 else {
    channels=configuration.getAudioChannelCount();
  }
  LOGGER.trace("String_Node_Str" + channels);
  if (!(params.aid.isAC3() && !ac3Remux) && !(type() == Format.AUDIO)) {
    cmdList.add("String_Node_Str");
    cmdList.add(configuration.getAudioBitrate() + "String_Node_Str");
  }
  cmdList.addAll(getCustomArgs());
  cmdList.addAll(getTranscodeVideoOptions(renderer,media,params));
  if (!dtsRemux) {
    cmdList.add("String_Node_Str");
  }
  String[] cmdArray=new String[cmdList.size()];
  cmdList.toArray(cmdArray);
  cmdArray=finalizeTranscoderArgs(fileName,dlna,media,params,cmdArray);
  ProcessWrapperImpl pw=new ProcessWrapperImpl(cmdArray,params);
  if (dtsRemux) {
    PipeProcess pipe;
    pipe=new PipeProcess(System.currentTimeMillis() + "String_Node_Str");
    TsMuxeRVideo ts=new TsMuxeRVideo(configuration);
    File f=new File(configuration.getTempFolder(),"String_Node_Str");
    String cmd[]=new String[]{ts.executable(),f.getAbsolutePath(),pipe.getInputPipe()};
    pw=new ProcessWrapperImpl(cmd,params);
    PipeIPCProcess ffVideoPipe=new PipeIPCProcess(System.currentTimeMillis() + "String_Node_Str",System.currentTimeMillis() + "String_Node_Str",false,true);
    cmdList.add(ffVideoPipe.getInputPipe());
    OutputParams ffparams=new OutputParams(configuration);
    ffparams.maxBufferSize=1;
    ffparams.stdin=params.stdin;
    String[] cmdArrayDts=new String[cmdList.size()];
    cmdList.toArray(cmdArrayDts);
    cmdArrayDts=finalizeTranscoderArgs(fileName,dlna,media,params,cmdArrayDts);
    ProcessWrapperImpl ffVideo=new ProcessWrapperImpl(cmdArrayDts,ffparams);
    ProcessWrapper ff_video_pipe_process=ffVideoPipe.getPipeProcess();
    pw.attachProcess(ff_video_pipe_process);
    ff_video_pipe_process.runInNewThread();
    ffVideoPipe.deleteLater();
    pw.attachProcess(ffVideo);
    ffVideo.runInNewThread();
    PipeIPCProcess ffAudioPipe=new PipeIPCProcess(System.currentTimeMillis() + "String_Node_Str",System.currentTimeMillis() + "String_Node_Str",false,true);
    StreamModifier sm=new StreamModifier();
    sm.setPcm(false);
    sm.setDtsEmbed(dtsRemux);
    sm.setSampleFrequency(48000);
    sm.setBitsPerSample(16);
    sm.setNbChannels(channels);
    String ffmpegLPCMextract[]=new String[]{executable(),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",fileName,"String_Node_Str","String_Node_Str" + channels,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",ffAudioPipe.getInputPipe()};
    if (!params.mediaRenderer.isMuxDTSToMpeg()) {
      ffAudioPipe.setModifier(sm);
    }
    if (params.stdin != null) {
      ffmpegLPCMextract[4]="String_Node_Str";
    }
    if (params.timeseek > 0) {
      ffmpegLPCMextract[3]="String_Node_Str" + params.timeseek;
    }
    OutputParams ffaudioparams=new OutputParams(configuration);
    ffaudioparams.maxBufferSize=1;
    ffaudioparams.stdin=params.stdin;
    ProcessWrapperImpl ffAudio=new ProcessWrapperImpl(ffmpegLPCMextract,ffaudioparams);
    params.stdin=null;
    PrintWriter pwMux=new PrintWriter(f);
    pwMux.println("String_Node_Str");
    String videoType="String_Node_Str";
    if (params.no_videoencode && params.forceType != null) {
      videoType=params.forceType;
    }
    String fps="String_Node_Str";
    if (params.forceFps != null) {
      fps="String_Node_Str" + params.forceFps + "String_Node_Str";
    }
    String audioType="String_Node_Str";
    if (dtsRemux) {
      if (params.mediaRenderer.isMuxDTSToMpeg()) {
        audioType="String_Node_Str";
      }
 else {
        audioType="String_Node_Str";
      }
    }
    pwMux.println(videoType + "String_Node_Str" + ffVideoPipe.getOutputPipe()+ "String_Node_Str"+ fps+ "String_Node_Str");
    pwMux.println(audioType + "String_Node_Str" + ffAudioPipe.getOutputPipe()+ "String_Node_Str");
    pwMux.close();
    ProcessWrapper pipe_process=pipe.getPipeProcess();
    pw.attachProcess(pipe_process);
    pipe_process.runInNewThread();
    try {
      Thread.sleep(50);
    }
 catch (    InterruptedException e) {
    }
    pipe.deleteLater();
    params.input_pipes[0]=pipe;
    ProcessWrapper ff_pipe_process=ffAudioPipe.getPipeProcess();
    pw.attachProcess(ff_pipe_process);
    ff_pipe_process.runInNewThread();
    try {
      Thread.sleep(50);
    }
 catch (    InterruptedException e) {
    }
    ffAudioPipe.deleteLater();
    pw.attachProcess(ffAudio);
    ffAudio.runInNewThread();
  }
  pw.runInNewThread();
  return pw;
}

Fixed version (ground truth):
@Override public ProcessWrapper launchTranscode(String fileName,DLNAResource dlna,DLNAMediaInfo media,OutputParams params) throws IOException {
  int nThreads=configuration.getNumberOfCpuCores();
  List<String> cmdList=new ArrayList<String>();
  RendererConfiguration renderer=params.mediaRenderer;
  setAudioAndSubs(fileName,media,params,configuration);
  boolean avisynth=avisynth();
  cmdList.add(executable());
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  if (params.timeseek > 0) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + params.timeseek);
  }
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str" + nThreads);
  final boolean isTsMuxeRVideoEngineEnabled=configuration.getEnginesAsList(PMS.get().getRegistry()).contains(TsMuxeRVideo.ID);
  ac3Remux=false;
  dtsRemux=false;
  if (configuration.isRemuxAC3() && params.aid != null && params.aid.isAC3() && !avisynth() && params.mediaRenderer.isTranscodeToAC3()) {
    ac3Remux=true;
  }
 else {
    dtsRemux=isTsMuxeRVideoEngineEnabled && configuration.isDTSEmbedInPCM() && params.aid != null && params.aid.isDTS() && !avisynth() && params.mediaRenderer.isDTSPlayable();
  }
  String frameRateRatio=null;
  String frameRateNumber=null;
  if (media != null) {
    frameRateRatio=media.getValidFps(true);
    frameRateNumber=media.getValidFps(false);
  }
  cmdList.add("String_Node_Str");
  if (avisynth && !fileName.toLowerCase().endsWith("String_Node_Str")) {
    File avsFile=AviSynthFFmpeg.getAVSScript(fileName,params.sid,params.fromFrame,params.toFrame,frameRateRatio,frameRateNumber);
    cmdList.add(ProcessUtil.getShortFileNameIfWideChars(avsFile.getAbsolutePath()));
  }
 else {
    cmdList.add(fileName);
  }
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str");
  if (media.getAudioTracksList().size() == 1) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str");
  }
 else   if (media.getAudioTracksList().size() > 1) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + (params.aid.getId() + 1));
  }
  cmdList.add("String_Node_Str");
  cmdList.add("String_Node_Str" + nThreads);
  if (params.timeend > 0) {
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + params.timeend);
  }
  cmdList.addAll(getRescaleOptions(renderer,media));
  int defaultMaxBitrates[]=getVideoBitrateConfig(configuration.getMaximumBitrate());
  int rendererMaxBitrates[]=new int[2];
  if (renderer.getMaxVideoBitrate() != null) {
    rendererMaxBitrates=getVideoBitrateConfig(renderer.getMaxVideoBitrate());
  }
  if ((defaultMaxBitrates[0] == 0 && rendererMaxBitrates[0] > 0) || rendererMaxBitrates[0] < defaultMaxBitrates[0] && rendererMaxBitrates[0] > 0) {
    defaultMaxBitrates=rendererMaxBitrates;
  }
  if (params.mediaRenderer.getCBRVideoBitrate() == 0 && defaultMaxBitrates[0] > 0) {
    defaultMaxBitrates[0]=1000 * defaultMaxBitrates[0];
    defaultMaxBitrates[0]=defaultMaxBitrates[0] / 2;
    int bufSize=1835;
    if (media.isHDVideo()) {
      bufSize=defaultMaxBitrates[0] / 3;
    }
    if (bufSize > 7000) {
      bufSize=7000;
    }
    if (defaultMaxBitrates[1] > 0) {
      bufSize=defaultMaxBitrates[1];
    }
    if (params.mediaRenderer.isDefaultVBVSize() && rendererMaxBitrates[1] == 0) {
      bufSize=1835;
    }
    defaultMaxBitrates[0]=defaultMaxBitrates[0] - configuration.getAudioBitrate();
    defaultMaxBitrates[0]=defaultMaxBitrates[0] / 1000 * 1000;
    bufSize=bufSize * 1000;
    defaultMaxBitrates[0]=defaultMaxBitrates[0] * 1000;
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + bufSize);
    cmdList.add("String_Node_Str");
    cmdList.add("String_Node_Str" + defaultMaxBitrates[0]);
  }
  int channels;
  if (ac3Remux) {
    channels=params.aid.getAudioProperties().getNumberOfChannels();
  }
 else   if (dtsRemux) {
    channels=2;
  }
 else {
    channels=configuration.getAudioChannelCount();
  }
  LOGGER.trace("String_Node_Str" + channels);
  if (!(params.aid.isAC3() && !ac3Remux) && !(type() == Format.AUDIO)) {
    cmdList.add("String_Node_Str");
    cmdList.add(configuration.getAudioBitrate() + "String_Node_Str");
  }
  cmdList.addAll(getCustomArgs());
  cmdList.addAll(getTranscodeVideoOptions(renderer,media,params));
  if (!dtsRemux) {
    cmdList.add("String_Node_Str");
  }
  String[] cmdArray=new String[cmdList.size()];
  cmdList.toArray(cmdArray);
  cmdArray=finalizeTranscoderArgs(fileName,dlna,media,params,cmdArray);
  ProcessWrapperImpl pw=new ProcessWrapperImpl(cmdArray,params);
  if (dtsRemux) {
    PipeProcess pipe;
    pipe=new PipeProcess(System.currentTimeMillis() + "String_Node_Str");
    TsMuxeRVideo ts=new TsMuxeRVideo(configuration);
    File f=new File(configuration.getTempFolder(),"String_Node_Str");
    String cmd[]=new String[]{ts.executable(),f.getAbsolutePath(),pipe.getInputPipe()};
    pw=new ProcessWrapperImpl(cmd,params);
    PipeIPCProcess ffVideoPipe=new PipeIPCProcess(System.currentTimeMillis() + "String_Node_Str",System.currentTimeMillis() + "String_Node_Str",false,true);
    cmdList.add(ffVideoPipe.getInputPipe());
    OutputParams ffparams=new OutputParams(configuration);
    ffparams.maxBufferSize=1;
    ffparams.stdin=params.stdin;
    String[] cmdArrayDts=new String[cmdList.size()];
    cmdList.toArray(cmdArrayDts);
    cmdArrayDts=finalizeTranscoderArgs(fileName,dlna,media,params,cmdArrayDts);
    ProcessWrapperImpl ffVideo=new ProcessWrapperImpl(cmdArrayDts,ffparams);
    ProcessWrapper ff_video_pipe_process=ffVideoPipe.getPipeProcess();
    pw.attachProcess(ff_video_pipe_process);
    ff_video_pipe_process.runInNewThread();
    ffVideoPipe.deleteLater();
    pw.attachProcess(ffVideo);
    ffVideo.runInNewThread();
    PipeIPCProcess ffAudioPipe=new PipeIPCProcess(System.currentTimeMillis() + "String_Node_Str",System.currentTimeMillis() + "String_Node_Str",false,true);
    StreamModifier sm=new StreamModifier();
    sm.setPcm(false);
    sm.setDtsEmbed(dtsRemux);
    sm.setSampleFrequency(48000);
    sm.setBitsPerSample(16);
    sm.setNbChannels(channels);
    String ffmpegLPCMextract[]=new String[]{executable(),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",fileName,"String_Node_Str","String_Node_Str" + channels,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",ffAudioPipe.getInputPipe()};
    if (!params.mediaRenderer.isMuxDTSToMpeg()) {
      ffAudioPipe.setModifier(sm);
    }
    if (params.stdin != null) {
      ffmpegLPCMextract[4]="String_Node_Str";
    }
    if (params.timeseek > 0) {
      ffmpegLPCMextract[3]="String_Node_Str" + params.timeseek;
    }
    OutputParams ffaudioparams=new OutputParams(configuration);
    ffaudioparams.maxBufferSize=1;
    ffaudioparams.stdin=params.stdin;
    ProcessWrapperImpl ffAudio=new ProcessWrapperImpl(ffmpegLPCMextract,ffaudioparams);
    params.stdin=null;
    PrintWriter pwMux=new PrintWriter(f);
    pwMux.println("String_Node_Str");
    String videoType="String_Node_Str";
    if (params.no_videoencode && params.forceType != null) {
      videoType=params.forceType;
    }
    String fps="String_Node_Str";
    if (params.forceFps != null) {
      fps="String_Node_Str" + params.forceFps + "String_Node_Str";
    }
    String audioType="String_Node_Str";
    if (dtsRemux) {
      if (params.mediaRenderer.isMuxDTSToMpeg()) {
        audioType="String_Node_Str";
      }
 else {
        audioType="String_Node_Str";
      }
    }
    pwMux.println(videoType + "String_Node_Str" + ffVideoPipe.getOutputPipe()+ "String_Node_Str"+ fps+ "String_Node_Str");
    pwMux.println(audioType + "String_Node_Str" + ffAudioPipe.getOutputPipe()+ "String_Node_Str");
    pwMux.close();
    ProcessWrapper pipe_process=pipe.getPipeProcess();
    pw.attachProcess(pipe_process);
    pipe_process.runInNewThread();
    try {
      Thread.sleep(50);
    }
 catch (    InterruptedException e) {
    }
    pipe.deleteLater();
    params.input_pipes[0]=pipe;
    ProcessWrapper ff_pipe_process=ffAudioPipe.getPipeProcess();
    pw.attachProcess(ff_pipe_process);
    ff_pipe_process.runInNewThread();
    try {
      Thread.sleep(50);
    }
 catch (    InterruptedException e) {
    }
    ffAudioPipe.deleteLater();
    pw.attachProcess(ffAudio);
    ffAudio.runInNewThread();
  }
  pw.runInNewThread();
  return pw;
}