Java uses FFMPEG to convert a video to a FLV File

Source: Internet
Author: User

Package COM. alpha. vedio; import Java. io. file; import Java. util. arraylist; import Java. util. calendar; import Java. util. list;/*** convert any video format to FLV * @ author javaalpha * @ date 2011-10-20 * @ Version V 1.0 */public class testvedio {public static Boolean Process (string resourcepath) {int type = checkcontenttype (resourcepath); Boolean status = false; If (type = 0) {status = processflv (resourcepath); // convert the file directly to FLV} Else if (type = 1) {status = processflv (resourcepath); // convert rmvb to FLV} return status;} Private Static int checkcontenttype (string resourcepath) {string type = resourcepath. substring (resourcepath. lastindexof (". ") + 1, resourcepath. length ()). tolowercase (); // formats that can be parsed by FFMPEG: (ASX, ASF, mpg, WMV, 3GP, MP4, mov, Avi, FLV, etc.) if (type. equals ("Avi") {return 0;} else if (type. equals ("MPG") {return 0;} else if (type. E Quals ("WMV") {return 0;} else if (type. equals ("3GP") {return 0;} else if (type. equals ("mov") {return 0;} else if (type. equals ("MP4") {return 0;} else if (type. equals ("ASF") {return 0;} else if (type. equals ("ASX") {return 0;} else if (type. equals ("FLV") {return 0;} else if (type. equals ("MPEG") {return 0;} else if (type. equals ("MPE") {return 0;} // format of files that cannot be parsed by FFMPEG (wmv9, RM, rmvb, etc.). // you can use other tools first. (Mencoder) to AVI (which can be parsed by FFMPEG) format. else if (type. equals ("wmv9") {return 1;} else if (type. equals ("RM") {return 1;} else if (type. equals ("rmvb") {return 1;} return 9;} Private Static Boolean checkfile (string path) {file = new file (PATH); If (! File. isfile () {return false;} return true;} // formats that can be parsed by FFMPEG: (ASX, ASF, mpg, WMV, 3GP, MP4, mov, Avi, FLV, etc) @ suppresswarnings ("unchecked") Private Static Boolean processflv (string resourcepath) {If (! Checkfile (resourcepath) {system. out. println (resourcepath + "is not file"); Return false;} // file name: Calendar c = calendar ar. getinstance (); string savename = string. valueof (C. gettimeinmillis () + math. round (math. random () * 100000); List commend = new arraylist (); commend. add ("E: \ FFMPEG"); commend. add ("-I"); commend. add (resourcepath); commend. add ("-AB"); commend. add ("56"); commend. add ("-AR"); commend. add ("22050 "); Commend. add ("-qscale"); commend. add ("8"); commend. add ("-R"); commend. add ("15"); commend. add ("-s"); commend. add ("600x500"); commend. add ("E: \" + savename + ". FLV "); try {runtime = runtime. getruntime (); process proce = NULL; string cmd = ""; string cut = "E: // ffmpeg.exe-I "+ resourcepath +"-y-F image2-SS 8-T 0.001-s 600x500 E: \ "+ savename + ". jpg "; string cutcmd = cmd + cut; proce = runtime. ex EC (cutcmd); processbuilder builder = new processbuilder (commend); // builder. command (commend); builder. start (); Return true;} catch (exception e) {e. printstacktrace (); Return false ;}} public static void main (string [] ARGs) {If (! Checkfile ("E: \ fly. avi ") {system. out. println ("" + "is not file"); return;} If (process ("E: \. MPG ") {system. out. println ("OK ");}}}

Required Video Processing Software: ffmpeg.exe:

Click Open Link

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.