Search in sources :

Example 1 with VideoOpenException

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;
}
Also used : VideoOpenException(co.videofirst.vft.capture.exception.VideoOpenException) Capture(co.videofirst.vft.capture.model.capture.Capture)

Example 2 with VideoOpenException

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);
    }
}
Also used : IOException(java.io.IOException) VideoOpenException(co.videofirst.vft.capture.exception.VideoOpenException) FileInputStream(java.io.FileInputStream) Capture(co.videofirst.vft.capture.model.capture.Capture)

Aggregations

VideoOpenException (co.videofirst.vft.capture.exception.VideoOpenException)2 Capture (co.videofirst.vft.capture.model.capture.Capture)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1