mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-12 05:35:31 +00:00
added a main class to org.mp4parser.isoparser that can spit out metadata for an mp4 file
Change-Id: I5cd577569eff809d734055fb744a50ddc429030b
This commit is contained in:
1 parent
bda19042ac
commit
ebd9d83de4
2 files changed
+80
No files matched your search
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/isoparser-1.9.31.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.sap.sailing.media;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.mp4parser.IsoFile;
|
||||
import org.mp4parser.boxes.UserBox;
|
||||
import org.mp4parser.boxes.iso14496.part12.MovieBox;
|
||||
import org.mp4parser.boxes.iso14496.part12.MovieHeaderBox;
|
||||
import org.mp4parser.tools.Path;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class MediaFileParser {
|
||||
public static void main(String[] args) throws MalformedURLException, ParserConfigurationException, SAXException, IOException {
|
||||
new MediaFileParser().checkMetadataByFullFileDownload(new File(args[0]));
|
||||
}
|
||||
|
||||
private void checkMetadataByFullFileDownload(File input)
|
||||
throws ParserConfigurationException, SAXException, IOException {
|
||||
IsoFile isof = new IsoFile(input);
|
||||
Date recordStartedTimer = determineRecordingStart(isof);
|
||||
long durationInMillis = determineDurationInMillis(isof);
|
||||
boolean spherical = determine360(isof);
|
||||
System.out.println("Start: "+recordStartedTimer.toString()+", duration: "+durationInMillis+"ms; spherical: "+spherical);
|
||||
}
|
||||
|
||||
private boolean determine360(IsoFile isof) throws ParserConfigurationException, SAXException, IOException {
|
||||
boolean spherical = false;
|
||||
UserBox uuidBox = Path.getPath(isof, "moov[0]/trak[0]/uuid");
|
||||
if (uuidBox != null) {
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(new ByteArrayInputStream(uuidBox.getData()));
|
||||
|
||||
NodeList childs = doc.getDocumentElement().getChildNodes();
|
||||
for (int i = 0; i < childs.getLength(); i++) {
|
||||
Node child = childs.item(i);
|
||||
if (child.getNodeName().toLowerCase().contains(":spherical")) {
|
||||
spherical = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return spherical;
|
||||
}
|
||||
|
||||
private long determineDurationInMillis(IsoFile isof) {
|
||||
long duration = -1;
|
||||
MovieBox mbox = isof.getMovieBox();
|
||||
if (mbox != null) {
|
||||
MovieHeaderBox mhb = mbox.getMovieHeaderBox();
|
||||
if (mhb != null) {
|
||||
duration = mhb.getDuration()*1000 / mhb.getTimescale();
|
||||
}
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
private Date determineRecordingStart(IsoFile isof) {
|
||||
Date creationTime = null;
|
||||
MovieBox mbox = isof.getMovieBox();
|
||||
if (mbox != null) {
|
||||
MovieHeaderBox mhb = mbox.getMovieHeaderBox();
|
||||
if (mhb != null) {
|
||||
creationTime = mhb.getCreationTime();
|
||||
}
|
||||
}
|
||||
return creationTime;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user