java 视频转换,将所有上传的视频类型转为mp4

用眼神瞬杀你 2015-05-21 03:31:14
java 视频转换,将所有上传的视频类型转为mp4,求大神解决
...全文
14033 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
疯狂的熊猫Npe 2018-10-10
  • 打赏
  • 举报
回复
楼上的你难道一直没发现你这种压缩方式上传到服务器上视频无法播放么
x业精于勤x 2017-02-13
  • 打赏
  • 举报
回复 1
要看楼主用啥方式了,ffmepg是可以,不过通过java调用性能很低,我推荐一种 java原生的方式,需要引入jave-1.0.2.jar

File source = new File("C:\\Users\\xfy\\desktop\\工作文档\\2817\\test.avi");  
File target = new File("C:\\Users\\xfy\\desktop\\工作文档\\2817\\test__001.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("C:\\Users\\xfy\\desktop\\工作文档\\2817\\test_1111.mp4");  
File target = new File("C:\\Users\\xfy\\desktop\\工作文档\\2817\\test_1111.avi");// 转MP4  
System.out.println(source.length());  
  
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("libxvid");// 转MP4  
video.setBitRate(new Integer(180000));// 180kb/s比特率  
video.setFrameRate(new Integer(1));// 1f/s帧频,1是目前测试比较清楚的,越大越模糊  
EncodingAttributes attrs = new EncodingAttributes();  
attrs.setFormat("avi");// 转MP4  
attrs.setAudioAttributes(audio);  
attrs.setVideoAttributes(video);  
Encoder encoder = new Encoder();  
long beginTime = System.currentTimeMillis();  
try {  
    // 获取时长  
    MultimediaInfo m = encoder.getInfo(source);  
    System.out.println(m.getDuration());  
    System.out.println("获取时长花费时间是:" + (System.currentTimeMillis() - beginTime));  
    beginTime = System.currentTimeMillis();  
    encoder.encode(source, target, attrs);  
    System.out.println("视频转码花费时间是:" + (System.currentTimeMillis() - beginTime));  
} catch (IllegalArgumentException e) {  
    e.printStackTrace();  
} catch (InputFormatException e) {  
    e.printStackTrace();  
} catch (EncoderException e) {  
    e.printStackTrace();  
}  
如果还是不懂可以去我的博客看下 http://blog.csdn.net/xiaopy_0508/article/details/54962386
aaaaaa0000060 2017-02-10
  • 打赏
  • 举报
回复
哈哈哈哈灌灌灌灌灌
他们好奇怪 2017-01-19
  • 打赏
  • 举报
回复
能转了吗 楼主
浮云若水 2016-11-16
  • 打赏
  • 举报
回复
这是传说中的挖坟么
janrick 2016-11-16
  • 打赏
  • 举报
回复
楼主解决了吗?求电话
九尾狐的yi巴 2016-10-14
  • 打赏
  • 举报
回复
我就像问问楼主解决了没有 好几年过去了
钠离子zi 2016-07-28
  • 打赏
  • 举报
回复
最强大的,莫过于ffmpeg
lizexing1 2016-07-26
  • 打赏
  • 举报
回复
所有格式都能转吗?我试试啊
狂暴的小猴儿 2016-07-26
  • 打赏
  • 举报
回复
ffmpeg 可以转
lizexing1 2016-07-26
  • 打赏
  • 举报
回复
哥们,你最后是怎么解决的,我这现在需要播放视频支持多格式的,后来想到了用html5播放,把所有上传的格式转成MP4,看到了你的提问,不知道你解决了没
wzy383545337 2015-10-16
  • 打赏
  • 举报
回复
楼主,我也是这个问题。我前段上传各种格式的视频文件。。后台把它们转为MP4格式 。并存储起来 请问楼主解决这个问题了没?求联系电话。来交流交流
弱猪 2015-05-22
  • 打赏
  • 举报
回复
http://www.oschina.net/code/snippet_220255_7784 朋友,你看了这个总会了吧,我代你问了下百度。
用眼神瞬杀你 2015-05-21
  • 打赏
  • 举报
回复
早就看了,就是不会用
弱猪 2015-05-21
  • 打赏
  • 举报
回复
ffmpeg, mencoder 这两个东西你查一下看有没有帮助。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧