Java实现视频编码格式转换(转libx264编码格式)

导入依赖

        <dependency>
            <groupId>ws.schild</groupId>
            <artifactId>jave-core</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>ws.schild</groupId>
            <artifactId>jave-native-win64</artifactId>
            <version>2.4.5</version>
        </dependency>

代码示例

import ws.schild.jave.*;

import java.io.File;

public class AviToMp4 {

    public static void main(String[] args) throws EncoderException {
        File source = new File("C:\\Users\\Administrator\\Desktop\\test0.mp4");
	    File target = new File("C:\\Users\\Administrator\\Desktop\\test1.mp4");
        AudioAttributes audio = new AudioAttributes();
        //音频编码格式
        audio.setCodec("libmp3lame");
        audio.setBitRate(800000);
        audio.setChannels(1);
        VideoAttributes video = new VideoAttributes();
        //视频编码格式
        video.setCodec("libx264");
        video.setBitRate(3200000);
        //数字设置小了,视频会卡顿 帧速率
        video.setFrameRate(30);
        EncodingAttributes attrs = new EncodingAttributes();
        //视频格式
        attrs.setFormat("mp4");
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        MultimediaObject multimediaObject = new MultimediaObject(source);

        encoder.encode(multimediaObject, target, attrs);
    }
}

你可能感兴趣的:(java,音视频)