前提:1.maven工程一個
2.avi視訊一個
第一步:
通過pom.xml匯入jave相關包
<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>
第二步:
示例:
File source = new File("d://123.avi"); //源avi格式視訊 File target = new File("d://456.mp4"); //轉換後的mp4格式視訊 AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); //音訊編碼格式 audio.setBitRate(new Integer(64000)); audio.setChannels(new Integer(1)); audio.setSamplingRate(new Integer(22050)); VideoAttributes video = new VideoAttributes(); video.setCodec("libx264");//視訊編碼格式 video.setBitRate(new Integer(180000)); video.setFrameRate(new Integer(1)); 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);//轉換開始。。。