mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
EXPERIMENTAL: Add {ffprobe} binding for direct access to ffprobe -show_streams -print_format json
This commit is contained in:
parent
435271f57d
commit
c5395e5ff1
@ -54,6 +54,7 @@ import net.filebot.hash.HashType;
|
|||||||
import net.filebot.media.MetaAttributes;
|
import net.filebot.media.MetaAttributes;
|
||||||
import net.filebot.media.PlexNamingStandard;
|
import net.filebot.media.PlexNamingStandard;
|
||||||
import net.filebot.media.VideoFormat;
|
import net.filebot.media.VideoFormat;
|
||||||
|
import net.filebot.mediainfo.FFProbe;
|
||||||
import net.filebot.mediainfo.ImageMetadata;
|
import net.filebot.mediainfo.ImageMetadata;
|
||||||
import net.filebot.mediainfo.MediaInfo;
|
import net.filebot.mediainfo.MediaInfo;
|
||||||
import net.filebot.mediainfo.MediaInfo.StreamKind;
|
import net.filebot.mediainfo.MediaInfo.StreamKind;
|
||||||
@ -1079,6 +1080,11 @@ public class MediaBindingBean {
|
|||||||
return MetaAttributes.toJson(infoObject);
|
return MetaAttributes.toJson(infoObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Define("ffprobe")
|
||||||
|
public Object getFFProbeDump() throws Exception {
|
||||||
|
return new FFProbe().streams(getInferredMediaFile());
|
||||||
|
}
|
||||||
|
|
||||||
public File getInferredMediaFile() {
|
public File getInferredMediaFile() {
|
||||||
File file = getMediaFile();
|
File file = getMediaFile();
|
||||||
|
|
||||||
|
40
source/net/filebot/mediainfo/FFProbe.java
Normal file
40
source/net/filebot/mediainfo/FFProbe.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user