Streaming video with Xuggler

7.3k views Asked by At

I was able to successfully play video with Xuggler with the code below. I need to be able to stream from an inputStream instead of a file. I tried using the commented out code to create an Icontainer. I did modified the getTestFile method to use a String instead of an inputstream when I commented out the code. It was originally getting the inputstream correctly.

When I call open on Icontainer is just blocks indefinitely. I don't know if I'm approaching this correctly. How would I do basically the same thing but without use a file and using an input stream?

Thanks :-)

package com.plumber.testing;

import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.IContainer;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class VideoTest {

    public static void main(String[] args) throws FileNotFoundException {


//        IContainer iContainer = IContainer.make();
//        iContainer.open(getTestFile("IMG_0983.MOV"), null);
//        I was originally passing the icontainer to make reader
        IMediaReader mediaReader = ToolFactory.makeReader(getTestFile("IMG_0983.MOV"));


        IMediaViewer mediaViewer = ToolFactory.makeViewer(true);

        mediaReader.addListener(mediaViewer);

        while (mediaReader.readPacket() == null) ;

    }

    private static String getTestFile(String fileName) {
        return VideoTest.class.getClassLoader().getResource("com/plumber/testing/testfiles/" + fileName).getPath();
    }

}
1

There are 1 answers

3
Stephen C On

I think you need to do something like this:

    IContainer iContainer = IContainer.make();
    if (iContainer.open(inputStream, IContainer.Type.READ, format) >= 0) {
        IMediaReader mediaReader = ToolFactory.makeReader(iContainer);
        ...
    }

... based on what the javadocs say. It looks like the format needs to be obtained using static methods of the IContainerFormat class. If you supply a null format, the open method will attempt to guess the container type ... apparently.