java对MP4视频编码转换为H264格式解决浏览器播放无画面问题

最近遇到一个mp4视屏在浏览器页面播放无画面问题,经过多次研究发现视屏编码在浏览器格式不支持,因此需要对视屏的编码进行转换,兼容性最好的是AVC(H264)格式
下面给大家介绍一个main方法对视频编码转换的工具类
jar包:
ws.schild jave-core:2.4.5
ws.schild jave-native-win64:2.4.5
可以在maven库搜索下载

1、pom中加入这两个依赖:

<!-- https://mvnrepository.com/artifact/ws.schild/jave-core -->
<dependency>
    <groupId>ws.schild</groupId>
    <artifactId>jave-core</artifactId>
    <version>2.4.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ws.schild/jave-native-win64 -->
<dependency>
    <groupId>ws.schild</groupId>
    <artifactId>jave-native-win64</artifactId>
    <version>2.4.5</version>
</dependency>

2、代码如下:

package org.springeos.modules.quartz.m3u8.main;

import ws.schild.jave.*;
import java.io.File;
import java.io.IOException;

public class test {
   public static void main(String[] args) throws IOException {
      File source = new File("source.avi");
      File target = new File("target.avi");
      AudioAttributes audio = new AudioAttributes();
      audio.setCodec("libmp3lame");//音频编码格式
      //audio.setBitRate(new Integer(56000));//设置比特率,比特率越大,转出来的音频越大(默认是128000,最好默认就行,有特殊要求再设置)
      audio.setChannels(new Integer(1));
      audio.setSamplingRate(new Integer(22050));
      VideoAttributes video = new VideoAttributes();
      video.setCodec("libx264");//视屏编码格式
      //video.setBitRate(new Integer(56000));//设置比特率,比特率越大,转出来的视频越大(默认是128000,最好默认就行,有特殊要求再设置)
      video.setFrameRate(new Integer(15));//数值设置小了,视屏会卡顿
      EncodingAttributes attrs = new EncodingAttributes();
      attrs.setFormat("mp4");
      attrs.setAudioAttributes(audio);
      attrs.setVideoAttributes(video);
      Encoder encoder = new Encoder();
      MultimediaObject multimediaObject=new MultimediaObject(source);
      try {
         encoder.encode(multimediaObject,target,attrs);
      }catch (IllegalArgumentException e){
         e.printStackTrace();
      }catch (InputFormatException e){
         e.printStackTrace();
      }catch (EncoderException e){
         e.printStackTrace();
      }
   }

}

下面这个链接是 JAVE 视音频转码链接,可以看下里面的一些属性设置;

https://blog.csdn.net/qllinhongyu/article/details/29817297​​​​​​​

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值