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