Merge pull request #153 from tmciver-basis/master

Bug fix to DataContentViewerMedia.captureFrames()
This commit is contained in:
adam 2013-02-26 16:41:29 -08:00
commit 27ff6bc2d0

View File

@ -430,6 +430,8 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
PlayBin2 playbin = new PlayBin2("VideoFrameCapture"); PlayBin2 playbin = new PlayBin2("VideoFrameCapture");
playbin.setInputFile(file); playbin.setInputFile(file);
playbin.setVideoSink(videoSink); playbin.setVideoSink(videoSink);
// this is necessary to get a valid duration value
playbin.play(); playbin.play();
playbin.pause(); playbin.pause();
playbin.getState(); playbin.getState();
@ -437,28 +439,25 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
// get the duration of the video // get the duration of the video
TimeUnit unit = TimeUnit.MILLISECONDS; TimeUnit unit = TimeUnit.MILLISECONDS;
long myDurationMillis = playbin.queryDuration(unit); long myDurationMillis = playbin.queryDuration(unit);
System.out.println("Duration is: " + myDurationMillis);
if (myDurationMillis <= 0) { if (myDurationMillis <= 0) {
return frames; return frames;
} }
// create a list of timestamps at which to get frames // create a list of timestamps at which to get frames
List<Long> timeStamps = new ArrayList<>();
int numFramesToGet = numFrames; int numFramesToGet = numFrames;
long frameInterval = myDurationMillis/numFrames; long frameInterval = myDurationMillis/numFrames;
if (frameInterval < MIN_FRAME_INTERVAL_MILLIS) { if (frameInterval < MIN_FRAME_INTERVAL_MILLIS) {
numFramesToGet = 1; numFramesToGet = 1;
} }
for (int i = 0; i < numFramesToGet; ++i) {
System.out.println("Adding timestamp " + i*frameInterval + " ms");
timeStamps.add(i*frameInterval);
}
// for each timeStamp, grap a frame // for each timeStamp, grap a frame
for (long timeStamp : timeStamps) { for (int i = 0; i < numFramesToGet; ++i) {
currentImage = null; long timeStamp = i*frameInterval;
playbin.pause(); playbin.pause();
playbin.getState(); playbin.getState();
currentImage = null;
if (!playbin.seek(timeStamp, unit)) { if (!playbin.seek(timeStamp, unit)) {
logger.log(Level.INFO, "There was a problem seeking to " + timeStamp + " " + unit.name().toLowerCase()); logger.log(Level.INFO, "There was a problem seeking to " + timeStamp + " " + unit.name().toLowerCase());
} }