加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Java——上传视频压缩

(2018-02-12 14:31:00)
分类: 程序猿
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("文件格式不正确!");
}
}
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有