Java Video Conversion Those things

Source: Internet
Author: User

Java Video Conversion in two ways, basically is based on the FFmpeg plug-in, the current online Java Video conversion is basically called plug-ins, spelling commands, to achieve the conversion of video format, but this way in the local is good, but when running on the WebLogic server, there will be problems, The main reason is that Windows and Linux systems differ in the format of the FFmpeg plugin. If you are running on a WebLogic server, you will need to go to the FFmpeg website to download the Linux version of the plugin.

First, record the first code address for video format conversion using the FFmpeg plug-in method:

Https://www.cnblogs.com/tohxyblog/p/6640786.html

? Secondly, the main record under the use of Jave jar video format conversion method, because the way to call the jar package, do not need to consider the different operating system problems, in the video format conversion, the Jave official API is English, not very good understanding, it should be noted that the video is divided into two parts: audio and image, Where the image part of the video format and video encoding, the current small video and live are encoded in the H264 encoding format in the decoding video, so if you need to convert to MP4 format video files, if the site display black screen But there is sound, The main reason is that the video codec format does not match. So the next thing I use in the conversion method is the FLV format, mainly because FLV does not involve this aspect, but the disadvantage is that FLV generates more video than the original video file, resulting in less efficient network transmission.

Private Boolean process (String inputpath,string OutputPath) {

try {

Logger.info ("---------Video conversion started-------------");

File Source = new file (InputPath);

File target = new file (OutputPath);

Long startTime = System.currenttimemillis (); Get Start time

Audioattributes audio = new Audioattributes ();

Audio.setcodec ("Libmp3lame"); Set encoder

Audio.setbitrate (New Integer (64000)); Set bit rate

Audio.setchannels (New Integer (1)); Set up sound channels

Audio.setsamplingrate (New Integer (22050)); Set the excerpt rate

Videoattributes video = new Videoattributes ();

Video.setcodec ("flv"); Set encoder

Video.setbitrate (New Integer (600000)); Set bit rate

Video.setframerate (New Integer (15)); Set frame rate

Video.setsize (New Videosize (640, 480)); Set resolution

Video.settag ("libx264");

Encodingattributes attrs = new Encodingattributes ();

Attrs.setformat ("flv");

Attrs.setaudioattributes (audio);

Attrs.setvideoattributes (video);

Encoder Encoder = new Encoder ();

Encoder.encode (source, target, attrs);

Long endTime = System.currenttimemillis (); Get End time

Logger.info ("---------video conversion successful, time consuming:" + ((endtime-starttime)/1000.00) + "s----------");

return true;

} catch (Exception e) {

Logger.info ("Video conversion Exception:" +e.getmessage ());

return false;

}

}?

Java Video Conversion those things

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.