Java Implementation of the video screenshot method [with ffmpeg download], javaffmpeg

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.