JAVE 官方的jar包帶了ffmpeg的exe程序,因此在windows上能夠直接使用,可是若是要在Linux上用就得先把ffmpeg的環境裝好。 php
官方的jar包在這裏下載:http://www.sauronsoftware.it/projects/jave/download.php java
在這裏列幾個官方的demo: windows
一、From a generic AVI to a youtube-like FLV movie, with an embedded MP3 audio stream: ide
File source = new File("source.avi"); File target = new File("target.flv"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(new Integer(64000)); audio.setChannels(new Integer(1)); audio.setSamplingRate(new Integer(22050)); VideoAttributes video = new VideoAttributes(); video.setCodec("flv"); video.setBitRate(new Integer(160000)); video.setFrameRate(new Integer(15)); video.setSize(new VideoSize(400, 300)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("flv"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
File source = new File("source.avi"); File target = new File("target.wav"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("pcm_s16le"); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("wav"); attrs.setAudioAttributes(audio); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
File source = new File("source.wav"); File target = new File("target.mp3"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(new Integer(128000)); audio.setChannels(new Integer(2)); audio.setSamplingRate(new Integer(44100)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); attrs.setAudioAttributes(audio); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
File source = new File("source.avi"); File target = new File("target.avi"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(new Integer(56000)); audio.setChannels(new Integer(1)); audio.setSamplingRate(new Integer(22050)); VideoAttributes video = new VideoAttributes(); video.setCodec(VideoAttributes.DIRECT_STREAM_COPY); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("avi"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
File source = new File("source.avi"); File target = new File("target.avi"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libvorbis"); VideoAttributes video = new VideoAttributes(); video.setCodec("mpeg4"); video.setTag("DIVX"); video.setBitRate(new Integer(160000)); video.setFrameRate(new Integer(30)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mpegvideo"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
六、A smartphone suitable video: 工具
File source = new File("source.avi"); File target = new File("target.3gp"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libfaac"); audio.setBitRate(new Integer(128000)); audio.setSamplingRate(new Integer(44100)); audio.setChannels(new Integer(2)); VideoAttributes video = new VideoAttributes(); video.setCodec("mpeg4"); video.setBitRate(new Integer(160000)); video.setFrameRate(new Integer(15)); video.setSize(new VideoSize(176, 144)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("3gp"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs);
這裏發兩個其它的博客地址,你們能夠參考下: 優化
http://mfan.iteye.com/blog/2032454 ui
http://blog.csdn.net/qllinhongyu/article/details/29817297 spa