Xuggle-Xuggler没有将.MOV或.AVI转换为.MP4

时间:2015-07-07 02:46:54

标签: java converter mp4 mov xuggle

我一直在尝试使用Xuggle将.MOV文件转换为.MP4​​。这是我的原始代码:

    // create a media reader  
    IMediaReader mediaReader = ToolFactory.makeReader(path);  

    // create a media writer  
    IMediaWriter mediaWriter = ToolFactory.makeWriter(outpath, mediaReader);  

    // add a writer to the reader, to create the output file  
    mediaReader.addListener(mediaWriter);  

    // create a media viewer with stats enabled  
    IMediaViewer mediaViewer = ToolFactory.makeViewer(true);  

    // add a viewer to the reader, to see the decoded media  
    mediaReader.addListener(mediaViewer);  

    // read and decode packets from the source file and  
    // and dispatch decoded audio and video to the writer  
    while (mediaReader.readPacket() == null) ;  

此代码适用于.WMV,但不适用于.AVI或.MOV。 这是我在.MOV中的错误:

19:36:37.270 [video stream 0 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]   DEBUG com.xuggle.mediatool.MediaViewer - thread started
19:36:37.407 [audio stream 1 PCM signed 16-bit little-endian] DEBUG   com.xuggle.mediatool.MediaViewer - thread started
19:36:37.640 [AWT-EventQueue-0] WARN  com.xuggle.xuggler - Got error:   picture is not of the same PixelType as this Coder expected   (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:1430)
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: failed to   encode video
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:764)
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:783)
at com.xuggle.mediatool.MediaWriter.onVideoPicture(MediaWriter.java:1434)
at com.xuggle.mediatool.AMediaToolMixin.onVideoPicture(AMediaToolMixin.java:166)
at com.xuggle.mediatool.MediaReader.dispatchVideoPicture(MediaReader.java:610)
at com.xuggle.mediatool.MediaReader.decodeVideo(MediaReader.java:519)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:475)
at Drivers.beginProgram(Drivers.java:146)
at Drivers.start(Drivers.java:182)
at Drivers$3.actionPerformed(Drivers.java:100)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

和.AVI的错误:

19:39:32.205 [video stream 0 DV (Digital Video)] DEBUG com.xuggle.mediatool.MediaViewer - thread started
19:39:32.331 [audio stream 1 PCM signed 16-bit little-endian] DEBUG com.xuggle.mediatool.MediaViewer - thread started
19:39:32.336 [audio stream 2 PCM signed 16-bit little-endian] DEBUG com.xuggle.mediatool.MediaViewer - thread started
19:39:32.390 [AWT-EventQueue-0] WARN  com.xuggle.xuggler - Got error: picture is not of the same PixelType as this Coder expected (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:1430)
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: failed to  encode video
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:764)
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:783)
at com.xuggle.mediatool.MediaWriter.onVideoPicture(MediaWriter.java:1434)
at com.xuggle.mediatool.AMediaToolMixin.onVideoPicture(AMediaToolMixin.java:166)
at com.xuggle.mediatool.MediaReader.dispatchVideoPicture(MediaReader.java:610)
at com.xuggle.mediatool.MediaReader.decodeVideo(MediaReader.java:519)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:475)
at Drivers.beginProgram(Drivers.java:146)
at Drivers.start(Drivers.java:182)
at Drivers$3.actionPerformed(Drivers.java:100)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

然后我尝试了这段代码:

IMediaReader reader = ToolFactory.makeReader(path);
IMediaWriter writer = ToolFactory.makeWriter(outpath, reader);
writer.open();
writer.setForceInterleave(true);
IContainerFormat outFormat = IContainerFormat.make();
outFormat.setOutputFormat("mp4", outpath, null);
IContainer container = writer.getContainer();
container.open(outpath, IContainer.Type.WRITE, outFormat);
writer.addVideoStream(0, 0, ICodec.findEncodingCodecByName("h264"), 1920, 1080);
writer.addAudioStream(1, 0, ICodec.findEncodingCodecByName("mp3"), 0, 0);
reader.addListener(writer);
while (reader.readPacket() == null);

它仍然无法运作。我听说我需要使用IAudioResampler,但我对如何做到这一点非常困惑,并且无法为像我这样的初学者找到足够的文档。非常感谢帮助!请尝试解释。谢谢!

修改 我认为第二个代码的问题是编解码器。我得到了一个" null编解码器"当我运行那个时出现异常。 (我也得到了一个" Closing悬挂式容器(../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:146)&# 34;问题,如果有人知道如何解决这个问题。

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试ICodec.ID.CODEC_ID_H264

writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, 1920, 1080);