01: /*
02: * Created on Sep 20, 2005
03: */
04: package org.openedit.store.images;
05:
06: import java.io.File;
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12:
13: import com.openedit.OpenEditException;
14: import com.openedit.modules.image.ConvertInstructions;
15: import com.openedit.modules.image.ImageResizer;
16: import com.openedit.util.Exec;
17: import com.openedit.util.PathUtilities;
18:
19: public class MpegImageResizer extends ImageResizer {
20: private static final Log log = LogFactory
21: .getLog(MpegImageResizer.class);
22: protected String fieldCommandName = "ffmpeg"; //ffmpeg -itsoffset 10 -deinterlace -i $TRACK -y -vframes 1 -f mjpeg $OUTPUT
23:
24: public boolean canResize(String inPath) {
25: String mime = getMimeTypeMap().getMimeType(
26: PathUtilities.extractPageType(inPath));
27: if (mime.equals("video/mpeg") || mime.equals("video/avi")) {
28: //return true;
29: }
30: return false;
31: }
32:
33: public boolean canConvert(String inPath) {
34: return false;
35: }
36:
37: public boolean resizeImage(File inFile, File inOutFile,
38: ConvertInstructions inStructions) throws Exception {
39: List com = new ArrayList();
40: com.add(getCommandName());
41: //-itsoffset 10 -deinterlace -i $TRACK -y -vframes 1 -f mjpeg $OUTPUT
42: com.add("-itsoffset");
43: com.add("10");
44: com.add("-deinterlace");
45: com.add("-i");
46: com.add(inFile.getAbsolutePath()); //TODO: Might need [0] to pick the first image only
47: com.add("-y");
48: com.add("-vframes");
49: com.add("1");
50: com.add("-f");
51: com.add("mjpeg");
52:
53: //-s 640x480
54: //com.add("-s");
55: //com.add( (int)inStructions.getMaxScaledSize().getWidth() + "x" + (int)inStructions.getMaxScaledSize().getHeight() + ">" );
56: com.add(inOutFile.getAbsolutePath());
57:
58: inOutFile.getParentFile().mkdirs();
59: long start = System.currentTimeMillis();
60: if (runExec(com)) {
61: log.info("Resize complete in:"
62: + (System.currentTimeMillis() - start) + " "
63: + inOutFile.getName());
64: return true;
65: }
66: return false;
67: }
68:
69: protected boolean runExec(List inCom) throws OpenEditException {
70: Exec exec = new Exec();
71:
72: exec.setTrackOutput(false);
73: boolean works = exec.runExec(inCom);
74: if (!works) {
75: log
76: .info("Resize failed running again with output tracking");
77: exec.setTrackOutput(true);
78: works = exec.runExec(inCom);
79: log.info(exec.getStandardOutput() + " error output:"
80: + exec.getErrorOutput());
81: }
82: return works;
83: }
84:
85: public String getCommandName() {
86: return fieldCommandName;
87: }
88:
89: public void setCommandName(String inCommandName) {
90: fieldCommandName = inCommandName;
91: }
92: }
|