Xuggle-Xuggler does not convert .MOV or .AVI to .MP4

I am trying to convert .MOV files to .MP4 using Xuggle . Here is my original code:

    // 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) ;  

      

This code works for .WMV, but not for .AVI or .MOV. Here is my error with .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)

      

And the error with .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)

      

Then I tried this code:

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);

      

It still doesn't work. I have heard that I need to use the IAudioResampler, but I am very confused on how to do this and cannot find sufficient documentation for a beginner like me. Help would be greatly appreciated! Try to explain. Thank!

Edit: I think the problem with the second code is the codec. I get a "codec zero" exception when I run this one. (I also get "Closing dangling container (../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:146)", also if anyone knows how to fix it.

Thank!

+3


source to share


1 answer


You can try with ICodec.ID.CODEC_ID_H264

:



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

      

0


source







All Articles