Java implementation of video methods [with ffmpeg download], javaffmpeg
This example describes how to implement video in Java. We will share this with you for your reference. The details are as follows:
I have introduced how to use ffmpeg for video conversion in Java. Here I will demonstrate how to use ffmpeg for video conversion.
The Code is as follows:
Import java. io. file; import java. util. list; // the first frame of the generated video file is the image // public class CreatePh in windows {// 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 + "] the 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 ("image2"); commands. add ("-ss"); commands. add ("8"); // This parameter sets the number of seconds when a video is captured. // 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 following code is displayed after running:
Appendix:
Ffmpeg.exe click hereDownload from this site.
Test video in avi format click hereDownload from this site.
For more java-related content, refer to this topic: java image operation skills summary, java Date and Time Operation Skills summary, Java operation DOM node skills summary, Java file and directory operation skills summary, and Java data structure and algorithm tutorial.
I hope this article will help you with java programming.