Xuggle can handle many different video formats. What I am thinking about is to wrap the Xuggle into Swing component, and make a start/pause button and a progress bar on the top of it. Any suggestions? Sample codes would be great.

MyDreamGirl

Dani AI

Generated

Practical, low-risk pattern for embedding Xuggler in Swing (what started): run a single decoder thread that converts each decoded video frame to a BufferedImage and publish that image to the UI thread; render it from an overridden JPanel.paintComponent(Graphics) with g.drawImage(...). Keep the decoder and UI separate (use a small bounded BlockingQueue or a single volatile currentFrame and call repaint()), and schedule repaint/update and progress-bar updates on the EDT. The Xuggler demo does the same conversion-to-BufferedImage approach and is a good reference for the decoding->image flow. (xuggle.wordpress.com)

Audio + volume: decode audio packets to raw PCM and write them to a Java Sound SourceDataLine opened with the matching AudioFormat. Try to get a FloatControl of type MASTER_GAIN (available only after the line is opened) and use it when present; if the control is not supported on the platform, scale PCM samples in Java before writing to the line (multiply sample values by a gain factor 0.0..1.0). Example (16-bit little-endian signed PCM):

for (int i = 0; i < buf.length; i += 2) {
  short s = (short)((buf[i+1] << 8) | (buf[i] & 0xff));
  s = (short)(s * gain); // gain between 0.0 and 1.0
  buf[i] = (byte)(s & 0xff);
  buf[i+1] = (byte)((s >>> 8) & 0xff);
}

See the Java Sound float-control docs and common Java examples for details. (docs.oracle.com)

Diagnosing the AVI OOM ("Failed to create a thread: retVal -1073741830, errno 12"): that error normally means native memory or thread-stack resources are exhausted (too many threads, too-large Java heap leaving little native memory, or OS limits). Actions that stop this class of failures: avoid spawning per-packet threads (use a fixed thread or thread pool), bound buffers (limit queued frames/samples), reduce -Xmx so native heap is available, reduce per-thread stack with -Xss if appropriate, and ensure decoders / lines are closed promptly. Collect a thread/heap dump to see what is growing. IBM docs and field notes explain this exact symptom and remedies. (ibm.com)

Quick checklist: 1) switch to a single decode thread + fixed-size queue; 2) render BufferedImage on EDT; 3) play audio on one JavaSound thread and use FloatControl or PCM scaling for volume; 4) limit memory by bounding buffers and tuning -Xmx/-Xss; 5) if sync problems appear, use timestamps from Xuggler and drive render timing from audio clock. Also review Xuggler docs and the user mailing list for sync patterns and examples. (xuggle.com)

Recommended Answers

All 9 Replies

> Any suggestions?
Sure, start reading their tutorials on the site.

I did. However, it does not work when I tried to wrap Xuggle into a Swing component. If you have done that before, please share your knowledge with me. Thanks,MyDreamGirl

This example app from the tutorials seems applicable:
http://xuggle.wordpress.com/2009/01/23/how-to-use-xuggler-to-decode-and-play-video/

They are updating a VideoImage frame with a BufferedImage from the stream. VideoImage just extends JFrame, so you could probably either look at that source or override paintComponent(Graphics) on a JPanel of your own and render the BufferedImage on that panel with drawImage().

It works. Thanks.

DO you know how to do volume control? Any tutorials?

When I do the tutorials you mentioned (DecodeAndPlayVideo.java and VideoImage.java), there is not sound. Do you know how to add sound into it?

There is 3 methods to decode audio and/or video :
- DecodeAndPlayVideo
- DecodeAndPlayAudio
- DecodeAndPlayAudioAndVideo

They are all in : com.xuggle.xuggler.demos

DecodeAndPlayAudioAndVideo wraps all thing together and leaves no room for custmozing Swing component. I am looking into combining video and audio, any other code that has already done the job? Thanks,

Got it to work. Thanks a lot for your help.

I got my application running fine against .mov, .mp3 and .flv. However, when I ran it against .avi file, it poped up following error:

JVMDUMP006I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" - please wait.
JVMDUMP032I JVM requested Snap dump using 'C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\Snap.20111025.134539.12108.0001.trc' in response to an event
JVMDUMP010I Snap dump written to C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\Snap.20111025.134539.12108.0001.trc
JVMDUMP032I JVM requested Heap dump using 'C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\heapdump.20111025.134539.12108.0002.phd' in response to an event
JVMDUMP010I Heap dump written to C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\heapdump.20111025.134539.12108.0002.phd
JVMDUMP032I JVM requested Java dump using 'C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\javacore.20111025.134539.12108.0003.txt' in response to an event
JVMDUMP010I Java dump written to C:\Users\xh2453\IBM\rationalsdp\workspace_70\TestWebAppl\javacore.20111025.134539.12108.0003.txt
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
Exception in thread "main" java.lang.OutOfMemoryError: Failed to create a thread: retVal -1073741830, errno 12
at java.lang.Thread.startImpl(Native Method)
at java.lang.Thread.start(Thread.java:887)
at com.test.xuggle.fileconvert.DecodeAndPlayVideo$VideoAudio.setAudio(DecodeAndPlayVideo.java:473)
at com.test.xuggle.fileconvert.DecodeAndPlayVideo.playJavaSound(DecodeAndPlayVideo.java:453)
at com.test.xuggle.fileconvert.DecodeAndPlayVideo.<init>(DecodeAndPlayVideo.java:233)
at com.test.xuggle.fileconvert.VideoPlayer.main(VideoPlayer.java:7)


Any suggestions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.