Some more work on movies.

This commit is contained in:
Knut Forkalsrud 2011-06-22 15:10:12 -07:00
parent 1b642ddab9
commit 74f08f44b0
3 changed files with 45 additions and 12 deletions

View file

@ -16,8 +16,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.forkalsrud.album.db.MovieDatabase;
import org.forkalsrud.album.db.Chunk;
import org.forkalsrud.album.db.MovieDatabase;
import org.forkalsrud.album.exif.Dimension;
import org.forkalsrud.album.exif.Thumbnail;
import org.forkalsrud.album.web.CachedImage;
@ -64,7 +64,7 @@ public class MovieCoder {
stdin.close();
InputStream stdout = p.getInputStream();
String searchPath = IOUtils.toString(stdout);
int returnStatus = p.waitFor();
p.waitFor();
String separator = System.getProperty("path.separator");
if (searchPath != null && separator != null && !"".equals(separator)) {
@ -100,7 +100,7 @@ public class MovieCoder {
Process p = pb.start();
p.getOutputStream().close();
List<String> lines = IOUtils.readLines(p.getInputStream());
int returnStatus = p.waitFor();
p.waitFor();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
String width = "", height = "";
for (String line : lines) {
@ -153,9 +153,7 @@ public class MovieCoder {
Process p = pb.start();
p.getOutputStream().close();
log.debug(IOUtils.toString(p.getInputStream()));
int returnStatus = p.waitFor();
String key = file.getPath() + ":" + secondNo + ":" + size;
p.waitFor();
CachedImage ci = pictureScaler.scalePicture(frame, thumbnail, size);
return ci;
} finally {
@ -265,6 +263,7 @@ public class MovieCoder {
* <outfile>.mp4
*/
@Override
public void run() {
try {
@ -353,7 +352,8 @@ public class MovieCoder {
public void stream(File file, Thumbnail thumbnail, String size, OutputStream out) throws IOException, InterruptedException {
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();
int chunkNo = 0;
boolean done = false;
@ -364,6 +364,7 @@ public class MovieCoder {
}
out.write(chunk.bits);
}
*/
}
}

View file

@ -296,11 +296,41 @@ public class AlbumServlet
}
void handleMovieFrame(HttpServletRequest req, HttpServletResponse res, FileEntry entry) {
File file = entry.getPath();
if (notModified(req, file)) {
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days
log.info(file.getName() + " not modified (based on date)");
return;
}
int secondNo = 3;
String size = req.getParameter("size");
if (size == null) {
size = "250";
}
String key = file.getPath() + ":" + secondNo + ":" + size;
CachedImage cimg = thumbDb.load(key);
if (cimg != null) {
if (cimg.lastModified == file.lastModified()) {
log.info("cache hit on " + key);
} else {
log.info(" " + key + " has changed so cache entry wil be refreshed");
cimg = null;
}
}
if (cimg == null) {
try {
cimg = movieCoder.extractFrame(file, secondNo, entry.getThumbnail(), size);
thumbDb.store(key, cimg);
log.info(" " + key + " added to the cache with size " + cimg.bits.length + " -- now " + thumbDb.size() + " entries");
} catch (Exception e) {
throw new RuntimeException("sadness", e);
}
}
try {
String size = req.getParameter("size");
CachedImage cimg = movieCoder.extractFrame(entry.getPath(), 3, entry.getThumbnail(), size != null ? size : "250");
res.setStatus(HttpServletResponse.SC_OK);
res.setDateHeader("Last-Modified", entry.getPath().lastModified());
res.setDateHeader("Last-Modified", file.lastModified());
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days
res.setContentType(cimg.mimeType);
res.setContentLength(cimg.bits.length);

View file

@ -86,7 +86,8 @@ public class PictureScaler {
}
public CachedImage call() throws Exception {
@Override
public CachedImage call() throws Exception {
return scalePictureReally(file, thumbnail, size);
}
@ -108,7 +109,8 @@ public class PictureScaler {
return new Comparator<PictureRequest>() {
public int compare(PictureRequest o1, PictureRequest o2) {
@Override
public int compare(PictureRequest o1, PictureRequest o2) {
return Long.signum(o1.priority - o2.priority);
}
};