Java视频压缩

1、导入Maven依赖包

<properties>
    <!--本地包的引入-->
    <java.lib>${project.basedir}/src/main/webapp/WEB-INF/lib</java.lib>
  </properties>
<dependency>
         <groupId>java</groupId>
         <artifactId>jave</artifactId>
         <version>1.0.2</version>
         <scope>system</scope>
         <systemPath>${java.lib}/jave-1.0.2.jar</systemPath>
     </dependency>

导入本地的jave包,由于没有搜索到maven仓库包,就下载了一个jar包,下载之后放到项目的lib目录下

如:

src/main/webapp/WEB-INF/lib


2、测试压缩程序

package com.zemel.test;

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 java.io.File;

public class FfmepgDemo {
	public static void main(String[] args) {
		
        File source = new File("D:/biudata/video/1.mp4");
        File target = new File("D:/biudata/yasuo/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);
            System.out.println("压缩完成...");
        }catch (EncoderException e){
            e.printStackTrace();
        }

    }
}
跑一下上面mian函数就成功了。


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值