Package net.pms.io

Examples of net.pms.io.PipeProcess


          pw.println(type + ", \"" + ffAudioPipe[i].getOutputPipe() + "\", " + timeshift + "track=" + (2 + i));
        }
      }
    }

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

    /**
     * Use the newer version of tsMuxeR on PS3 since other renderers
     * like Panasonic TVs don't always recognize the new output
     */
    String executable = executable();
    if (params.mediaRenderer.isPS3()) {
      executable = configuration.getTsmuxerNewPath();
    }

    String[] cmdArray = new String[]{
      executable,
      f.getAbsolutePath(),
      tsPipe.getInputPipe()
    };

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

    ProcessWrapperImpl p = new ProcessWrapperImpl(cmdArray, params);
    params.maxBufferSize = 100;
    params.input_pipes[0] = tsPipe;
    params.stdin = null;
    ProcessWrapper pipe_process = tsPipe.getPipeProcess();
    p.attachProcess(pipe_process);
    pipe_process.runInNewThread();

    try {
      Thread.sleep(50);
    } catch (InterruptedException e) {
    }
    tsPipe.deleteLater();

    ProcessWrapper ff_pipe_process = ffVideoPipe.getPipeProcess();
    p.attachProcess(ff_pipe_process);
    ff_pipe_process.runInNewThread();
    try {
View Full Code Here


    DLNAResource dlna,
    DLNAMediaInfo media,
    OutputParams params) throws IOException {
    boolean isWindows = Platform.isWindows();
    final String filename = dlna.getSystemName();
    PipeProcess tsPipe = new PipeProcess("VLC" + System.currentTimeMillis() + "." + getMux());
    ProcessWrapper pipe_process = tsPipe.getPipeProcess();

    // XXX it can take a long time for Windows to create a named pipe
    // (and mkfifo can be slow if /tmp isn't memory-mapped), so start this as early as possible
    pipe_process.runInNewThread();
    tsPipe.deleteLater();

    params.input_pipes[0] = tsPipe;
    params.minBufferSize = params.minFileSize;
    params.secondread_minsize = 100000;

    List<String> cmdList = new ArrayList<>();
    cmdList.add(executable());
    cmdList.add("-I");
    cmdList.add("dummy");

    // TODO: either
    // 1) add this automatically if enabled (probe)
    // 2) add a GUI option to "enable GPU acceleration"
    // 3) document it as an option the user can enable themselves in the vlc GUI (saved to a config file used by cvlc)
    // XXX: it's still experimental (i.e. unstable), causing (consistent) segfaults on Windows and Linux,
    // so don't even document it for now
    // cmdList.add("--ffmpeg-hw");

    String transcodeSpec = String.format(
      "#transcode{%s}:standard{access=file,mux=%s,dst=\"%s%s\"}",
      getEncodingArgs(),
      getMux(),
      (isWindows ? "\\\\" : ""),
      tsPipe.getInputPipe()
    );

    // XXX there's precious little documentation on how (if at all) VLC
    // treats colons and hyphens (and :name= and --name=) differently
    // so we just have to test it ourselves
View Full Code Here

      Thread.currentThread().getId(),
      System.currentTimeMillis()
    );

    // This process wraps the command that creates the named pipe
    PipeProcess pipe = new PipeProcess(fifoName);
    pipe.deleteLater(); // delete the named pipe later; harmless if it isn't created
    ProcessWrapper mkfifo_process = pipe.getPipeProcess();

    /**
     * It can take a long time for Windows to create a named pipe (and
     * mkfifo can be slow if /tmp isn't memory-mapped), so run this in
     * the current thread.
     */
    mkfifo_process.runInSameThread();

    params.input_pipes[0] = pipe;

    // Build the command line
    List<String> cmdList = new ArrayList<>();
    if (!dlna.isURLResolved()) {
      URLResult r1 = ExternalFactory.resolveURL(filename);
      if (r1 != null) {
        if (r1.precoder != null) {
          filename = "-";
          if (Platform.isWindows()) {
            cmdList.add("cmd.exe");
            cmdList.add("/C");
          }
          cmdList.addAll(r1.precoder);
          cmdList.add("|");
        } else {
          if (StringUtils.isNotEmpty(r1.url)) {
            filename = r1.url;
          }
        }
        if (r1.args != null && r1.args.size() > 0) {
          customOptions.addAll(r1.args);
        }
      }
    }

    cmdList.add(executable());

    // XXX squashed bug - without this, ffmpeg hangs waiting for a confirmation
    // that it can write to a file that already exists i.e. the named pipe
    cmdList.add("-y");

    cmdList.add("-loglevel");
   
    if (LOGGER.isTraceEnabled()) { // Set -loglevel in accordance with LOGGER setting
      cmdList.add("info"); // Could be changed to "verbose" or "debug" if "info" level is not enough
    } else {
      cmdList.add("warning");
    }

    /*
     * FFmpeg uses multithreading by default, so provided that the
     * user has not disabled FFmpeg multithreading and has not
     * chosen to use more or less threads than are available, do not
     * specify how many cores to use.
     */
    int nThreads = 1;
    if (configuration.isFfmpegMultithreading()) {
      if (Runtime.getRuntime().availableProcessors() == configuration.getNumberOfCpuCores()) {
        nThreads = 0;
      } else {
        nThreads = configuration.getNumberOfCpuCores();
      }
    }

    // Decoder threads
    if (nThreads > 0) {
      cmdList.add("-threads");
      cmdList.add("" + nThreads);
    }

    // Add global and input-file custom options, if any
    if (!customOptions.isEmpty()) {
      customOptions.transferGlobals(cmdList);
      customOptions.transferInputFileOptions(cmdList);
    }

    if (params.timeseek > 0) {
      cmdList.add("-ss");
      cmdList.add("" + (int) params.timeseek);
    }

    cmdList.add("-i");
    cmdList.add(filename);

    cmdList.addAll(getVideoFilterOptions(dlna, media, params));

    // Encoder threads
    if (nThreads > 0) {
      cmdList.add("-threads");
      cmdList.add("" + nThreads);
    }

    // Add the output options (-f, -c:a, -c:v, etc.)
    cmdList.addAll(getVideoTranscodeOptions(dlna, media, params));

    // Add video bitrate options
    cmdList.addAll(getVideoBitrateOptions(dlna, media, params));

    // Add audio bitrate options
    cmdList.addAll(getAudioBitrateOptions(dlna, media, params));

    // Add any remaining custom options
    if (!customOptions.isEmpty()) {
      customOptions.transferAll(cmdList);
    }

    // Output file
    cmdList.add(pipe.getInputPipe());

    // Convert the command list to an array
    String[] cmdArray = new String[cmdList.size()];
    cmdList.toArray(cmdArray);

View Full Code Here

    setAudioAndSubs(filename, media, params);

    // Make sure we can play this
    CodecConfig config = genConfig(params.mediaRenderer);

    PipeProcess tsPipe = new PipeProcess("VLC" + System.currentTimeMillis() + "." + config.container);
    ProcessWrapper pipe_process = tsPipe.getPipeProcess();

    // XXX it can take a long time for Windows to create a named pipe
    // (and mkfifo can be slow if /tmp isn't memory-mapped), so start this as early as possible
    pipe_process.runInNewThread();
    tsPipe.deleteLater();

    params.input_pipes[0] = tsPipe;
    params.minBufferSize = params.minFileSize;
    params.secondread_minsize = 100000;

    List<String> cmdList = new ArrayList<>();
    cmdList.add(executable());
    cmdList.add("-I");
    cmdList.add("dummy");

    // Disable hardware acceleration which is enabled by default,
    // but for hardware acceleration, user must enable it in "VLC Preferences",
    // until they release documentation for new functionalities introduced in 2.1.4+
    if (!configuration.isGPUAcceleration()) {
      cmdList.add("--avcodec-hw=disabled");
    }

    // Useful for the more esoteric codecs people use
    if (experimentalCodecs.isSelected()) {
      cmdList.add("--sout-avcodec-strict=-2");
    }

    // Stop the DOS box from appearing on windows
    if (isWindows) {
      cmdList.add("--dummy-quiet");
    }

    // File needs to be given before sout, otherwise vlc complains
    cmdList.add(filename);

    String disableSuffix = "track=-1";

    // Handle audio language
    if (params.aid != null) {
      // User specified language at the client, acknowledge it
      if (params.aid.getLang() == null || params.aid.getLang().equals("und")) {
        // VLC doesn't understand "und", so try to get audio track by ID
        cmdList.add("--audio-track=" + params.aid.getId());
      } else {
        cmdList.add("--audio-language=" + params.aid.getLang());
      }
    } else {
      // Not specified, use language from GUI
      // FIXME: VLC does not understand "loc" or "und".
      cmdList.add("--audio-language=" + configuration.getAudioLanguages());
    }

    // Handle subtitle language
    if (params.sid != null) { // User specified language at the client, acknowledge it
      if (params.sid.isExternal()) {
        String externalSubtitlesFileName;

        // External subtitle file
        if (params.sid.isExternalFileUtf16()) {
          try {
            // Convert UTF-16 -> UTF-8
            File convertedSubtitles = new File(configuration.getTempFolder(), "utf8_" + params.sid.getExternalFile().getName());
            FileUtil.convertFileFromUtf16ToUtf8(params.sid.getExternalFile(), convertedSubtitles);
            externalSubtitlesFileName = ProcessUtil.getShortFileNameIfWideChars(convertedSubtitles.getAbsolutePath());
          } catch (IOException e) {
            LOGGER.debug("Error converting file from UTF-16 to UTF-8", e);
            externalSubtitlesFileName = ProcessUtil.getShortFileNameIfWideChars(params.sid.getExternalFile().getAbsolutePath());
          }
        } else {
          externalSubtitlesFileName = ProcessUtil.getShortFileNameIfWideChars(params.sid.getExternalFile().getAbsolutePath());
        }

        if (externalSubtitlesFileName != null) {
          cmdList.add("--sub-file");
          cmdList.add(externalSubtitlesFileName);
        }
      } else if (params.sid.getLang() != null && !params.sid.getLang().equals("und")) { // Load by ID (better)
        cmdList.add("--sub-track=" + params.sid.getId());
      } else { // VLC doesn't understand "und", but does understand a nonexistent track
        cmdList.add("--sub-" + disableSuffix);
      }
    } else {
      cmdList.add("--sub-" + disableSuffix);
    }

    // x264 options
    if (videoRemux) {
      cmdList.add("--sout-x264-preset");
      cmdList.add("superfast");

      cmdList.add("--no-sout-avcodec-hurry-up");

      cmdList.addAll(getVideoBitrateOptions(dlna, media, params));
    }

    // Skip forward if necessary
    if (params.timeseek != 0) {
      cmdList.add("--start-time");
      cmdList.add(String.valueOf(params.timeseek));
    }

    // Generate encoding args
    String separator = "";
    StringBuilder encodingArgsBuilder = new StringBuilder();
    for (Map.Entry<String, Object> curEntry : getEncodingArgs(config, params).entrySet()) {
      encodingArgsBuilder.append(separator);
      encodingArgsBuilder.append(curEntry.getKey());

      if (curEntry.getValue() != null) {
        encodingArgsBuilder.append("=");
        encodingArgsBuilder.append(curEntry.getValue());
      }

      separator = ",";
    }

    // Add our transcode options
    String transcodeSpec = String.format(
      "#transcode{%s}:standard{access=file,mux=%s,dst='%s%s'}",
      encodingArgsBuilder.toString(),
      config.container,
      (isWindows ? "\\\\" : ""),
      tsPipe.getInputPipe()
    );
    cmdList.add("--sout");
    cmdList.add(transcodeSpec);

    // Force VLC to exit when finished
View Full Code Here

    ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);

    setOutputParsing(dlna, pw, false);

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

      TsMuxeRVideo ts = new TsMuxeRVideo();
      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(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() + "ffmpegaudio01", System.currentTimeMillis() + "audioout", false, true);
      StreamModifier sm = new StreamModifier();
      sm.setPcm(false);
      sm.setDtsEmbed(dtsRemux);
      sm.setSampleFrequency(48000);
      sm.setBitsPerSample(16);
      sm.setNbChannels(2);

      List<String> cmdListDTS = new ArrayList<>();
      cmdListDTS.add(executable());
      cmdListDTS.add("-y");
      cmdListDTS.add("-ss");

      if (params.timeseek > 0) {
        cmdListDTS.add(String.valueOf(params.timeseek));
      } else {
        cmdListDTS.add("0");
      }

      if (params.stdin == null) {
        cmdListDTS.add("-i");
      } else {
        cmdListDTS.add("-");
      }
      cmdListDTS.add(filename);

      if (params.timeseek > 0) {
        cmdListDTS.add("-copypriorss");
        cmdListDTS.add("0");
        cmdListDTS.add("-avoid_negative_ts");
        cmdListDTS.add("1");
      }

      cmdListDTS.add("-ac");
      cmdListDTS.add("2");

      cmdListDTS.add("-f");
      cmdListDTS.add("dts");

      cmdListDTS.add("-c:a");
      cmdListDTS.add("copy");

      cmdListDTS.add(ffAudioPipe.getInputPipe());

      String[] cmdArrayDTS = new String[cmdListDTS.size()];
      cmdListDTS.toArray(cmdArrayDTS);

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

      OutputParams ffaudioparams = new OutputParams(configuration);
      ffaudioparams.maxBufferSize = 1;
      ffaudioparams.stdin = params.stdin;
      ProcessWrapperImpl ffAudio = new ProcessWrapperImpl(cmdArrayDTS, ffaudioparams);

      params.stdin = null;
      try (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 (renderer.isTranscodeToH264()) {
          videoType = "V_MPEG4/ISO/AVC";
        }

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

        StringBuilder fps = new StringBuilder();
        fps.append("");
        if (params.forceFps != null) {
          fps.append("fps=").append(params.forceFps).append(", ");
        }

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

        pwMux.println(videoType + ", \"" + ffVideoPipe.getOutputPipe() + "\", " + fps + "level=4.1, insertSEI, contSPS, track=1");
        pwMux.println(audioType + ", \"" + ffAudioPipe.getOutputPipe() + "\", track=2");
      }

      ProcessWrapper pipe_process = pipe.getPipeProcess();
      pw.attachProcess(pipe_process);
      pipe_process.runInNewThread();

      try {
        wait(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();
View Full Code Here

    DLNAMediaInfo media,
    OutputParams params) throws IOException {
    params.minBufferSize = params.minFileSize;
    params.secondread_minsize = 100000;

    PipeProcess pipe = new PipeProcess("mencoder" + System.currentTimeMillis());
    params.input_pipes[0] = pipe;

    String cmdArray[] = new String[args().length + 4];
    cmdArray[0] = executable();
    final String filename = dlna.getSystemName();
    cmdArray[1] = filename;
    System.arraycopy(args(), 0, cmdArray, 2, args().length);
    cmdArray[cmdArray.length - 2] = "-o";
    cmdArray[cmdArray.length - 1] = pipe.getInputPipe();

    ProcessWrapper mkfifo_process = pipe.getPipeProcess();

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

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

    /**
     * It can take a long time for Windows to create a named pipe (and
     * mkfifo can be slow if /tmp isn't memory-mapped), so run this in
     * the current thread.
     */
    mkfifo_process.runInSameThread();

    pipe.deleteLater();

    pw.runInNewThread();

    // Not sure what good this 50ms wait will do for the calling method.
    try {
View Full Code Here

    OutputParams params
  ) throws IOException {
    params.minBufferSize = params.minFileSize;
    params.secondread_minsize = 100000;

    PipeProcess pipe = new PipeProcess("mencoder" + System.currentTimeMillis());
    params.input_pipes[0] = pipe;

    String cmdArray[] = new String[args().length + 4];
    cmdArray[0] = executable();
    final String filename = dlna.getSystemName();
    cmdArray[1] = filename;

    for (int i = 0; i < args().length; i++) {
      cmdArray[i + 2] = args()[i];
    }

    cmdArray[cmdArray.length - 2] = "-o";
    cmdArray[cmdArray.length - 1] = pipe.getInputPipe();

    ProcessWrapper mkfifo_process = pipe.getPipeProcess();

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

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

    // It can take a long time for Windows to create a named pipe (and
    // mkfifo can be slow if /tmp isn't memory-mapped), so run this in the
    // current thread.
    mkfifo_process.runInSameThread();

    pipe.deleteLater();

    pw.runInNewThread();

    // Not sure what good this 50ms wait will do for the calling method.
    try {
View Full Code Here

    if (params.stdin != null) {
      cmdList.add("-cache");
      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());
      }
View Full Code Here

    DLNAMediaInfo media,
    OutputParams params
  ) throws IOException {
    boolean isWindows = Platform.isWindows();
    final String filename = dlna.getSystemName();
    PipeProcess tsPipe = new PipeProcess("VLC" + System.currentTimeMillis() + "." + getMux());
    ProcessWrapper pipe_process = tsPipe.getPipeProcess();

    // XXX it can take a long time for Windows to create a named pipe
    // (and mkfifo can be slow if /tmp isn't memory-mapped), so start this as early as possible
    pipe_process.runInNewThread();
    tsPipe.deleteLater();

    params.input_pipes[0] = tsPipe;
    params.minBufferSize = params.minFileSize;
    params.secondread_minsize = 100000;

    List<String> cmdList = new ArrayList<String>();
    cmdList.add(executable());
    cmdList.add("-I");
    cmdList.add("dummy");

    // TODO: either
    // 1) add this automatically if enabled (probe)
    // 2) add a GUI option to "enable GPU acceleration"
    // 3) document it as an option the user can enable themselves in the vlc GUI (saved to a config file used by cvlc)
    // XXX: it's still experimental (i.e. unstable), causing (consistent) segfaults on Windows and Linux,
    // so don't even document it for now
    // cmdList.add("--ffmpeg-hw");

    String transcodeSpec = String.format(
      "#transcode{%s}:standard{access=file,mux=%s,dst=\"%s%s\"}",
      getEncodingArgs(),
      getMux(),
      (isWindows ? "\\\\" : ""),
      tsPipe.getInputPipe()
    );

    // XXX there's precious little documentation on how (if at all) VLC
    // treats colons and hyphens (and :name= and --name=) differently
    // so we just have to test it ourselves
View Full Code Here

      Thread.currentThread().getId(),
      System.currentTimeMillis()
    );

    // This process wraps the command that creates the named pipe
    PipeProcess pipe = new PipeProcess(fifoName);
    pipe.deleteLater(); // delete the named pipe later; harmless if it isn't created
    ProcessWrapper mkfifo_process = pipe.getPipeProcess();

    // It can take a long time for Windows to create a named pipe (and
    // mkfifo can be slow if /tmp isn't memory-mapped), so run this in
    // the current thread.
    mkfifo_process.runInSameThread();

    params.input_pipes[0] = pipe;

    // Build the command line
    final List<String> cmdList = new ArrayList<String>();
    cmdList.add(executable());
    cmdList.addAll(getGlobalOptions(logger));

    int nThreads = configuration.getNumberOfCpuCores();

    // Decoder threads
    cmdList.add("-threads");
    cmdList.add("" + nThreads);

    // Add global and input-file custom options, if any
    if (!customOptions.isEmpty()) {
      customOptions.transferGlobals(cmdList);
      customOptions.transferInputFileOptions(cmdList);
    }

    cmdList.add("-i");
    cmdList.add(filename);

    cmdList.addAll(getVideoFilterOptions(dlna, media, params));

    // Encoder threads
    cmdList.add("-threads");
    cmdList.add("" + nThreads);

    // Add the output options (-f, -acodec, -vcodec)
    cmdList.addAll(getVideoTranscodeOptions(dlna, media, params));

    // Add video bitrate options
    cmdList.addAll(getVideoBitrateOptions(dlna, media, params));

    // Add audio bitrate options
    cmdList.addAll(getAudioBitrateOptions(dlna, media, params));

    // Add any remaining custom options
    if (!customOptions.isEmpty()) {
      customOptions.transferAll(cmdList);
    }

    // Output file
    cmdList.add(pipe.getInputPipe());

    // Convert the command list to an array
    String[] cmdArray = new String[cmdList.size()];
    cmdList.toArray(cmdArray);
View Full Code Here

TOP

Related Classes of net.pms.io.PipeProcess

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.