1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

EXPERIMENTAL: Add {ffprobe} binding for direct access to ffprobe -show_streams -print_format json

This commit is contained in:
Reinhard Pointner 2018-06-02 23:38:27 +07:00
parent 435271f57d
commit c5395e5ff1
2 changed files with 46 additions and 0 deletions

View File

@ -54,6 +54,7 @@ import net.filebot.hash.HashType;
import net.filebot.media.MetaAttributes;
import net.filebot.media.PlexNamingStandard;
import net.filebot.media.VideoFormat;
import net.filebot.mediainfo.FFProbe;
import net.filebot.mediainfo.ImageMetadata;
import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind;
@ -1079,6 +1080,11 @@ public class MediaBindingBean {
return MetaAttributes.toJson(infoObject);
}
@Define("ffprobe")
public Object getFFProbeDump() throws Exception {
return new FFProbe().streams(getInferredMediaFile());
}
public File getInferredMediaFile() {
File file = getMediaFile();

View File

@ -0,0 +1,40 @@
package net.filebot.mediainfo;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.File;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.util.List;
import java.util.Map;
import com.cedarsoftware.util.io.JsonReader;
public class FFProbe {
public String getFFProbeCommand() {
return System.getProperty("net.filebot.mediainfo.ffprobe", "ffprobe");
}
public List<Map<String, Object>> streams(File file) throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(getFFProbeCommand(), "-show_streams", "-print_format", "json", "-v", "error", file.getCanonicalPath());
processBuilder.directory(file.getParentFile());
processBuilder.redirectError(Redirect.INHERIT);
Process process = processBuilder.start();
// parse process standard output
Map<String, Object> json = (Map<String, Object>) JsonReader.jsonToJava(process.getInputStream(), singletonMap(JsonReader.USE_MAPS, true));
List<Map<String, Object>> streams = (List) asList((Object[]) json.get("streams"));
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new IOException(String.format("%s failed with exit code %d", processBuilder.command(), exitCode));
}
return streams;
}
}