tried to add "duration" metadata to flv stream
This commit is contained in:
parent
1e04937fab
commit
a9a5840692
4 changed files with 22 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,5 +6,5 @@ cache.properties
|
||||||
/.project
|
/.project
|
||||||
/.settings
|
/.settings
|
||||||
/.springBeans
|
/.springBeans
|
||||||
|
/bin
|
||||||
/target
|
/target
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,10 @@ public class DirectoryEntry extends EntryWithChildren<Entry> {
|
||||||
setThumbnail(thumbnail);
|
setThumbnail(thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String duration = props.getProperty("file." + name + ".length");
|
||||||
|
if (duration != null) {
|
||||||
|
thumbnail.setDuration(duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (key.startsWith("dir.") && !key.endsWith(".hidden")) {
|
} else if (key.startsWith("dir.") && !key.endsWith(".hidden")) {
|
||||||
String name = key.substring("dir.".length());
|
String name = key.substring("dir.".length());
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public class Thumbnail {
|
||||||
Dimension size;
|
Dimension size;
|
||||||
int orientation;
|
int orientation;
|
||||||
String etag;
|
String etag;
|
||||||
|
String duration;
|
||||||
|
|
||||||
|
|
||||||
public Thumbnail(File path) {
|
public Thumbnail(File path) {
|
||||||
|
|
@ -68,4 +69,11 @@ public class Thumbnail {
|
||||||
public File getPath() {
|
public File getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
public void setDuration(String duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ public class MovieCoder {
|
||||||
List<String> lines = IOUtils.readLines(p.getInputStream());
|
List<String> lines = IOUtils.readLines(p.getInputStream());
|
||||||
int returnStatus = p.waitFor();
|
int returnStatus = p.waitFor();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||||
String width = "", height = "";
|
String width = "", height = "", length = "";
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
int pos = line.indexOf('=');
|
int pos = line.indexOf('=');
|
||||||
if (pos >= 0) {
|
if (pos >= 0) {
|
||||||
|
|
@ -110,6 +110,7 @@ public class MovieCoder {
|
||||||
String value = line.substring(pos + 1);
|
String value = line.substring(pos + 1);
|
||||||
if (name.equals("ID_VIDEO_WIDTH")) width = value;
|
if (name.equals("ID_VIDEO_WIDTH")) width = value;
|
||||||
if (name.equals("ID_VIDEO_HEIGHT")) height = value;
|
if (name.equals("ID_VIDEO_HEIGHT")) height = value;
|
||||||
|
if (name.equals("ID_LENGTH")) length = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props.put("type", "movie");
|
props.put("type", "movie");
|
||||||
|
|
@ -117,6 +118,7 @@ public class MovieCoder {
|
||||||
props.put("dimensions", new Dimension(width, height).toString());
|
props.put("dimensions", new Dimension(width, height).toString());
|
||||||
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
props.put("captureDate", sdf.format(new Date(f.lastModified())));
|
||||||
props.put("etag", Integer.toHexString(f.getName().hashCode() + Long.valueOf(f.lastModified()).hashCode()));
|
props.put("etag", Integer.toHexString(f.getName().hashCode() + Long.valueOf(f.lastModified()).hashCode()));
|
||||||
|
props.put("length", length);
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -289,8 +291,9 @@ public class MovieCoder {
|
||||||
"-g", "150", "-cmp", "2", "-subcmp", "2", "-mbd", "2",
|
"-g", "150", "-cmp", "2", "-subcmp", "2", "-mbd", "2",
|
||||||
"-flags", "+aic+cbp+mv0+mv4", "-trellis", "1",
|
"-flags", "+aic+cbp+mv0+mv4", "-trellis", "1",
|
||||||
"-f", "flv",
|
"-f", "flv",
|
||||||
|
"-metadata", "duration=" + thumbnail.getDuration(),
|
||||||
"-");
|
"-");
|
||||||
|
log.info(pb.command().toString());
|
||||||
pb.redirectErrorStream(false);
|
pb.redirectErrorStream(false);
|
||||||
Process p = pb.start();
|
Process p = pb.start();
|
||||||
p.getOutputStream().close();
|
p.getOutputStream().close();
|
||||||
|
|
@ -351,9 +354,10 @@ public class MovieCoder {
|
||||||
|
|
||||||
|
|
||||||
public void stream(File file, Thumbnail thumbnail, String size, OutputStream out) throws IOException, InterruptedException {
|
public void stream(File file, Thumbnail thumbnail, String size, OutputStream out) throws IOException, InterruptedException {
|
||||||
|
System.out.println("being asked to stream " + file + " size=" + size);
|
||||||
Dimension targetSize = thumbnail.getSize().scale(size);
|
Dimension targetSize = thumbnail.getSize().scale(size);
|
||||||
// new EncodingProcess(file, thumbnail, targetSize).streamTo(out);
|
new EncodingProcess(file, thumbnail, targetSize).streamTo(out);
|
||||||
|
/*
|
||||||
String key = file.getPath() + ":" + targetSize.getWidth();
|
String key = file.getPath() + ":" + targetSize.getWidth();
|
||||||
int chunkNo = 0;
|
int chunkNo = 0;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
@ -364,6 +368,7 @@ public class MovieCoder {
|
||||||
}
|
}
|
||||||
out.write(chunk.bits);
|
out.write(chunk.bits);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue