运用JAVE进行多媒体格式(avi视频格式转成mp4格式)转换

所用到的核心包是:jave-1.0.2.jar (自行去网上搜索下载)

官方文档:http://www.sauronsoftware.it/projects/jave/manual.php?PHPSESSID=eu6upk3l6okcd3h6sj6b9egqp4 


package com.infore.platform.common.util;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.VideoAttributes;


/**  
 * @Title:  MultimediaFormatConversionUtils.java
 * @Package com.infore.manage.common.util
 * @Description: 多媒体格式转换工具类
 * @author: ZXM
 * @date: 2018年9月29日 下午5:14:42
 * @version V1.0
 * @company:
 * @Copyright: 
 */
public class MultimediaFormatConversionUtils {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * @Title: convertMultimediaFormat
	 * @Description: 视频格式转换
	 * 【文档:http://www.sauronsoftware.it/projects/jave/manual.php?PHPSESSID=eu6upk3l6okcd3h6sj6b9egqp4】
	 * @author: ZXM
	 * @param sourcePath
	 * @param targetPath
	 * @param audioEncoder
	 * @param videoEncoder
	 * @param targetFormat
	 */
	public void convertMultimediaFormat(String sourcePath, String targetPath, String audioEncoder, String videoEncoder,
			String targetFormat) {
		try {
			/*File source = new File("C:\\Users\\Administrator\\Pictures\\新建文件夹\\3-6 webpack打包(中).avi");
			File target = new File("C:\\Users\\Administrator\\Pictures\\新建文件夹\\4-3.mp4");*/
			File source = new File(sourcePath);
			File target = new File(targetPath);
			/*设置音频属性*/
			AudioAttributes audio = new AudioAttributes();
			audio.setCodec(audioEncoder); // libmp3lame  或  flac
			audio.setBitRate(new Integer(400000)); // 数字越大声音越接近原声,转换时间越久(亲测这个数值比较好)
			audio.setChannels(new Integer(1));
			// audio.setSamplingRate(new Integer(22050));
			/*设置视频属性*/
			VideoAttributes video = new VideoAttributes();
			video.setCodec(videoEncoder);  // msmpeg4v2
			video.setBitRate(new Integer(1600000)); // 数字越大画面越清晰,转换时间越久(亲测这个数值比较好)
			video.setFrameRate(new Integer(15));
			// video.setSize(new VideoSize(400, 300));
			/*设置编码属性*/
			EncodingAttributes attrs = new EncodingAttributes();
			attrs.setFormat(targetFormat); //mp4  需要转换成的格式
			attrs.setAudioAttributes(audio);
			attrs.setVideoAttributes(video);
			/*执行转码*/
			Encoder encoder = new Encoder();
			encoder.encode(source, target, attrs);
			logger.info("转码成功!!!!!!!");
		} catch (IllegalArgumentException e) {
			logger.error("转码失败!(IllegalArgumentException)");
			e.printStackTrace();
		} catch (InputFormatException e) {
			logger.error("转码失败!(InputFormatException)");
			e.printStackTrace();
		} catch (EncoderException e) {
			logger.error("转码失败!(EncoderException)");
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		MultimediaFormatConversionUtils m = new MultimediaFormatConversionUtils();
		String sourcePath = "C:\\Users\\Administrator\\Pictures\\新建文件夹\\3-6 webpack打包(中).avi";
		String targetPath = "C:\\Users\\Administrator\\Pictures\\新建文件夹\\4-3.mp4";
		m.convertMultimediaFormat(sourcePath, targetPath, "libmp3lame", "msmpeg4v2", "mp4");
	}
}


 

 

 

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值