Use FFMPEG to convert video files to FLV <Article 6>

Source: Internet
Author: User
Tags flv file

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. % 1/FFMPEG-I % 2-y-AB 56-ar 22050-B 500-R 15-s 320 * 240% 3
  2. 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
  1. [Capture the thumbnail while converting the file format]
  2. FFmpeg-I "test. Avi"-y-F image2-SS 8-T 0.001-s 350x240 "test.jpg"
  3. [Capture existing FLV images]
  4. FFmpeg-I "test. FLV "-y-F image2-SS 8-T 0.001-s 350x240" test.jpg "<br> ****************
  5. -SS followed by time in seconds
  6. ****************

 

4. Create a class

 

[Java]View plaincopy
  1. Public class convertvideo
  2. {
  3. Private Static string input_path;
  4. Private Static string output_path;
  5. Private Static string project_path;
  6. Private Static hashmap <string, string> filetype;
  7. Static
  8. {
  9. Filetype = new hashmap <string, string> ();
  10. Filetype. Put ("Avi", "true ");
  11. Filetype. Put ("MPG", "true ");
  12. Filetype. Put ("WMV", "true ");
  13. Filetype. Put ("3GP", "true ");
  14. Filetype. Put ("mov", "true ");
  15. Filetype. Put ("MP4", "true ");
  16. Filetype. Put ("ASF", "true ");
  17. Filetype. Put ("ASX", "true ");
  18. Filetype. Put ("FLV", "true ");
  19. }
  20. Public static void converttoflv (string projectpath, string inputfile, string outputfile)
  21. {
  22. Input_path = inputfile;
  23. Output_path = outputfile;
  24. Project_path = projectpath;
  25. If (checkcontenttype ())
  26. Processflv (); // directly convert the file into a FLV File
  27. }
  28. Private Static Boolean checkcontenttype ()
  29. {
  30. String type = input_path.substring (input_path.lastindexof (".") + 1, input_path.length (). tolowercase ();
  31. // Formats that can be parsed by FFMPEG: (ASX, ASF, mpg, WMV, 3GP, MP4, mov, Avi, and FLV)
  32. Return "true". Equals (filetype. Get (type ));
  33. }
  34. Private Static void processflv ()
  35. {
  36. If (new file (input_path). isfile ())
  37. {
  38. Try
  39. {
  40. String cmd = "CMD/C start X: // FFMPEG. BAT/"" + project_path + "/"/"" + input_path + "/"/"" + output_path + "/"";
  41. Runtime.getruntime(cmd.exe C (CMD );
  42. }
  43. Catch (exception E)
  44. {
  45. E. printstacktrace ();
  46. }
  47. }
  48. }
  49. }

 

 

5. Test code

[Java]View plaincopy
  1. Public static void main (string [] ARGs)
  2. {
  3. Convertvideo. converttoflv ("X: // convertvideo", "X: // A. wmv", "X: // A. FLV ");
  4. }

 

 

JS Code
[JavaScript]View plaincopy
  1. Varswf_width = "100% ";
  2. VaR swf_height = "100% ";
  3. VaR files = 'nba. flv ';
  4. 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 ';
  5. VaR texts = 'nba highlights top 10 ';
  6. 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 + '"> ');
  7. Document. Write ('<Param name = "movie" value = "vcastr2.swf"/> ');
  8. Document. Write ('<Param name = "quality" value = "high"/> ');
  9. Document. Write ('<Param name = "menu" value = "false"/> ');
  10. Document. Write ('<Param name = wmode value = "Opaque"/> ');
  11. Document. write ('<Param name = "flashvars" value = "vcastr_file =' + files + '& vcastr_title =' + texts + '& vcastr_config =' + config + '"> ');
  12. 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"/> ');
  13. 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>

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.