Java call command to achieve the video upload process automatically converted to FLV format and screenshot to generate thumbnails

Source: Internet
Author: User
Tags file size stringbuffer

Video upload process automatically converted to FLV format and screenshot to generate thumbnails (Java Invoke command implementation)
Import java.util.ArrayList;
Import java.util.List;

public class Videoprocess {

System.out.println (oldfilepath+ "->" +newfilename+ "->" +newimg);
list<string> commendf = new arraylist<string> ();
List<string> commendi=new java.util.arraylist<string> ();

Commendf.add ("D://tools//mencoder//mencoder");
Commendf.add (Oldfilepath);
Commendf.add ("-O");
Commendf.add (NewFileName);
Commendf.add ("-of");
Commendf.add ("Lavf");
Commendf.add ("-oac");
Commendf.add ("Mp3lame");
Commendf.add ("-lameopts");
Commendf.add ("abr:br=32:vol=1");
Commendf.add ("-srate");
Commendf.add ("22050");
Commendf.add ("-OVC");
Commendf.add ("LAVC");
Commendf.add ("-lavcopts");
Commendf.add ("Vcodec=flv:vbitrate=480:mbd=2:v4mv:turbo:vb_strategy=1:last_pred=2:trell");
C Ommendf.add ("-VF");
Commendf.add ("scale=400:226");

Commendi.add ("D://tools//ffmpeg");
Commendi.add ("I");
Commendi.add (Oldfilepath);
Commendi.add ("Y");
Commendi.add ("-f");
Commendi.add ("Image2");
Commendi.add ("-SS");
Commendi.add ("8");
Commendi.add ("-t");
Commendi.add ("0.001");
Commendi.add ("-S");
Commendi.add ("100x100");
Commendi.add (NEWIMG);

try {

Processclass.exec (COMMENDF);
Processclass.exec (Commendi);

return true;
catch (Exception e) {
E.printstacktrace ();
return false;
}
}

public static void Main (string[] args) {
String Oldfilepath = "D://video//a1.avi";
String newfilename = "d://video//a1.flv";
String newimg = "D://video//a1.jpg";

ProcessTransToImg2 (OLDFILEPATH,NEWFILENAME,NEWIMG);
System.out.println ("over");
}
}
Processclass.java
Import java.io.IOException;
Import java.util.ArrayList;
Import Java.util.Iterator;
Import java.util.List;


public class processclass{
Public list<string> commendlist = new arraylist<string> ();
Public Processclass (list<string> commendlist) {
This.commendlist = commendlist;
}
Synchronization allows only one process to execute the method (the screenshot process is implemented after the format conversion process is completed)
public static synchronized Process exec (list<string> commendlist) {
StringBuffer strbuf = new StringBuffer ();
For (iterator Iter =commendlist.iterator (); Iter.hasnext ();) {
String strtemp = (string) iter.next ();
Strbuf.append (strtemp);
Strbuf.append ("");
}

try {
Return Runtime.getruntime (). EXEC (strbuf.tostring ());
catch (IOException e) {
E.printstacktrace ();
return null;
}
}
}

This is not a perfect procedure, there are some problems:

1, because of the command parameters in the ffmpeg I do not know, for the command of the parameter value is not the best choice, I am in the process of conversion after the file size is larger than the original file.

2, if you do not see the resulting picture after conversion, you can try to modify

Commendi.add ("100x100"); The value inside this.

When I set it to 100x75 in the program, I don't generate a picture, and when I set it to 100x100, I can see the picture generated.

On the internet to see a friend to the example set to 320x240, but in my project feel the picture is too large, affecting the overall beauty. You can try it yourself.

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.