gpt4 book ai didi

java - 如何仅使用 java 将 mp4 文件转换为 webm?

转载 作者:行者123 更新时间:2023-12-04 23:17:59 26 4
gpt4 key购买 nike

我正在尝试将文件从 mp4 转换为 webm。我正在尝试使用 FFmpeg 的 JAVE 包装器。我收到错误消息。
这是我的代码:

private String ConvertVideo(URL url) {
File target =null;
MultimediaObject multimediaObject = new MultimediaObject(url);
try {
target = File.createTempFile("target", ".webm");

} catch (IOException e1) {
e1.printStackTrace();
}
AudioAttributes audio = new AudioAttributes();
audio.setCodec(AudioAttributes.DIRECT_STREAM_COPY);
audio.setBitRate(new Integer(128000));
audio.setSamplingRate(new Integer(44100));
audio.setChannels(new Integer(2));
VideoAttributes video = new VideoAttributes();
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setCodec("libvpx-vp9");
video.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("webm");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);

try {
Encoder encoder = new Encoder();
encoder.encode(multimediaObject, target, attrs);
} catch (Exception e) {
e.printStackTrace();
}

return "success";
}
我收到以下错误:
2022-Jun-13 11:12:55 AM [qtp1914526580-175] ERROR ws.schild.jave.Encoder - Process exit code: 1  to target2636257785060285182.webm
ws.schild.jave.EncoderException: Exit code of ffmpeg encoding run is 1
我在这里做错了什么。还有其他方法吗?我只想用java来做。

最佳答案

我已经整理好了。这是我的最终工作代码。刚刚删除了 video.setCodec(VideoAttributes.DIRECT_STREAM_COPY); 行并且还更改了 audio.setCodec(AudioAttributes.DIRECT_STREAM_COPY); 行至audio.setCodec("libvorbis");

private String convertVideo(URL url) {
File target =null;
MultimediaObject multimediaObject = new MultimediaObject(url);

try {
target = File.createTempFile("target", ".webm");
} catch (IOException e1) {
e1.printStackTrace();
}
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libvorbis");
audio.setBitRate(new Integer(128000));
audio.setSamplingRate(new Integer(44100));
audio.setChannels(new Integer(2));
VideoAttributes video = new VideoAttributes();
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(20));
video.setCodec("libvpx-vp9");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("webm");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);

try {
Encoder encoder = new Encoder();
encoder.encode(multimediaObject, target, attrs);
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}

关于java - 如何仅使用 java 将 mp4 文件转换为 webm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72598294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com