由于 Java 媒体库中支持的编解码器不多,我尝试使用 Xuggler 将 AVI 和 MPEG4 文件转换为 MP4,然后打开新文件。
AVI 文件没有问题,但在 MPEG4 文件上我收到以下错误:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: failed to encode video
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:764)
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:783)
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaWriter.onVideoPicture(MediaWriter.java:1434)
at xuggle.xuggler@5.4/com.xuggle.mediatool.AMediaToolMixin.onVideoPicture(AMediaToolMixin.java:166)
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaReader.dispatchVideoPicture(MediaReader.java:610)
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaReader.decodeVideo(MediaReader.java:519)
at xuggle.xuggler@5.4/com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:475)
at magnitudo.c_movie/de.telemotive.magnitudo.c_movie.VideoFileIO.convertUnsupportedFiles(VideoFileIO.java:71)
at magnitudo.c_movie/de.telemotive.magnitudo.c_movie.VideoFileIO.load(VideoFileIO.java:21)
at magnitudo.c_movie/de.telemotive.magnitudo.c_movie.VideoController.loadFile(VideoController.java:103)
at magnitudo.c_movie/de.telemotive.magnitudo.c_movie.VideoController.displayFile(VideoController.java:79)
at magnitudo.c_analysiscase/de.telemotive.magnitudo.c_analysiscase.AnalysisCaseController.lambda$12(AnalysisCaseController.java:232)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:830)
我不知道问题出在哪里,我的方法很简单:
private static Path convertUnsupportedFiles(Path path) {
Path pathNew = Paths.get("C:/DEV/2020-05-15_Freitag/Video_NoName_Cam1_20200515_092350_20200515_092830/output.mp4");
IMediaReader mR = ToolFactory.makeReader(path.toString());
IMediaWriter mW = ToolFactory.makeWriter(pathNew.toString(), mR);
mR.addListener(mW);
while (mR.readPacket() == null);
return pathNew;
}
我已经阅读了一些关于支持的代码和其他转换代码的帖子,但结果没有改变。
我是否错过了对 MPEG4 文件的支持?
亲切的问候,马文