Created
January 21, 2021 07:23
-
-
Save gagannn/32323c384046f0b19f4a7a1a693b4ed6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.overriding; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.DirectoryStream; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.UUID; | |
import javax.imageio.ImageIO; | |
import org.bytedeco.javacv.FFmpegFrameGrabber; | |
import org.bytedeco.javacv.Java2DFrameConverter; | |
public class thumbnail { | |
public static void main(String[] args) { | |
DirectoryStream.Filter<Path> filter = file -> { | |
return file.toString().endsWith(".mp4") || file.toString().endsWith(".MP4") | |
|| file.toString().endsWith(".mov") || file.toString().endsWith(".MOV"); | |
}; | |
Path dirName = Paths.get("C:\\Users\\14406\\Music\\kiosk"); | |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dirName, filter)) { | |
stream.forEach(path -> { | |
FFmpegFrameGrabber g = new FFmpegFrameGrabber(path.toString()); | |
try { | |
g.start(); | |
Java2DFrameConverter paintConverter = new Java2DFrameConverter(); | |
BufferedImage difImage = paintConverter.getBufferedImage(g.grabImage()); | |
ImageIO.write(difImage, "png", new File( | |
"C:\\Users\\14406\\Music\\kiosk\\video-frame-" + UUID.randomUUID().toString() + ".png")); | |
g.stop(); | |
g.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
}); | |
} catch (IOException e1) { | |
e1.printStackTrace(); | |
} | |
} | |
} | |
//Dependency for pom.xml | |
<dependency> | |
<groupId>org.bytedeco</groupId> | |
<artifactId>javacv-platform</artifactId> | |
<version>1.3.1</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment