Merge pull request #5726 from wschaeferB/6133-ChangeDefaultVideoThumb

6133 change default video thumb
This commit is contained in:
Richard Cordovano 2020-03-20 15:04:09 -04:00 committed by GitHub
commit b63c48905e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -23,7 +23,6 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.io.Files; import com.google.common.io.Files;
import java.awt.Image; import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -95,6 +94,7 @@ class FileSearch {
.build(); .build();
private static final int PREVIEW_SIZE = 256; private static final int PREVIEW_SIZE = 256;
private static volatile TextSummarizer summarizerToUse = null; private static volatile TextSummarizer summarizerToUse = null;
private static final BufferedImage VIDEO_DEFAULT_IMAGE = getDefaultVideoThumbnail();
/** /**
* Run the file search and returns the SearchResults object for debugging. * Run the file search and returns the SearchResults object for debugging.
@ -456,6 +456,20 @@ class FileSearch {
+ "AND blackboard_artifacts.obj_id IN (" + objIdList + ") "; // NON-NLS + "AND blackboard_artifacts.obj_id IN (" + objIdList + ") "; // NON-NLS
} }
/**
* Get the default image to display when a thumbnail is not available.
*
* @return The default video thumbnail.
*/
private static BufferedImage getDefaultVideoThumbnail() {
try {
return ImageIO.read(ImageUtils.class.getResourceAsStream("/org/sleuthkit/autopsy/images/failedToCreateVideoThumb.png"));//NON-NLS
} catch (IOException ex) {
logger.log(Level.SEVERE, "Failed to load 'failed to create video' placeholder.", ex); //NON-NLS
}
return null;
}
/** /**
* Get the video thumbnails for a file which exists in a * Get the video thumbnails for a file which exists in a
* VideoThumbnailsWrapper and update the VideoThumbnailsWrapper to include * VideoThumbnailsWrapper and update the VideoThumbnailsWrapper to include
@ -476,7 +490,6 @@ class FileSearch {
cacheDirectory = null; cacheDirectory = null;
logger.log(Level.WARNING, "Unable to get cache directory, video thumbnails will not be saved", ex); logger.log(Level.WARNING, "Unable to get cache directory, video thumbnails will not be saved", ex);
} }
if (cacheDirectory == null || file.getMd5Hash() == null || !Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash()).toFile().exists()) { if (cacheDirectory == null || file.getMd5Hash() == null || !Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash()).toFile().exists()) {
java.io.File tempFile; java.io.File tempFile;
try { try {
@ -488,7 +501,7 @@ class FileSearch {
0, 0,
0, 0,
0}; 0};
thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); thumbnailWrapper.setThumbnails(createDefaultThumbnailList(VIDEO_DEFAULT_IMAGE), framePositions);
return; return;
} }
if (tempFile.exists() == false || tempFile.length() < file.getSize()) { if (tempFile.exists() == false || tempFile.length() < file.getSize()) {
@ -502,7 +515,7 @@ class FileSearch {
0, 0,
0, 0,
0}; 0};
thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); thumbnailWrapper.setThumbnails(createDefaultThumbnailList(VIDEO_DEFAULT_IMAGE), framePositions);
return; return;
} }
ContentUtils.writeToFile(file, tempFile, progress, null, true); ContentUtils.writeToFile(file, tempFile, progress, null, true);
@ -523,7 +536,7 @@ class FileSearch {
0, 0,
0, 0,
0}; 0};
thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); thumbnailWrapper.setThumbnails(createDefaultThumbnailList(VIDEO_DEFAULT_IMAGE), framePositions);
return; return;
} }
double fps = videoFile.get(5); // gets frame per second double fps = videoFile.get(5); // gets frame per second
@ -535,7 +548,7 @@ class FileSearch {
0, 0,
0, 0,
0}; 0};
thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); thumbnailWrapper.setThumbnails(createDefaultThumbnailList(VIDEO_DEFAULT_IMAGE), framePositions);
return; return;
} }
if (Thread.interrupted()) { if (Thread.interrupted()) {
@ -544,7 +557,7 @@ class FileSearch {
0, 0,
0, 0,
0}; 0};
thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); thumbnailWrapper.setThumbnails(createDefaultThumbnailList(VIDEO_DEFAULT_IMAGE), framePositions);
return; return;
} }
@ -573,10 +586,10 @@ class FileSearch {
logger.log(Level.WARNING, "Error seeking to " + framePositions[i] + "ms in {0}", file.getParentPath() + "/" + file.getName()); //NON-NLS logger.log(Level.WARNING, "Error seeking to " + framePositions[i] + "ms in {0}", file.getParentPath() + "/" + file.getName()); //NON-NLS
// If we can't set the time, continue to the next frame position and try again. // If we can't set the time, continue to the next frame position and try again.
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(VIDEO_DEFAULT_IMAGE);
if (cacheDirectory != null) { if (cacheDirectory != null) {
try { try {
ImageIO.write((RenderedImage) ImageUtils.getDefaultThumbnail(), THUMBNAIL_FORMAT, ImageIO.write(VIDEO_DEFAULT_IMAGE, THUMBNAIL_FORMAT,
Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS) Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS)
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex); logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex);
@ -588,10 +601,10 @@ class FileSearch {
if (!videoFile.read(imageMatrix)) { if (!videoFile.read(imageMatrix)) {
logger.log(Level.WARNING, "Error reading frame at " + framePositions[i] + "ms from {0}", file.getParentPath() + "/" + file.getName()); //NON-NLS logger.log(Level.WARNING, "Error reading frame at " + framePositions[i] + "ms from {0}", file.getParentPath() + "/" + file.getName()); //NON-NLS
// If the image is bad for some reason, continue to the next frame position and try again. // If the image is bad for some reason, continue to the next frame position and try again.
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(VIDEO_DEFAULT_IMAGE);
if (cacheDirectory != null) { if (cacheDirectory != null) {
try { try {
ImageIO.write((RenderedImage) ImageUtils.getDefaultThumbnail(), THUMBNAIL_FORMAT, ImageIO.write(VIDEO_DEFAULT_IMAGE, THUMBNAIL_FORMAT,
Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS) Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS)
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex); logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex);
@ -602,10 +615,10 @@ class FileSearch {
} }
// If the image is empty, return since no buffered image can be created. // If the image is empty, return since no buffered image can be created.
if (imageMatrix.empty()) { if (imageMatrix.empty()) {
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(VIDEO_DEFAULT_IMAGE);
if (cacheDirectory != null) { if (cacheDirectory != null) {
try { try {
ImageIO.write((RenderedImage) ImageUtils.getDefaultThumbnail(), THUMBNAIL_FORMAT, ImageIO.write(VIDEO_DEFAULT_IMAGE, THUMBNAIL_FORMAT,
Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS) Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, file.getMd5Hash(), i + "-" + framePositions[i] + "." + THUMBNAIL_FORMAT).toFile()); //NON-NLS)
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex); logger.log(Level.WARNING, "Unable to save default video thumbnail for " + file.getMd5Hash() + " at frame position " + framePositions[i], ex);
@ -660,7 +673,7 @@ class FileSearch {
videoFile.release(); // close the file} videoFile.release(); // close the file}
} }
} else { } else {
loadSavedThumbnails(cacheDirectory, thumbnailWrapper); loadSavedThumbnails(cacheDirectory, thumbnailWrapper, VIDEO_DEFAULT_IMAGE);
} }
} }
@ -674,7 +687,7 @@ class FileSearch {
* information about the file and the thumbnails * information about the file and the thumbnails
* associated with it. * associated with it.
*/ */
private static void loadSavedThumbnails(String cacheDirectory, VideoThumbnailsWrapper thumbnailWrapper) { private static void loadSavedThumbnails(String cacheDirectory, VideoThumbnailsWrapper thumbnailWrapper, BufferedImage failedVideoThumbImage) {
int[] framePositions = new int[4]; int[] framePositions = new int[4];
List<Image> videoThumbnails = new ArrayList<>(); List<Image> videoThumbnails = new ArrayList<>();
int thumbnailNumber = 0; int thumbnailNumber = 0;
@ -683,7 +696,7 @@ class FileSearch {
try { try {
videoThumbnails.add(ImageIO.read(Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, md5, fileName).toFile())); videoThumbnails.add(ImageIO.read(Paths.get(cacheDirectory, VIDEO_THUMBNAIL_DIR, md5, fileName).toFile()));
} catch (IOException ex) { } catch (IOException ex) {
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(failedVideoThumbImage);
logger.log(Level.WARNING, "Unable to read saved video thumbnail " + fileName + " for " + md5, ex); logger.log(Level.WARNING, "Unable to read saved video thumbnail " + fileName + " for " + md5, ex);
} }
int framePos = Integer.valueOf(FilenameUtils.getBaseName(fileName).substring(2)); int framePos = Integer.valueOf(FilenameUtils.getBaseName(fileName).substring(2));
@ -699,12 +712,12 @@ class FileSearch {
* *
* @return List containing the default thumbnail. * @return List containing the default thumbnail.
*/ */
private static List<Image> createDefaultThumbnailList() { private static List<Image> createDefaultThumbnailList(BufferedImage failedVideoThumbImage) {
List<Image> videoThumbnails = new ArrayList<>(); List<Image> videoThumbnails = new ArrayList<>();
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(failedVideoThumbImage);
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(failedVideoThumbImage);
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(failedVideoThumbImage);
videoThumbnails.add(ImageUtils.getDefaultThumbnail()); videoThumbnails.add(failedVideoThumbImage);
return videoThumbnails; return videoThumbnails;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB