title: Xuggle-Xuggler not converting .MOV or .AVI to .MP4
body: <p>I have been trying to convert .MOV files to .MP4 using <a href="http://www.xuggle.com/xuggler" rel="nofollow">Xuggle</a>. Here was my original code:</p>
  
  <pre><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) ;  
  </code></pre>
  
  <p>This code works for .WMV, but not for .AVI or .MOV.
  Here is my error with .MOV:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>And the error with .AVI:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Then I tried this code:</p>
  
  <pre><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);
  </code></pre>
  
  <p>It still doesn't work. I have heard I need to use an IAudioResampler, but am very confused on how to do that, and can't find sufficient documentation for a beginner like me. Help would be greatly appreciated! Please try to explain. Thank you!</p>
  
  <p><strong>Edit:</strong>
  I think the issue with the second code is the codec. I get a "null codec" exception when I run that one. (I also get a "Closing dangling Container (../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:146)" issue too, if anyone knows how to fix that.</p>
  
  <p>Thank you!</p>