use of co.videofirst.vft.capture.exception.VideoOpenException in project vft-capture by videofirst.
the class FileSystemCaptureDao method findById.
@Override
public Capture findById(String captureId) {
// Check cache
if (captureIdCache.get(captureId) != null) {
try {
Capture capture = readVideoFromDataFile(captureIdCache.get(captureId), Capture.class);
if (capture != null && capture.getId().equals(captureId)) {
return capture;
}
} catch (VideoOpenException voEx) {
log.warn("Error opening capture", voEx.getMessage());
}
// remove from cache and continue
captureIdCache.remove(captureId);
}
FindFile findFile = new FindFile();
findVideoFile(captureId, videoFolder, findFile);
if (findFile.getFile() == null) {
throw new VideoOpenException("Cannot find a capture for ID - " + captureId);
}
Capture capture = readVideoFromDataFile(findFile.getFile(), Capture.class);
captureIdCache.put(captureId, findFile.getFile());
return capture;
}
use of co.videofirst.vft.capture.exception.VideoOpenException in project vft-capture by videofirst.
the class FileSystemCaptureDao method readVideoFromDataFile.
// private methods
private <V> V readVideoFromDataFile(File file, Class<V> videoType) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
V v = objectMapper.readValue(fileInputStream, videoType);
// Set additional (non-saved) fields which can be useful e.g. uploading / streaming
if (v instanceof Capture) {
Capture capture = (Capture) v;
capture.setDataFile(getDataFile(capture));
capture.setVideoFile(getVideoFile(capture));
}
return v;
} catch (IOException e) {
throw new VideoOpenException("Error open video - " + file.getAbsolutePath(), e);
}
}
Aggregations