Package net.pms.io

Examples of net.pms.io.ProcessWrapperImpl


    String cmdArray[] = new String[4];
    cmdArray[0] = PMS.getConfiguration().getDCRawPath();
    cmdArray[1] = "-e";
    cmdArray[2] = "-c";
    cmdArray[3] = fileName;
    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.runInSameThread();

    InputStream is = pw.getInputStream(0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int n = -1;
    byte buffer[] = new byte[4096];
    while ((n = is.read(buffer)) > -1) {
      baos.write(buffer, 0, n);
View Full Code Here


      media,
      params,
      cmdArray
    );

    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.runInNewThread();

    return pw;
  }
View Full Code Here

      // let's get that speed
      OutputParams op = new OutputParams(null);
      op.log = true;
      op.maxBufferSize = 1;
      SystemUtils sysUtil = PMS.get().getRegistry();
      final ProcessWrapperImpl pw = new ProcessWrapperImpl(sysUtil.getPingCommand(addr.getHostAddress(), 3, 64000), op,
          true, false);
      Runnable r = new Runnable() {
        public void run() {
          try {
            Thread.sleep(2000);
          } catch (InterruptedException e) {
          }
          pw.stopProcess();
        }
      };

      Thread failsafe = new Thread(r, "SpeedStats Failsafe");
      failsafe.start();
      pw.runInSameThread();
      List<String> ls = pw.getOtherResults();
      int time = 0;
      int c = 0;

      for (String line : ls) {
        int msPos = line.indexOf("ms");
View Full Code Here

      cmdList.add("8192");
    }

    PipeProcess pipe = null;

    ProcessWrapperImpl pw = null;

    if (pcm || dtsRemux) {
      // transcode video, demux audio, remux with tsmuxer
      boolean channels_filter_present = false;

      for (String s : cmdList) {
        if (isNotBlank(s) && s.startsWith("channels")) {
          channels_filter_present = true;
          break;
        }
      }

      if (params.avidemux) {
        pipe = new PipeProcess("mencoder" + System.currentTimeMillis(), (pcm || dtsRemux || ac3Remux) ? null : params);
        params.input_pipes[0] = pipe;

        cmdList.add("-o");
        cmdList.add(pipe.getInputPipe());

        if (pcm && !channels_filter_present && params.aid != null) {
          String mixer = getLPCMChannelMappingForMencoder(params.aid);
          if (isNotBlank(mixer)) {
            cmdList.add("-af");
            cmdList.add(mixer);
          }
        }

        String[] cmdArray = new String[cmdList.size()];
        cmdList.toArray(cmdArray);
        pw = new ProcessWrapperImpl(cmdArray, params);

        PipeProcess videoPipe = new PipeProcess("videoPipe" + System.currentTimeMillis(), "out", "reconnect");
        PipeProcess audioPipe = new PipeProcess("audioPipe" + System.currentTimeMillis(), "out", "reconnect");

        ProcessWrapper videoPipeProcess = videoPipe.getPipeProcess();
        ProcessWrapper audioPipeProcess = audioPipe.getPipeProcess();

        params.output_pipes[0] = videoPipe;
        params.output_pipes[1] = audioPipe;

        pw.attachProcess(videoPipeProcess);
        pw.attachProcess(audioPipeProcess);
        videoPipeProcess.runInNewThread();
        audioPipeProcess.runInNewThread();
        try {
          Thread.sleep(50);
        } catch (InterruptedException e) { }
        videoPipe.deleteLater();
        audioPipe.deleteLater();
      } else {
        // remove the -oac switch, otherwise the "too many video packets" errors appear again
        for (ListIterator<String> it = cmdList.listIterator(); it.hasNext();) {
          String option = it.next();

          if (option.equals("-oac")) {
            it.set("-nosound");

            if (it.hasNext()) {
              it.next();
              it.remove();
            }

            break;
          }
        }

        pipe = new PipeProcess(System.currentTimeMillis() + "tsmuxerout.ts");

        TsMuxeRVideo ts = new TsMuxeRVideo(configuration);
        File f = new File(configuration.getTempFolder(), "pms-tsmuxer.meta");
        String cmd[] = new String[]{ ts.executable(), f.getAbsolutePath(), pipe.getInputPipe() };
        pw = new ProcessWrapperImpl(cmd, params);

        PipeIPCProcess ffVideoPipe = new PipeIPCProcess(System.currentTimeMillis() + "ffmpegvideo", System.currentTimeMillis() + "videoout", false, true);

        cmdList.add("-o");
        cmdList.add(ffVideoPipe.getInputPipe());

        OutputParams ffparams = new OutputParams(configuration);
        ffparams.maxBufferSize = 1;
        ffparams.stdin = params.stdin;

        String[] cmdArray = new String[cmdList.size()];
        cmdList.toArray(cmdArray);
        ProcessWrapperImpl ffVideo = new ProcessWrapperImpl(cmdArray, 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();

        String aid = null;
        if (media != null && media.getAudioTracksList().size() > 1 && params.aid != null) {
          if (media.getContainer() != null && (media.getContainer().equals(FormatConfiguration.AVI) || media.getContainer().equals(FormatConfiguration.FLV))) {
            // TODO confirm (MP4s, OGMs and MOVs already tested: first aid is 0; AVIs: first aid is 1)
            // for AVIs, FLVs and MOVs mencoder starts audio tracks numbering from 1
            aid = "" + (params.aid.getId() + 1);
          } else {
            // everything else from 0
            aid = "" + params.aid.getId();
          }
        }

        PipeIPCProcess ffAudioPipe = new PipeIPCProcess(System.currentTimeMillis() + "ffmpegaudio01", System.currentTimeMillis() + "audioout", false, true);
        StreamModifier sm = new StreamModifier();
        sm.setPcm(pcm);
        sm.setDtsEmbed(dtsRemux);
        sm.setSampleFrequency(48000);
        sm.setBitsPerSample(16);

        String mixer = null;
        if (pcm && !dtsRemux) {
          mixer = getLPCMChannelMappingForMencoder(params.aid); // LPCM always outputs 5.1/7.1 for multichannel tracks. Downmix with player if needed!
        }

        sm.setNbChannels(channels);

        // it seems the -really-quiet prevents mencoder to stop the pipe output after some time...
        // -mc 0.1 make the DTS-HD extraction works better with latest mencoder builds, and makes no impact on the regular DTS one
        String ffmpegLPCMextract[] = new String[]{
          executable(),
          "-ss", "0",
          filename,
          "-really-quiet",
          "-msglevel", "statusline=2",
          "-channels", "" + channels,
          "-ovc", "copy",
          "-of", "rawaudio",
          "-mc", dtsRemux ? "0.1" : "0",
          "-noskip",
          (aid == null) ? "-quiet" : "-aid", (aid == null) ? "-quiet" : aid,
          "-oac", (ac3Remux || dtsRemux) ? "copy" : "pcm",
          (isNotBlank(mixer) && !channels_filter_present) ? "-af" : "-quiet", (isNotBlank(mixer) && !channels_filter_present) ? mixer : "-quiet",
          "-srate", "48000",
          "-o", ffAudioPipe.getInputPipe()
        };

        if (!params.mediaRenderer.isMuxDTSToMpeg()) { // no need to use the PCM trick when media renderer supports DTS
          ffAudioPipe.setModifier(sm);
        }

        if (media != null && media.getDvdtrack() > 0) {
          ffmpegLPCMextract[3] = "-dvd-device";
          ffmpegLPCMextract[4] = filename;
          ffmpegLPCMextract[5] = "dvd://" + media.getDvdtrack();
        } else if (params.stdin != null) {
          ffmpegLPCMextract[3] = "-";
        }

        if (filename.toLowerCase().endsWith(".evo")) {
          ffmpegLPCMextract[4] = "-psprobe";
          ffmpegLPCMextract[5] = "1000000";
        }

        if (params.timeseek > 0) {
          ffmpegLPCMextract[2] = "" + 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("MUXOPT --no-pcr-on-video-pid --no-asyncio --new-audio-pes --vbr --vbv-len=500");
        String videoType = "V_MPEG-2";

        if (params.no_videoencode && params.forceType != null) {
          videoType = params.forceType;
        }

        String fps = "";
        if (params.forceFps != null) {
          fps = "fps=" + params.forceFps + ", ";
        }

        String audioType;
        if (ac3Remux) {
          audioType = "A_AC3";
        } else if (dtsRemux) {
          if (params.mediaRenderer.isMuxDTSToMpeg()) {
            //renderer can play proper DTS track
            audioType = "A_DTS";
          } else {
            // DTS padded in LPCM trick
            audioType = "A_LPCM";
          }
        } else {
          // PCM
          audioType = "A_LPCM";
        }


        // mencoder bug (confirmed with mencoder r35003 + ffmpeg 0.11.1):
        // audio delay is ignored when playing from file start (-ss 0)
        // override with tsmuxer.meta setting
        String timeshift = "";
        if (mencoderAC3RemuxAudioDelayBug) {
          timeshift = "timeshift=" + params.aid.getAudioProperties().getAudioDelay() + "ms, ";
        }

        pwMux.println(videoType + ", \"" + ffVideoPipe.getOutputPipe() + "\", " + fps + "level=4.1, insertSEI, contSPS, track=1");
        pwMux.println(audioType + ", \"" + ffAudioPipe.getOutputPipe() + "\", " + timeshift + "track=2");
        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();
      }
    } else {
      boolean directpipe = Platform.isMac() || Platform.isFreeBSD();

      if (directpipe) {
        cmdList.add("-o");
        cmdList.add("-");
        cmdList.add("-really-quiet");
        cmdList.add("-msglevel");
        cmdList.add("statusline=2");
        params.input_pipes = new PipeProcess[2];
      } else {
        pipe = new PipeProcess("mencoder" + System.currentTimeMillis(), (pcm || dtsRemux) ? null : params);
        params.input_pipes[0] = pipe;
        cmdList.add("-o");
        cmdList.add(pipe.getInputPipe());
      }

      String[] cmdArray = new String[ cmdList.size() ];
      cmdList.toArray(cmdArray);

      cmdArray = finalizeTranscoderArgs(
        filename,
        dlna,
        media,
        params,
        cmdArray
      );

      pw = new ProcessWrapperImpl(cmdArray, params);

      if (!directpipe) {
        ProcessWrapper mkfifo_process = pipe.getPipeProcess();
        pw.attachProcess(mkfifo_process);
View Full Code Here

      media,
      params,
      cmdArray
    );

    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.runInNewThread();

    return pw;
  }
View Full Code Here

      dlna,
      media,
      params,
      cmdArray);

    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.attachProcess(pipe_process);

    try {
      Thread.sleep(150);
    } catch (InterruptedException e) { }

    pw.runInNewThread();
    return pw;
  }
View Full Code Here

      params,
      cmdArray
    );

    // Now launch FFmpeg
    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.attachProcess(mkfifo_process); // Clean up the mkfifo process when the transcode ends

    // Give the mkfifo process a little time
    try {
      Thread.sleep(300);
    } catch (InterruptedException e) {
      logger.error("Thread interrupted while waiting for named pipe to be created", e);
    }

    // Launch the transcode command...
    pw.runInNewThread();
    // ...and wait briefly to allow it to start
    try {
      Thread.sleep(200);
    } catch (InterruptedException e) {
      logger.error("Thread interrupted while waiting for transcode to start", e);
View Full Code Here

    // Pass to process wrapper
    String[] cmdArray = new String[cmdList.size()];
    cmdList.toArray(cmdArray);
    cmdArray = finalizeTranscoderArgs(filename, dlna, media, params, cmdArray);
    logger.trace("Finalized args: " + StringUtils.join(cmdArray, " "));
    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
    pw.attachProcess(pipe_process);

    // TODO: Why is this here?
    try {
      Thread.sleep(150);
    } catch (InterruptedException e) {
    }

    pw.runInNewThread();
    return pw;
  }
View Full Code Here

      if (file.getFile() != null) {
        cmdArray[3] = file.getFile().getAbsolutePath();
      }

      params.log = true;
      ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params, true, false);
      pw.runInSameThread();

      List<String> list = pw.getOtherResults();
      for (String s : list) {
        if (s.startsWith("Thumb size:  ")) {
          String sz = s.substring(13);
          media.setWidth(Integer.parseInt(sz.substring(0, sz.indexOf("x")).trim()));
          media.setHeight(Integer.parseInt(sz.substring(sz.indexOf("x") + 1).trim()));
View Full Code Here

      "dvd://1"
    };
    OutputParams params = new OutputParams(configuration);
    params.maxBufferSize = 1;
    params.log = true;
    final ProcessWrapperImpl pw = new ProcessWrapperImpl(cmd, params, true, false);

    Runnable r = new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(10000);
        } catch (InterruptedException e) { }
        pw.stopProcess();
      }
    };

    Thread failsafe = new Thread(r, "DVDISO Failsafe");
    failsafe.start();
    pw.runInSameThread();
    List<String> lines = pw.getOtherResults();

    if (lines != null) {
      for (String line : lines) {
        if (line.startsWith("ID_DVD_TITLE_") && line.contains("_LENGTH")) {
          int rank = Integer.parseInt(line.substring(13, line.indexOf("_LENGT")));
View Full Code Here

TOP

Related Classes of net.pms.io.ProcessWrapperImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.