1. First download FFMPEG
2. decompress the decompressed ffmpeg.exe and pthreadgc2.dll files to any directory (of course, it can also be a directory in webroot)
3. Create the BAT file convertvideo. BAT and add the following content: (for parameter descriptions, see Appendix 1)
[TXT]View plaincopy
- % 1/FFMPEG-I % 2-y-AB 56-ar 22050-B 500-R 15-s 320 * 240% 3
- Exit
******************
% 1 is the FFMPEG storage directory
% 2 is the file path to be converted
% 3 is the output directory of the FLV file.
******************
Note that the path of the BAT file cannot contain spaces.
[Capture the thumbnail while converting the file format]
FFmpeg-I "test. Avi"-y-F image2-SS 8-T 0.001-s 350x240 "test.jpg"
[Capture existing FLV images]
FFmpeg-I "test. FLV"-y-F image2-SS 8-T 0.001-s 350x240 "test.jpg"
****************
-SS followed by time in seconds
****************
[TXT]View plaincopy
- [Capture the thumbnail while converting the file format]
- FFmpeg-I "test. Avi"-y-F image2-SS 8-T 0.001-s 350x240 "test.jpg"
- [Capture existing FLV images]
- FFmpeg-I "test. FLV "-y-F image2-SS 8-T 0.001-s 350x240" test.jpg "<br> ****************
- -SS followed by time in seconds
- ****************
4. Create a class
[Java]View plaincopy
- Public class convertvideo
- {
- Private Static string input_path;
- Private Static string output_path;
- Private Static string project_path;
- Private Static hashmap <string, string> filetype;
- Static
- {
- Filetype = new hashmap <string, string> ();
- Filetype. Put ("Avi", "true ");
- Filetype. Put ("MPG", "true ");
- Filetype. Put ("WMV", "true ");
- Filetype. Put ("3GP", "true ");
- Filetype. Put ("mov", "true ");
- Filetype. Put ("MP4", "true ");
- Filetype. Put ("ASF", "true ");
- Filetype. Put ("ASX", "true ");
- Filetype. Put ("FLV", "true ");
- }
- Public static void converttoflv (string projectpath, string inputfile, string outputfile)
- {
- Input_path = inputfile;
- Output_path = outputfile;
- Project_path = projectpath;
- If (checkcontenttype ())
- Processflv (); // directly convert the file into a FLV File
- }
- Private Static Boolean checkcontenttype ()
- {
- String type = input_path.substring (input_path.lastindexof (".") + 1, input_path.length (). tolowercase ();
- // Formats that can be parsed by FFMPEG: (ASX, ASF, mpg, WMV, 3GP, MP4, mov, Avi, and FLV)
- Return "true". Equals (filetype. Get (type ));
- }
- Private Static void processflv ()
- {
- If (new file (input_path). isfile ())
- {
- Try
- {
- String cmd = "CMD/C start X: // FFMPEG. BAT/"" + project_path + "/"/"" + input_path + "/"/"" + output_path + "/"";
- Runtime.getruntime(cmd.exe C (CMD );
- }
- Catch (exception E)
- {
- E. printstacktrace ();
- }
- }
- }
- }
5. Test code
[Java]View plaincopy
- Public static void main (string [] ARGs)
- {
- Convertvideo. converttoflv ("X: // convertvideo", "X: // A. wmv", "X: // A. FLV ");
- }
JS Code
[JavaScript]View plaincopy
- Varswf_width = "100% ";
- VaR swf_height = "100% ";
- VaR files = 'nba. flv ';
- VaR Config = '0: automatic playback | 1: continuous playback | 100: Default volume | 0: control bar position | 2: control bar display | 0x000033: subject color | 60: subject transparency | 0x66ff00: Halo color | 0 xffffff: icon color | 0 xffffff: text color |: logo text |: logo address |: End SWF address ';
- VaR texts = 'nba highlights top 10 ';
- Document. write ('<object classid = "CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000" codebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width = "' + swf_width + '" Height = "' + swf_height + '"> ');
- Document. Write ('<Param name = "movie" value = "vcastr2.swf"/> ');
- Document. Write ('<Param name = "quality" value = "high"/> ');
- Document. Write ('<Param name = "menu" value = "false"/> ');
- Document. Write ('<Param name = wmode value = "Opaque"/> ');
- Document. write ('<Param name = "flashvars" value = "vcastr_file =' + files + '& vcastr_title =' + texts + '& vcastr_config =' + config + '"> ');
- Document. write ('<embed src = "vcastr2.swf" mce_src = "vcastr2.swf"/> "wmode =" Opaque "flashvars =" vcastr_file =' + files + '& vcastr_title =' + texts + '& vcastr_config =' + config + '"menu =" false "Quality =" high "width ="' + swf_width + '"Height ="' + swf_height + '"type = "Application/X-Shockwave-flash" pluginspage = "http://www.macromedia.com/go/getflashplayer"/> ');
- Document. Write ('</Object> ');
[Note] If you encounter video formats other than those involved in FFMPEG, you can use other conversion tools to convert them first, such as mencoder.
Appendix 1 (FFMPEG parameter description ):
[Parameters] |
[Description] |
[Example] |
-I "path" |
Specify the file path to be converted |
-I "C:/NBA. wmv" |
-Y |
Overwrite the output file, that is, if the NBA. xxx file already exists, directly overwrite it |
|
Control screen parameters |
-Bitexac |
Use standard Bit Rate |
|
-Vcodec Xvid |
Use Xvid for compression |
|
-S <aspect ratio> |
Resolution size |
-S 320*240 |
-R <value> |
Frame Rate (non-standard values will cause audio and video to be not synchronized [standard value: 15 or 29.97 ]) |
-R 15 |
-B <bit rate> |
Specify the compression Bit Rate |
-B 1500 |
-Qmin <value> |
Set minimum quality |
-Qmin 10 |
-Qmax <value> |
Opposite to-qmin, it can be used together with-qmin |
-Qmax 30 |
-Sameq |
Use the same quality as the source video |
|
Control sound Parameters |
-Acodec AAC |
Set sound Encoding |
|
-AC <value> |
Set the number of channels: 1 for single channel, 2 for stereo |
-AC 2 |
-Ar <sampling rate> |
Set the sound sampling rate (22050) |
-Ar 22050 |
-AB <bit rate> |
Set the sound bit rate (-ac must be set to half the bit rate when set to stereo, for example, 96 for Kbps) |
-AB 96 |
-Vol <percentage> |
Set the volume. For example, set 200 to 2 times the original volume. |
-Vol 200 |
Blog Source: http://www.javaeye.com/topic/333994
Use FFMPEG to convert video files to FLV <Article 6>