use of net.pms.io.ProcessWrapperImpl in project UniversalMediaServer by UniversalMediaServer.
the class DVDISOFile method resolveOnce.
@Override
protected void resolveOnce() {
double[] titles = new double[100];
String[] cmd = new String[] { configuration.getMplayerPath(), "-identify", "-endpos", "0", "-ao", "null", "-vc", "null", "-vo", "null", "-dvd-device", ProcessUtil.getShortFileNameIfWideChars(file.getAbsolutePath()), "dvd://" };
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")));
double duration = Double.parseDouble(line.substring(line.lastIndexOf("LENGTH=") + 7));
titles[rank] = duration;
} else if (line.startsWith("ID_DVD_VOLUME_ID")) {
String volumeId = line.substring(line.lastIndexOf("_ID=") + 4).trim();
if (configuration.isPrettifyFilenames()) {
volumeId = volumeId.replaceAll("_", " ");
if (isNotBlank(volumeId) && volumeId.equals(volumeId.toUpperCase(PMS.getLocale()))) {
volumeId = WordUtils.capitalize(volumeId.toLowerCase(PMS.getLocale()));
}
}
this.volumeId = volumeId;
}
}
}
double oldduration = -1;
for (int i = 1; i < 99; i++) {
/**
* Don't take into account titles less than 10 seconds
* Also, workaround for the MPlayer bug which reports a unique title with the same length several times
* The "maybe wrong" title is taken into account only if its duration is less than 1 hour.
* Common-sense is a single video track on a DVD is usually greater than 1h
*/
if (titles[i] > 10 && (titles[i] != oldduration || oldduration < 3600)) {
DVDISOTitle dvd = new DVDISOTitle(file, volumeId, i);
addChild(dvd);
oldduration = titles[i];
}
}
if (childrenNumber() > 0) {
PMS.get().storeFileInCache(file, Format.ISO);
}
}
use of net.pms.io.ProcessWrapperImpl in project UniversalMediaServer by UniversalMediaServer.
the class DLNAMediaInfo method getMplayerThumbnail.
private ProcessWrapperImpl getMplayerThumbnail(InputFile media, boolean resume, RendererConfiguration renderer) throws IOException {
File file = media.getFile();
String[] args = new String[14];
args[0] = configuration.getMplayerPath();
args[1] = "-ss";
if (resume) {
args[2] = "" + (int) getDurationInSeconds();
} else {
args[2] = "" + configuration.getThumbnailSeekPos();
}
args[3] = "-quiet";
if (file != null) {
args[4] = ProcessUtil.getShortFileNameIfWideChars(file.getAbsolutePath());
} else {
args[4] = "-";
}
args[5] = "-msglevel";
args[6] = "all=4";
int thumbnailWidth = 320;
int thumbnailHeight = 180;
boolean isThumbnailPadding = true;
if (renderer != null) {
thumbnailWidth = renderer.getThumbnailWidth();
thumbnailHeight = renderer.getThumbnailHeight();
isThumbnailPadding = renderer.isThumbnailPadding();
}
if (isThumbnailPadding) {
args[7] = "-vf";
args[8] = "scale=" + thumbnailWidth + ":-2,expand=:" + thumbnailHeight;
} else {
args[7] = "-vf";
args[8] = "scale=" + thumbnailWidth + ":-2";
}
args[9] = "-frames";
args[10] = "1";
args[11] = "-vo";
String frameName = "" + media.hashCode();
frameName = "mplayer_thumbs:subdirs=\"" + frameName + "\"";
frameName = frameName.replace(',', '_');
args[12] = "jpeg:outdir=" + frameName;
args[13] = "-nosound";
OutputParams params = new OutputParams(configuration);
params.workDir = configuration.getTempFolder();
params.maxBufferSize = 1;
params.stdin = media.getPush();
params.log = true;
// not serious if anything happens during the thumbnailer
params.noexitcheck = true;
final ProcessWrapperImpl pw = new ProcessWrapperImpl(args, true, params);
// FAILSAFE
synchronized (parsingLock) {
parsing = true;
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
pw.stopProcess();
synchronized (parsingLock) {
parsing = false;
}
}
};
Thread failsafe = new Thread(r, "MPlayer Thumbnail Failsafe");
failsafe.start();
pw.runInSameThread();
synchronized (parsingLock) {
parsing = false;
}
return pw;
}
use of net.pms.io.ProcessWrapperImpl in project UniversalMediaServer by UniversalMediaServer.
the class SubtitleUtils method convertSubsToSubtitleType.
/**
* Converts external subtitles or extract embedded subs to the requested subtitle type
*
* @param fileName subtitles file or video file with embedded subs
* @param media
* @param params output parameters
* @param configuration
* @param outputSubtitleType requested subtitle type
* @return Converted subtitles file in requested type
*/
public static File convertSubsToSubtitleType(String fileName, DLNAMediaInfo media, OutputParams params, PmsConfiguration configuration, SubtitleType outputSubtitleType) {
if (!params.sid.getType().isText()) {
return null;
}
List<String> cmdList = new ArrayList<>();
File tempSubsFile;
cmdList.add(configuration.getFfmpegPath());
cmdList.add("-y");
cmdList.add("-loglevel");
if (LOGGER.isTraceEnabled()) {
// Set -loglevel in accordance with LOGGER setting
// Could be changed to "verbose" or "debug" if "info" level is not enough
cmdList.add("info");
} else {
cmdList.add("fatal");
}
// Try to specify input encoding if we have a non utf-8 external sub
if (params.sid.getId() >= 100 && !params.sid.isExternalFileUtf8()) {
String encoding = isNotBlank(configuration.getSubtitlesCodepage()) ? // Note: likely wrong if the file isn't supplied by the user.
configuration.getSubtitlesCodepage() : params.sid.getSubCharacterSet() != null ? // Note: accuracy isn't 100% guaranteed.
params.sid.getSubCharacterSet() : // Otherwise we're out of luck!
null;
if (encoding != null) {
cmdList.add("-sub_charenc");
cmdList.add(encoding);
}
}
cmdList.add("-i");
cmdList.add(fileName);
if (params.sid.isEmbedded()) {
cmdList.add("-map");
cmdList.add("0:s:" + (media.getSubtitleTracksList().indexOf(params.sid)));
}
try {
tempSubsFile = new File(configuration.getTempFolder(), FilenameUtils.getBaseName(fileName) + "." + outputSubtitleType.getExtension());
} catch (IOException e1) {
LOGGER.debug("Subtitles conversion finished wih error: " + e1);
return null;
}
cmdList.add(tempSubsFile.getAbsolutePath());
String[] cmdArray = new String[cmdList.size()];
cmdList.toArray(cmdArray);
ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
pw.runInNewThread();
try {
// Wait until the conversion is finished
pw.join();
// Avoid creating a pipe for this process and messing up with buffer progress bar
pw.stopProcess();
} catch (InterruptedException e) {
LOGGER.debug("Subtitles conversion finished wih error: " + e);
return null;
}
tempSubsFile.deleteOnExit();
return tempSubsFile;
}
use of net.pms.io.ProcessWrapperImpl in project UniversalMediaServer by UniversalMediaServer.
the class VideoLanVideoStreaming method launchTranscode.
@Override
public ProcessWrapper launchTranscode(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) throws IOException {
// Use device-specific pms conf
PmsConfiguration prev = configuration;
configuration = (DeviceConfiguration) params.mediaRenderer;
boolean isWindows = Platform.isWindows();
final String filename = dlna.getFileName();
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());
if (isWindows) {
cmdList.add("--dummy-quiet");
}
if (isWindows || Platform.isMac()) {
cmdList.add("--sout=" + transcodeSpec);
} else {
cmdList.add("--sout");
cmdList.add(transcodeSpec);
}
// via: https://code.google.com/p/ps3mediaserver/issues/detail?id=711
if (Platform.isMac()) {
cmdList.add("");
}
cmdList.add(filename);
cmdList.add("vlc://quit");
String[] cmdArray = new String[cmdList.size()];
cmdList.toArray(cmdArray);
cmdArray = finalizeTranscoderArgs(filename, dlna, media, params, cmdArray);
ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
pw.attachProcess(pipe_process);
try {
Thread.sleep(150);
} catch (InterruptedException e) {
}
pw.runInNewThread();
configuration = prev;
return pw;
}
use of net.pms.io.ProcessWrapperImpl in project UniversalMediaServer by UniversalMediaServer.
the class FFmpegDVRMSRemux method getFFMpegTranscode.
// pointless redirection of launchTranscode
@Deprecated
protected ProcessWrapperImpl getFFMpegTranscode(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) {
PmsConfiguration prev = configuration;
// Use device-specific pms conf
configuration = (DeviceConfiguration) params.mediaRenderer;
String ffmpegAlternativePath = configuration.getFfmpegAlternativePath();
List<String> cmdList = new ArrayList<>();
final String filename = dlna.getFileName();
if (ffmpegAlternativePath != null && ffmpegAlternativePath.length() > 0) {
cmdList.add(ffmpegAlternativePath);
} else {
cmdList.add(executable());
}
if (params.timeseek > 0) {
cmdList.add("-ss");
cmdList.add("" + params.timeseek);
}
cmdList.add("-i");
cmdList.add(filename);
cmdList.addAll(Arrays.asList(args()));
String customSettingsString = configuration.getMPEG2MainSettingsFFmpeg();
if (StringUtils.isNotBlank(customSettingsString)) {
String[] customSettingsArray = StringUtils.split(customSettingsString);
if (customSettingsArray != null) {
cmdList.addAll(Arrays.asList(customSettingsArray));
}
}
cmdList.add("pipe:");
String[] cmdArray = new String[cmdList.size()];
cmdList.toArray(cmdArray);
cmdArray = finalizeTranscoderArgs(filename, dlna, media, params, cmdArray);
ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params);
pw.runInNewThread();
configuration = prev;
return pw;
}
Aggregations