视频压缩转码FFmpegFrameRecorder

代码

/**
     * 视频压缩
     *  movToMp4("C:/mysoftware/video/test188.mp4","C:/mysoftware/video/test188temp.mp4");
     * @param sourcePath  视频来源
     * @param targetPath 压缩后的视频地址
     */
    private void movToMp4(String sourcePath, String targetPath) {
        File source = new File(sourcePath);
        File target = new File(targetPath);
        long beginTime = System.currentTimeMillis();
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");//aac
        //比特率是指每秒传送的比特(bit)数。单位为 bps(Bit Per Second),比特率越高,传送数据速度越快
        audio.setBitRate(new Integer(80000));//设置比特率
        audio.setChannels(new Integer(1));//设置声音频道
        audio.setSamplingRate(new Integer(22050));//设置节录率
        VideoAttributes video = new VideoAttributes();
        video.setCodec("h264");
        video.setBitRate(new Integer(2325 * 1024));
        //比特率是指每秒传送的比特(bit)数。单位为 bps(Bit Per Second),比特率越高,传送数据速度越快
       // video.setBitRate(new Integer(800000));//设置比特率
        video.setFrameRate(new Integer(60));//设置帧率,越大越流畅,越小越卡
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp4");
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        try {

            encoder.encode(new MultimediaObject(source), target, attrs);
            System.out.println("压缩完成花费时间是:" + ((System.currentTimeMillis() - beginTime))/1000 + "秒");
        } catch (IllegalArgumentException | EncoderException e) {
            e.printStackTrace();
        }

    }

支持 Maven

 <!-- 压缩视频 -->
 <properties>
        <java.version>1.8</java.version>
        <bytedeco.version>1.4.1</bytedeco.version>
        <bytedeco.javacpp.version>3.4.1-1.4.1</bytedeco.javacpp.version>
        <bytedeco.javacpp-presets>3.4.2-1.4.1</bytedeco.javacpp-presets>
        <schild.version>2.7.1</schild.version>
    </properties>
   <dependency>
       <groupId>ws.schild</groupId>
       <artifactId>jave-all-deps</artifactId>
       <version>${schild.version}</version>
   </dependency>
   <dependency>
       <groupId>ws.schild</groupId>
       <artifactId>jave-core</artifactId>
       <version>${schild.version}</version>
   </dependency>
   <dependency>
       <groupId>ws.schild</groupId>
       <artifactId>jave-nativebin-win64</artifactId>
       <version>${schild.version}</version>
   </dependency>
   <!--<dependency>
       <groupId>ws.schild</groupId>
       <artifactId>jave-nativebin-linux64</artifactId>
       <version>${schild.version}</version>
   </dependency>
   <dependency>
       <groupId>ws.schild</groupId>
       <artifactId>jave-nativebin-osx64</artifactId>
       <version>${schild.version}</version>
   </dependency>-->
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值