javaxugglerxuggle

Xuggler not working with webapp


Hi i am trying to use Xuggler with my web app in which i am trying to convert a video file from one format to another.For a desktop java app i am able to do so but for the web app i am getting the following error

 frontend.DownloadServlet -
java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:2
07)
        at java.awt.Window.<init>(Window.java:535)
        at java.awt.Frame.<init>(Frame.java:420)
        at java.awt.Frame.<init>(Frame.java:385)
        at javax.swing.JFrame.<init>(JFrame.java:180)
        at com.xuggle.mediatool.MediaViewer$PositionFrame.<init>(MediaViewer.jav
a:1315)
        at com.xuggle.mediatool.MediaViewer$MediaFrame.<init>(MediaViewer.java:1
427)
        at com.xuggle.mediatool.MediaViewer.onAddStream(MediaViewer.java:421)
        at com.xuggle.mediatool.AMediaToolMixin.onAddStream(AMediaToolMixin.java
:78)
        at com.xuggle.mediatool.MediaReader.getStreamCoder(MediaReader.java:375)

        at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:461)
        at com.dms.frontend.client.widget.Download.MediaConvertor.<init>(Medi
aConvertor.java:33)
        at com.dms.servlet.frontend.DownloadServlet.service(DownloadServlet.java:204);

My guess is its trying to create a window that shows the encoding(which i noticed for the desktop app) and unable to do so for the web app.

My code for video file conversion.

public MediaConvertor(File Dest,File Source) {
    IMediaReader mediaReader =
               ToolFactory.makeReader(Source.getPath());

        // create a media writer
        IMediaWriter mediaWriter =
               ToolFactory.makeWriter(Dest.getPath(), 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) ;
}

Can anyone through some light on it?As in what extra configuration i need to do for my web app.

I am using maven m2e with eclipse juno and xuggler 5.4. I have put the xuggle-xuggler-5.4.jar in my tomcat lib folder.


Solution

  • Got the mistake i did apparently the line of code

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

    was the one creating a viewer for all the video request i make.This code for some reasons doesn't work for web apps. removed this and it worked.