This article describes the Java method to screenshot videos. Share it for your reference, as follows:
I have introduced Java to use ffmpeg for video conversion before. Here I will demonstrate how ffmpeg performs video screenshots.
The specific code is as follows:
import java.io.File;import java.util.List;//The first frame of the generated video file is the picture//The version under windows public class CreatePh { // public static final String FFMPEG_PATH = "E:/ffmpeg/ffmpeg.exe"; public static boolean processImg(String veido_path, String ffmpeg_path) { File file = new File(veido_path); if (!file.exists()) { System.err.println("Path[" + veido_path + "] corresponding video file does not exist!"); return false; } List<String> commands = new java.util.ArrayList<String>(); commands.add(ffmpeg_path); commands.add("-i"); commands.add(veido_path); commands.add("-y"); commands.add("-f"); commands.add("-f"); commands.add("image2"); commands.add("-ss"); commands.add("8");// This parameter is the screen when the video is intercepted for how many seconds// commands.add("-t"); // commands.add("0.001"); commands.add("-s"); commands.add("700x525"); commands.add(veido_path.substring(0, veido_path.lastIndexOf(".")) .replaceFirst("vedio", "file") + ".jpg"); try { ProcessBuilder builder = new ProcessBuilder(); builder.command(commands); builder.start(); System.out.println("Intercepted successfully"); return true; } catch (Exception e) { e.printStackTrace(); return false; } } public static void main(String[] args) { processImg("C:/video1.avi", "C:/ffmpeg.exe"); }}The screenshot after running is as follows:
Attached:
ffmpeg.exe click here to download this site .
Click here to download the test video in AV format.
For more Java-related content, readers who are interested in this site can view the topics: "Summary of Java Image Operation Skills", "Summary of Java Date and Time Operation Skills", "Summary of Java Operation DOM Node Skills", "Summary of Java File and Directory Operation Skills" and "Tutorials of Java Data Structure and Algorithm".
I hope this article will be helpful to everyone's Java programming.