我想将视频从.webm转换为.mp4。我尝试过使用Java库JAVE(Java Audio Video Encoder)。这是我使用Jave的代码:
File source = new File("C:\\Development\\workspace\\java-project\\video.webm");
File target = new File("C:\\Development\\workspace\\java-project\\video.mp4");
Encoder encoder = new Encoder();
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("mpeg4");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setSize(new VideoSize(400, 300));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp4");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
try {
encoder.encode(source, target, attrs);
} catch (EncoderException e) {
e.printStackTrace();
}
如果我使用像“source”一样的视频.avi或.flv,但是使用.webm,那么这段代码就可以了!我究竟做错了什么?我该怎么办?
答案 0 :(得分:1)
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
public class XuggleApiTest {
private static final String inputFilename = "filepath/filename.webm";
private static final String outputFilename = "filepath/filename.mp4";
public static void main(String[] args) {
IMediaReader mediaReader =
ToolFactory.makeReader(inputFilename);
IMediaWriter mediaWriter =
ToolFactory.makeWriter(outputFilename, mediaReader);
mediaReader.addListener(mediaWriter);
IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
mediaReader.addListener(mediaViewer);
while (mediaReader.readPacket() == null) ;
}
}