Package net.pms.io

Examples of net.pms.io.PipeProcess


    setAudioAndSubs(filename, media, params, configuration);

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

    PipeProcess tsPipe = new PipeProcess("VLC" + System.currentTimeMillis() + "." + codecConfig.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<String>();
    cmdList.add(executable());
    cmdList.add("-I");
    cmdList.add("dummy");

    // XXX hardware acceleration causes issues with some videos
    // on VLC 2.0.5, so disable it by default.
    // Note: it's enabled by default in 2.0.5 (and possibly
    // earlier), so, if not enabled, it needs to be explicitly
    // disabled

    // These options do not exist in VLC 2.0.7 on Mac OS X
    if (!Platform.isMac()) {
      if (configuration.isVideoHardwareAcceleration()) {
        logger.warn("VLC hardware acceleration support is an experimental feature. Please disable it before reporting issues.");
        cmdList.add("--ffmpeg-hw");
      } else {
        cmdList.add("--no-ffmpeg-hw");
      }
    }

    // Useful for the more esoteric codecs people use
    if (experimentalCodecs.isSelected()) {
      cmdList.add("--sout-ffmpeg-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);

    // FIXME not sure what this hack is trying to do, but it results in no audio and no subtitles
    // Huge fake track id that shouldn't conflict with any real subtitle or audio id. Hopefully.
    String disableSuffix = "track=214748361";

    // 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 = null;

        // 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 if (!configuration.isDisableSubtitles()) { // Not specified, use language from GUI if enabled
      // FIXME: VLC does not understand "loc" or "und".
      cmdList.add("--sub-language=" + configuration.getSubtitlesLanguages());
    } else {
      cmdList.add("--sub-" + disableSuffix);
    }

    // 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(codecConfig).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(),
        codecConfig.container,
        (isWindows ? "\\\\" : ""),
        tsPipe.getInputPipe());
    cmdList.add("--sout");
    cmdList.add(transcodeSpec);

    // Force VLC to exit when finished
    cmdList.add("vlc://quit");
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.