StoryBoard.java
3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.dam.api.Asset
* com.day.image.Layer
* org.apache.commons.io.IOUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.video;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.handler.ffmpeg.FFMpegWrapper;
import com.day.image.Layer;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StoryBoard {
private static final Logger log = LoggerFactory.getLogger(StoryBoard.class);
private final List<String> framesList = new LinkedList<String>();
private final FFMpegWrapper wrapper;
private final Asset asset;
private int frames = 10;
private int start = 0;
private int maxWidth = 320;
private int maxHeight = 240;
private boolean upscale = true;
public StoryBoard(FFMpegWrapper wrapper, Asset asset) {
this.wrapper = wrapper;
this.asset = asset;
if (null == wrapper) {
throw new IllegalArgumentException("wrapper may not be null");
}
if (null == asset) {
throw new IllegalArgumentException("asset may not be null");
}
}
public void setFrames(int frames) {
this.frames = frames;
}
public void setStart(int start) {
this.start = start;
}
public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
}
public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}
public void setUpscale(boolean upscale) {
this.upscale = upscale;
}
public synchronized void addFrame(String config) {
this.framesList.add(config);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void create() throws IOException {
BufferedImage[] frames = this.wrapper.getThumbnails(this.frames, this.start);
log.debug("got [{}] thumbs to be processed as key frames for [{}]...", (Object)frames.length, (Object)this.asset.getPath());
int i = 0;
File tmpFile = null;
try {
tmpFile = File.createTempFile("keyframe." + System.currentTimeMillis(), ".tmp");
for (BufferedImage frame : frames) {
if (null == frame) {
log.warn("encountered null frame at index [{}] for asset [{}]", (Object)i, (Object)this.asset.getPath());
} else {
log.debug("processing frame [{}] for [{}]...", (Object)i, (Object)this.asset.getPath());
Layer l = new Layer(frame);
FileOutputStream out = null;
FileInputStream in = null;
try {
out = new FileOutputStream(tmpFile);
l.write("image/png", 0.8, (OutputStream)out);
in = new FileInputStream(tmpFile);
Asset sub = this.asset.addSubAsset(this.asset.getName() + ".keyframe." + (i + 1) + ".png", "image/png", (InputStream)in);
log.info("created key frame sub-asset [{}] for [{}],", (Object)sub.getPath(), (Object)this.asset.getPath());
}
finally {
IOUtils.closeQuietly((InputStream)in);
IOUtils.closeQuietly((OutputStream)out);
}
}
++i;
}
}
catch (Exception e) {
log.error("failed creating storyboard for [{}]: ", (Object)this.asset.getPath(), (Object)e);
}
finally {
if (null != tmpFile) {
tmpFile.delete();
}
}
}
}