) JSP core Java method for automatically converting videos to FLV after uploading

Source: Internet
Author: User
Tags flv file
Summary

Author: Gucci flying e

Blog: www.v246.com

QQ: 28095553

Email: aquaqu (circle. a) gmail.com

This article is original from the ancient brake flying e. For more information, see the source!

The following is the source code:

[Full text]

Author: Gucci flying e

Blog: www.v246.com

QQ: 28095553

Email: aquaqu (circle. a) gmail.com

This article is original from the ancient brake flying e. For more information, see the source!

This method has been verified by practice, is being used in the project, you can view later: http://www.0431net.com, the core function of the website video mode is to use this method to achieve fast :)

The following is the source code:

Cnvert class

Package com. v246.convertflv;

Import java. util. arraylist;
Import java. util. List;

Import com. v246.utils. aqu;

// Author: Furukawa blog: www.v246.com lazy Mode
Public class convert {

Private Static convert instance = NULL;

// Author: the absolute address of the FLV tool at www.v246.com
Private string aquinterceptpictoolspath = "C: \ flvtools \ ffmpeg.exe ";

// Author: Furukawa blog: absolute address of www.v246.com FLV Repair Tool
Private string fixflvtoolspath = "C :\\ flvtools \ flvmdi.exe ";

// Author: Furukawa blog: absolute address of the FLV Conversion Tool www.v246.com
Private string aqucoverflvtoolspath = "C: \ flvtools \ mencoder \ mencoder.exe ";

Private convert (){
// Author: Furukawa blog: www. v246.cominit ();
}

Public static convert getinstance (){
If (instance = NULL ){
Instance = new convert ();
}
Return instance;
}
Public void reset (){
// Author: Furukawa blog: www. v246.cominit ();
}
Private void Init (){
/* Aquinterceptpictoolspath = aqu. getxmlvalue ("convertflv. xml ",
"// Author: Gu Sha flying e blog: www.v246.com full path of Gu Sha flying e/FLV Conversion Tool") [0];
Fixflvtoolspath = aqu
. Getxmlvalue ("convertflv. xml", "// Author: Gucci flying e blog: www.v246.com full path of Gucci flying e/FLV tool") [0];
Aqucoverflvtoolspath = aqu. getxmlvalue ("convertflv. xml ",
"// Author: Gu Sha flying e blog: www.v246.com full path of Gu Sha flying e/FLV Repair Tool") [0];
Aquinterceptpictoolspath = aquinterceptpictoolspath. Replace ("/","\\");
Fixflvtoolspath = fixflvtoolspath. Replace ("/","\\");
Aqucoverflvtoolspath = aqucoverflvtoolspath. Replace ("/","\\");
System. Out. println (aquinterceptpictoolspath );
System. Out. println (fixflvtoolspath );
System. Out. println (aqucoverflvtoolspath );*/

}

Public synchronized Boolean convert (string aquinputpath, string outpath ){
Boolean Re = false;
// Author: Gu Sha flying e blog: www.v246.com, a path Locator
Aquinputpath = aquinputpath. Replace ("/","\\");
// Author: Gu Sha flying e blog: www.v246.com, a path Locator
Outpath = outpath. Replace ("/","\\");
// Author: Furukawa blog: www.v246.com analyzes the output path that does not contain the file name
String interceptpicsavepath = outpath. substring (0, outpath
. Lastindexof ("\") + 1 );
// Author: Gu Sha flying e blog: name of the file output by analysis on www.v246.com
String outfilename = outpath. substring (outpath. lastindexof ("\") + 1,
Outpath. Length ());
// Author: Gu Sha flying e blog: www.v246.com continue to analyze the file name that does not contain the extension
String outfilenamenoext = outfilename. substring (0, outfilename
. Lastindexof ("."));

// Author: Furukawa blog: www.v246.com working directory, set as needed
// Author: Furukawa blog: www.v246.com string workdirectory = "C: \ Windows \ Temp ";
// Author: Gu Sha flying e blog: www.v246.com repair command
List <string> parameterforfix = new arraylist <string> (100 );
// Author: Furukawa blog: www.v246.com conversion command
List <string> aquparameterforconvert = new arraylist <string> (100 );
// Author: Gu Sha flying e blog: www.v246.com command
List <string> aquparameterforintercept = new arraylist <string> (100 );
// Author: Furukawa blog: www.v246.com build conversion command
Aquparameterforconvert. Add (aqucoverflvtoolspath );
Aquparameterforconvert. Add ("-VF ");
Aquparameterforconvert. Add ("scale = 320: 240 ");
Aquparameterforconvert. Add ("-ffourcc ");
Aquparameterforconvert. Add ("flv1 ");
Aquparameterforconvert. Add ("-");
Aquparameterforconvert. Add ("lavf ");
Aquparameterforconvert. Add ("-lavfopts ");
Aquparameterforconvert
. Add ("I _certify_that_my_video_stream_does_not_use_ B _frames ");
Aquparameterforconvert. Add ("-OVC ");
Aquparameterforconvert. Add ("lavc ");
Aquparameterforconvert. Add ("-lavcopts ");
Aquparameterforconvert. Add ("vcodec = FLV: vbitrate = 200 ");
Aquparameterforconvert. Add ("-srate ");
Aquparameterforconvert. Add ("22050 ");
Aquparameterforconvert. Add ("-OAC ");
Aquparameterforconvert. Add ("lavc ");
Aquparameterforconvert. Add ("-lavcopts ");
Aquparameterforconvert. Add ("acodec = MP3: abitrate = 56 ");
Aquparameterforconvert. Add (aquinputpath );
Aquparameterforconvert. Add ("-o ");
Aquparameterforconvert. Add (outpath );

// Author: Gu Sha flying e blog: www.v246.com build repair command
Parameterforfix. Add (fixflvtoolspath );
Parameterforfix. Add (outpath );
// Author: Furukawa blog: www.v246.com build command
Aquparameterforintercept. Add (aquinterceptpictoolspath );
Aquparameterforintercept. Add ("-I ");
Aquparameterforintercept. Add (outpath );
Aquparameterforintercept. Add ("-y ");
Aquparameterforintercept. Add ("-F ");
Aquparameterforintercept. Add ("image2 ");
Aquparameterforintercept. Add ("-SS ");
Aquparameterforintercept. Add ("8 ");
Aquparameterforintercept. Add ("-T ");
Aquparameterforintercept. Add ("0.001 ");
Aquparameterforintercept. Add ("-s ");
Aquparameterforintercept. Add ("320x240 ");
Aquparameterforintercept. Add (interceptpicsavepath + outfilenamenoext
+ ". Jpg ");
// Author: Furukawa blog: www.v246.com Conversion
String tmp1 = aqu.exe C (aquparameterforconvert );
// Author: Furukawa blog: www.v246.com
String tmp2 = aqu.exe C (aquparameterforintercept );
Return re;
}

Public static void main (string [] ARGs ){
Getinstance (). Convert ("H :\\ qq28095553 \. wmv", "H :\\ aquaqu (quana) gmail.com \. FLV ");
}
}

Convertthread class

Package com. v246.convertflv;

Public class convertthread extends thread {
 
Private string frompath = NULL;
Private string topath = NULL;
@ Override
Public void run (){
Convert. getinstance (). Convert (frompath, topath );
}
Public void setfrompath (string frompath ){
This. frompath = frompath;
}
Public void settopath (string topath ){
This. topath = topath;
}
}

 

Convertthreadproxy class:

Package com. v246.convertflv;

Public class convertthreadproxy {
Public static void convert (string frompath, string topath ){
Convertthread Ct = new convertthread ();
Ct. setfrompath (frompath );
Ct. settopath (topath );
Ct. Start ();
}
}

 

 

When using this function, you only need to use the static method of the convertthreadproxy class to set the absolute address of the Source Video (including the file name + display name) and the absolute address of the FLV file to be generated (including the file name + display name) it can be passed in as a string! Because multithreading is used, the conversion process does not occupy the current thread!

The core conversion class is thread-synchronous, so you don't have to worry about the parallel problem, because only one file can be converted at a time!

Note: install and use FFMPEG to convert the video to a FLV file (Windows and Linux)
Use a Java program to call FFMPEG to convert the video file format to FLV

Source: http://www.v246.com/html/182.html

Related Article

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.