spring boot Java 视频转换:avi转mp4

1.pom添加:

<dependency>
    <groupId>ws.schild</groupId>
    <artifactId>jave-core</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>ws.schild</groupId>
    <artifactId>jave-nativebin-linux64</artifactId>
    <version>3.0.1</version>
</dependency>

2.新建类:

package com.api.ynlc.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ws.schild.jave.*;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import ws.schild.jave.encode.VideoAttributes;

import java.io.File;
import java.util.Date;

/**
 * @Auther: liyl
 * @Date: 2021/9/16 10:35
 * @Description:
 */
public class VideoChangeUtil {

    private static final Logger logger = LoggerFactory.getLogger(com.api.ynlc.util.VideoChangeUtil.class);

    public static boolean AviToMp4(String oldPath,String newPath) {
//    File source = new File("D:\\temp\\1.avi");
//     File target = new File("D:\\file\\1.mp4");
        File source = new File(oldPath);
        File target = new File(newPath);
        logger.info("转换后的路径:"+newPath);
        AudioAttributes audio = new AudioAttributes();
        //音频编码格式
        audio.setCodec("libmp3lame");
        audio.setBitRate(new Integer(800000));
        audio.setChannels(new Integer(1));
        VideoAttributes video = new VideoAttributes();
        //视频编码格式
        video.setCodec("libx264");
        video.setBitRate(new Integer(6000000));
        //数字设置小了,视频会卡顿
        video.setFrameRate(new Integer(15));
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        MultimediaObject multimediaObject = new MultimediaObject(source);
        try {
            logger.info("avi转MP4 --- 转换开始:"+new Date());
            encoder.encode(multimediaObject, target, attrs);
            logger.info("avi转MP4 --- 转换结束:"+new Date());
            return true;
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InputFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (EncoderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值