created method to read metadata from video files
This commit is contained in:
parent
6b0082c685
commit
e13c8f822d
3 changed files with 51 additions and 0 deletions
7
pom.xml
7
pom.xml
|
|
@ -192,6 +192,13 @@
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<version>1.5.10</version>
|
<version>1.5.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ public class Dimension {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Dimension(String width, String height) {
|
||||||
|
this(Integer.parseInt(width), Integer.parseInt(height));
|
||||||
|
}
|
||||||
|
|
||||||
public Dimension doubled() {
|
public Dimension doubled() {
|
||||||
|
|
||||||
return new Dimension(w * 2, h * 2);
|
return new Dimension(w * 2, h * 2);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
@ -17,6 +18,7 @@ import javax.imageio.ImageReadParam;
|
||||||
import javax.imageio.ImageReader;
|
import javax.imageio.ImageReader;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.forkalsrud.album.db.DirectoryProps;
|
import org.forkalsrud.album.db.DirectoryProps;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -94,6 +96,12 @@ public class DirectoryMetadataGenerator {
|
||||||
props.setProperty("dir." + name, "present");
|
props.setProperty("dir." + name, "present");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param f the jpeg file
|
||||||
|
* @return a map with the following keys: orientation dimensions captureDate comment etag
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
private Map<String, String> generateThumbnailProperties(File f) throws IOException {
|
private Map<String, String> generateThumbnailProperties(File f) throws IOException {
|
||||||
|
|
||||||
HashMap<String, String> props = new HashMap<String, String>();
|
HashMap<String, String> props = new HashMap<String, String>();
|
||||||
|
|
@ -159,6 +167,38 @@ public class DirectoryMetadataGenerator {
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param f the jpeg file
|
||||||
|
* @return a map with the following keys: orientation dimensions captureDate comment etag
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Map<String, String> generateVideoProperties(File f) throws IOException {
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
ProcessBuilder pb = new ProcessBuilder().command(
|
||||||
|
"mplayer", "-vo", "null", "-ao", "null", "-frames", "0", "-identify", f.getAbsolutePath());
|
||||||
|
pb.redirectErrorStream(false);
|
||||||
|
Process p = pb.start();
|
||||||
|
p.getOutputStream().close();
|
||||||
|
List<String> lines = IOUtils.readLines(p.getInputStream());
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||||
|
String width = "", height = "";
|
||||||
|
for (String line : lines) {
|
||||||
|
int pos = line.indexOf('=');
|
||||||
|
if (pos >= 0) {
|
||||||
|
String name = line.substring(0, pos);
|
||||||
|
String value = line.substring(pos + 1);
|
||||||
|
if (name.equals("ID_VIDEO_WIDTH")) width = value;
|
||||||
|
if (name.equals("ID_VIDEO_HEIGHT")) height = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
props.put("orientation", "1");
|
||||||
|
props.put("dimensions", new Dimension(width, height).toString());
|
||||||
|
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
||||||
|
props.put("etag", Integer.toHexString(f.getName().hashCode() + Long.valueOf(f.lastModified()).hashCode()));
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
private Date getExifDate(Directory exifDirectory, int tagName) throws MetadataException {
|
private Date getExifDate(Directory exifDirectory, int tagName) throws MetadataException {
|
||||||
|
|
||||||
String dateStr = (String)exifDirectory.getObject(tagName);
|
String dateStr = (String)exifDirectory.getObject(tagName);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue