Decode videos
Regarding the problem #1, there is no magic solution to read images of whichever video format.
Each video format needs a specific algorithm to interpret it and hardly a single implementation will cover all formats.
Even if some libraries (or group of libraries) can read several common formats, there are always some proprietary formats or variations that end up causing problems.
Approaches
Two basic solutions for miniatures would be:
Pre-store the thumbnails
Store thumbnails along with video files.
If you have any control over how video files are generated or included in the directory, this would be the best solution.
Use any tool via command line to generate the thumbnail and make your Java program simple and fast.
Generate the thumbnail on demand
This is the possible approach when you have no control over the videos.
Decoding the video from your program may be convenient on the one hand, but keep in mind that it will greatly increase the complexity of the program and potentially affect performance in a very negative way. Think about rendering 500 videos from any folder.
You may need to create a queue to process videos and work with different threads not to crash the program and allow cancellation in case the user does not want to wait for the operation to end.
Xuggler
I don’t understand what’s wrong with keeping the libraries used by xuggler. Many programs and tools accompany different libraries.
The argument of "having to control it later" makes no sense because any dependency added to your project will have to be managed.
What exactly is the difficulty in control if you put libraries together with your program when distributing?
From what I read in documentation, xuggler is a wrapper for native FFMPEG libraries, used in many projects. The advantage of using these libraries is that they already have maturity and are reliable.
Jcodec
Another alternative would be Jcodec, an implementation made purely in Java.
The first page already brings an example of how to extract a frame from the video to an image:
int frameNumber = 150;
BufferedImage frame = FrameGrab.getFrame(new File("arquivo.mp4"), frameNumber);
ImageIO.write(frame, "png", new File("frame_150.png"));
However, as expected from a less used library, it supports few formats: AVC, H.264 in MP4, ISO BMF and Quicktime. I suppose she also has less adherence to variations of these formats.
Although there are recent updates in this library, probably the updates to new or even existing formats will be few or more time consuming, since there doesn’t seem to be much involvement in the project.
Problem with listFiles()
The problem with the listFiles
can be caused if the Java process does not have permissions to read from the folder.
It may also be that the directory you passed is invalid. For example, I ran a test by passing ~
(user directory) and did not work. However, passing the absolute path did work.
It would also use the newest Java API. Example:
//extensões aceitas
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.{txt,log}");
//diretório de busca
Path diretorio = Paths.get("/my/dir");
//permite links simbólicos
EnumSet<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
//navega no diretório
Files.walkFileTree(diretorio, options, 1,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//verifica se não é um diretório e se tem uma das extensões esperadas
if (!attrs.isDirectory() && matcher.matches(file.getFileName())) {
System.out.println(file.toString());
}
return super.visitFile(file, attrs);
}
});
See relevant documentation on walkFileTree
and on the PathMatcher
.
Considerations
Define the best approach to your case and remember that any of them will have their positives and negatives.
No one has any idea?
– Wilson Tamarozzi
Question #1 looks like a duplicate of this http://answall.com/questions/95988/pega-imagem-preview-de-um-v%C3%Addeo-listfiles-n%C3%A3o-funciona
– utluiz