Xuggle-Xuggler not converting .MOV or .AVI to .MP4 - java

I have been trying to convert .MOV files to .MP4 using Xuggle. Here was 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 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!
Edit:
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.
Thank you!

You can try with ICodec.ID.CODEC_ID_H264 :
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, 1920, 1080);

Related

Opening docx file directly from src generating "File not found" exception

Edited:
I am trying to open a file that is stored in a project file SRC. I am getting a "File not found" exception and I really don't understand why. The file is a docx and I have dropped it in eclipse into my project's src folder.
Here is the code where I try to open the file:
JButton documentationButton = new JButton("Helpfile");
documentationButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
Desktop desktop = null;
if(Desktop.isDesktopSupported()){
desktop = Desktop.getDesktop();
}
try {
ClassLoader classLoader = getClass().getClassLoader();
File fi = new File(classLoader.getResource("ReturnBuilderDocumentation.docx").getFile());
String string = "file:/src/ReturnBuilderDocumentation.docx";
desktop.open(new File(URI.create(string)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Here is the exception generating:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: The file: \src\ReturnBuilderDocumentation.docx doesn't exist.
at java.awt.Desktop.checkFileValidation(Unknown Source)
at java.awt.Desktop.open(Unknown Source)
at nachamultifive.GUIs.MainMenu$3.actionPerformed(MainMenu.java:172)
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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
This file is clearly in my project src so I have no idea why the error is generating. Any help is greatly appreciated.
UPDATE:
I also tried with backslashes and another error was generated.
Code:
String string = "\\src\\ReturnBuilderDocumentation.docx";
Error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Illegal character in opaque part at index 5: file:\src\ReturnBuilderDocumentation.docx
at java.net.URI.create(Unknown Source)
at nachamultifive.GUIs.MainMenu$3.actionPerformed(MainMenu.java:172)
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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 5: file:\src\ReturnBuilderDocumentation.docx
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
... 38 more
This code is the problem because it can't find that file at the given path
String string = "file:/src/ReturnBuilderDocumentation.docx";
desktop.open(new File(URI.create(string)));
Reason being is that the src folder doesn't really exist after the code is compiled.
To get the file resource post-compilation, you have to use
getClass().getClassLoader().getResource()
Which you have correctly done here
ClassLoader classLoader = getClass().getClassLoader();
File fi = new File(classLoader.getResource("ReturnBuilderDocumentation.docx").getFile());
So to open the file, you should simply have to do
desktop.open(fi);
Instead of
desktop.open(new File(URI.create(string)));
Check this answer. I don't think URIs can have a space, which is character 26 in your file name. File can accept a String, you could take out the URI and replace it with just the file name, or try to change the URI

NoSuchFieldError: RESOURCE_PREFIX when using Tess4J with Eclipse

I've tried using Tess4J in Eclipse but it results with the error in the title. I imported these jar files: tess4j, jai_imageio, and jna. The test code I have written is as per the example given on their examples page.
File DMTfile = new File(System.getProperty("user.dir")+"\\DMTcap.bmp");
BufferedImage DMTcap = ImageIO.read(DMTfile);Tesseract instance = new Tesseract();
String result = "";
try {
result = instance.doOCR(DMTcap);
} catch (TesseractException e2) {
e2.printStackTrace();
}
System.out.println(result);
The full error is as follows:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: RESOURCE_PREFIX
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(Unknown Source)
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at DMT$10.actionPerformed(DMT.java:516)
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)
How can I fix this?
Platform.RESOURCE_PREFIX is a JNA constant. Make sure you use the appropriate version of JNA (4.1.0).
Also check out the answers in this post: NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j

Stuck on playing wav file in java... Need some guidance

I'm trying to play sound in java when a button is pressed. So I have something like the following:
public void playSound(File soundFile) {
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
}
catch (Exception e) {e.printStackTrace();}
}
Then I call the method in actionPerformed inside buttonListener:
playSound(new File("woow_x.wav"));
But it's throwing UnsupportedAudioFileException. Is this saying that .wav files are not supported? I confirmed that the wav file works so I don't know what the issue is. And I'm trying to do this without using sun. Please let me know how this is correctly done. Thank you.
Stack trace:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input
stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at robotMaze.SystemGUI.playSound(SystemGUI.java:183)
at robotMaze.SystemGUI$SendButtonListener.actionPerformed(SystemGUI.java:229)
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$400(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)
The file's encoding is specified in its header to be 0x55. I'm not sure exactly what 0x55 is, but I suspect it is mp3. Either way, it's not one of the encodings supported by Java.
For your purposes (and if the license allows it), you might use an audio editor to convert the file to a format that is supported. (These are enumerated by the static fields in AudioFormat.Encoding.)

Retrieve path of photo from a ResultSet on java

I am using an odbc connector.
I want to know how I can retrieve the path of photo from a resultSet in java.
on windows the path is with a single back slash (example: "C:\test\rahul.jpg") so when I try this :
String str = resultSet.getString ("Ar_photo");
i got an error (Error in assignment).
because the path is not a valid string in java.
Knowing that i have tried to escape the value of path in database, but i noticed that this odbc connector doesn't support "replace" scalar function in sql query.
How to proceed?
Here is the full stack trace :
java.sql.SQLException: [Simba][Simba ODBC Driver]Error in assignment.
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at com.connector.sageConnection.ProductQueries.getCreatedProducts(ProductQueries.java:97)
at com.connector.sageConnection.ODBCConnection.synchronizeProduct_SG_sl(ODBCConnection.java:126)
at com.connector.sageConnection.ODBCConnection.synchronizeDataFromSage(ODBCConnection.java:86)
at com.connector.UI.LoginMethod.synchronizeData(LoginMethod.java:57)
at com.connector.UI.Main$1.actionPerformed(Main.java:79)
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$200(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)

How to rewrite XMP XML in jpg file using Apache Sanselan library?

I want to write XMP to jpg. I use Apache Sanselan library. In the following code I'm trying to read XMP XML and write it again to the same file but get the exception(ImageReadException: Unexpected EOF.).
File file=new File("./img/file.jpg");//input file
if(file.canWrite()){
try {
String xmpXml = Sanselan.getXmpXml(file);
JpegXmpRewriter xmpWriter=new JpegXmpRewriter();
//File newfile = new File("./img/newfile.jpg"); //output file
//xmpWriter.updateXmpXml(new ByteSourceFile(file), new BufferedOutputStream(new FileOutputStream(newfile)), xmpXml);
xmpWriter.updateXmpXml(new ByteSourceFile(file), new BufferedOutputStream(new FileOutputStream(file)), xmpXml);
} catch (ImageReadException | IOException | ImageWriteException e) {
e.printStackTrace();
}
}else {
System.out.println("Can NOT Write");
}
If the input and output files are different the code works fine.
File newfile = new File("./img/newfile.jpg"); //output file
xmpWriter.updateXmpXml(new ByteSourceFile(file), new BufferedOutputStream(new FileOutputStream(newfile)), xmpXml);
But if I read from and write to the same file i get an exception.
org.apache.sanselan.ImageReadException: Unexpected EOF.
at org.apache.sanselan.common.BinaryFileFunctions.readAndVerifyBytes(BinaryFileFunctions.java:129)
at org.apache.sanselan.formats.jpeg.JpegUtils.traverseJFIF(JpegUtils.java:61)
at org.apache.sanselan.formats.jpeg.xmp.JpegRewriter.analyzeJFIF(JpegRewriter.java:204)
at org.apache.sanselan.formats.jpeg.xmp.JpegXmpRewriter.updateXmpXml(JpegXmpRewriter.java:187)
at Editor$1.mouseClicked(Editor.java:147)
at java.awt.AWTEventMulticaster.mouseClicked(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$000(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)

Categories