JAVA视频格式转码

   
            ws.schild
            jave-core
            2.4.5
        
        
        
            ws.schild
            jave-native-win64
            2.4.5
        

 public static void main(String[] args) {
        File source = new File("C:\\Users\\Administrator\\Documents\\League of Legends\\Highlights\\1.webm");
        File target = new File("C:\\Users\\Administrator\\Documents\\League of Legends\\Highlights\\2.mp4");
        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(165));//视频的帧率,根据实际情况填写,不要太高扛不住,144,165即可
        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();
        }
    }

JAVA视频格式转码_第1张图片

你可能感兴趣的:(java,开发语言)