The example of this article describes the method of calling FFMPEG to implement video conversion. Share it for everyone for your reference. The specific analysis is as follows:
Here I was tested under the Windows platform. Essence Essence
You need to have 4 files in e:/below ffmpeg.exe; Mencoder.exe; DRV43260.dll; pncrt.dll.
Also put various video files named A under E:/Input; E:/Output; you can get a converted file of A.FLV after the Java program is executed.
Fempeg.exe Format: (ASX, ASF, MPG, WMV, 3GP, MP4, MOV, AVI, FLV, etc.)
For file formats (WMV9, RM, RMVB, etc.) that FFMPEG.EXE cannot be parsed, you can use other tools (MENCODER) to convert it to AVI (FFMPEG Analysis) format;
Mencoder.exe; Drv43260.dll; PNCRT.DLL This three files are prepared for file format (WMV9, RM, RMVB, etc.) to be prepared for AVI (FFMPEG can be parsed) format;
Then convert the conversion AVI file with ffmpeg.exe to a FLV format video file. Essence Essence
The content of the java file is as follows:
Import java.io.file; Import Java.util.list; Public Class Convertvideo {Private Final Static String Path = "C: //Test/a.mpg"; tring [] args) {if (if ! Checkfile (path)) {system.out.println (path+"is not file"); Return;} if (proces ()) {system.out.println ("ok");}}} cess () {int Type = CheckContentType (); Boolean Status = false; if (type == 0) {status = processflv (path); // directly convert the file to FLV file} else if (type == 1) avifilepath = Processavi (Type); if (avifilepath == NULL) Return false; // avi files do not get status = processflv (avifilepath); // Convert Avi to FLV} Return Status;} e static int CheckContentType () {string type = PATH.substring(PATH.lastIndexOf(".") + 1, PATH.length()).toLowerCase();//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.equals (" 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 ("FLV") ) {RETURN 0;} // The file format that cannot be parsed for FFMPEG (WMV9, RM, RMVB, etc.), // You can use other tools (Mencoder) to be converted to AVI (FFMPEG can be parsed) format. .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 file = new file (path); if (! File.isfile ()) {Return false;} Return true;} (WMV9, RM , RMVB, etc.), you can use other tools to convert it to AVI (FFMPEG can be parsed) format first. Private Static String Processavi (Int Type) {list <string> Comment = New Java.util.arrayList <STRIN <STRIN <STRIN g> (g> ( );; "" "e: // Mencoder"); Commend.add (PATH); Commend.add ("-OAC"); Commend.add ("LAVC"); Commend.add ("-LAVCOPTS") ; Comment.add ("Acodec = mp3: Abitrate = 64"); Comment.add ("-OVC"); Commend.add ("xvid"); Commend.add ("-Xvidencopts"); bitrate = 600 "); Commend.add (" -OF "); Commend.add (" Avi "); Commend.add ("-O "); Commend.add (" C: //home/a.avi "); Try {processBuilder Builder = New ProcessBuilder (); Builder.Command (Comment); builder.start (); Return" c: //home/a.avi "; e) {e.printstacktrace (); Return null;}} // FFMPEG can analyze the format: (ASX, ASF, MPG, WMV, 3GP, MP4, MOV, AVI, FLV, etc.) Private Static Boolean ProcessFlv (String Oldfilepath) {if (! CH! Eckfile ( Path) {system.out.println (OldFilepath+"is not file"); Return false;} list <string> comment = new java.util.arraylist <); Comment.add ("E: E: E: E: E: E: E: E: E: E: E: E: // ffmpeg "); Commend.add (" -I "); Commend.add (OldFilepath); Commend.add (" -AB "); Commend.add (" 64 "); Commend.add (" -Acodec "); .Add ("mp3"); Commend.add ("-AC"); Commend.add ("2"); Commend.add ("-Ar"); Commend.add ("22050"); "-b"); Commend.add ("230"); Commend.add ("-R"); Commend.add ("24"); Commend.add ("-iy"); Commend.add ("C : //home/a.flv "); Try {ProcessBuilder Builder = New ProcessBuilder (); Builder.Command (Comment); builder.start ();} Catch on E) {e.printstacktrace () ; Return false;}}}It is hoped that this article is helpful to everyone's Java program design.