import java.io.File; import it.sauronsoftware.jave.AudioAttributes; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.EncoderException; import it.sauronsoftware.jave.EncodingAttributes; import it.sauronsoftware.jave.VideoAttributes; import it.sauronsoftware.jave.VideoSize; public class FfmepgUtil { public static void ffmepg(String sourceAddr, String targetAddr, String codec, int bitRate, String format) { File source = new File(sourceAddr); File target = new File(targetAddr); try { AudioAttributes audio = new AudioAttributes();// 音频属性 audio.setCodec("libmp3lame");// libfaac PGM编码 // audio.setBitRate(new Integer(128000));// 音频比特率 // audio.setChannels(new Integer(2));// 声道 // audio.setSamplingRate(new Integer(44100));// 采样率 VideoAttributes video = new VideoAttributes();// 视频属性 video.setCodec(codec);// 视频编码 video.setBitRate(new Integer(bitRate));// 视频比特率 // video.setFrameRate(new Integer(30));// 帧率 // video.setSize(new VideoSize(1920,1080));// 视频宽高 EncodingAttributes attrs = new EncodingAttributes();// 转码属性 attrs.setFormat(format);// 视频格式 attrs.setAudioAttributes(audio);// 音频属性 attrs.setVideoAttributes(video);// 视频属性 Encoder encoder = new Encoder();// 创建解码器 encoder.encode(source, target, attrs); System.out.println("上传成功!!!"); } catch (EncoderException e) { e.printStackTrace(); System.out.println("文件格式不正确!"); } } } public class FfmepgDemo { public static void main(String[] args) { File source = new File("D:/xxx.mp4"); File target = new File("D:/xxx1.mp4"); try{ 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("mpeg4"); video.setBitRate(new Integer(800000)); video.setFrameRate(new Integer(15)); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp4"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); encoder.encode(source, target, attrs); }catch (EncoderException e){ e.printStackTrace(); } } } 需要jave.jar |
|