I am using xuggler to transcode videos into different formats. If I open my IContainer directly from a file, it works perfectly, however, this time I want to open IContainer use an InputStream. Strange thing is I tried to open a mp4 format video via FileInputStream, the IContainer can be opened using this FileInputStream, but I cannot read Ipacket in this stream. Can someone give me some suggestions? Did miss something? I really need my xuggler to deal with streams
public static void main(String[] args) throws IOException {
//the file input stream
FileInputStream fi = new FileInputStream("test.mp4");
//icontainer format
IContainerFormat format = IContainerFormat.make();
format.setInputFormat("mp4");
IContainer container = IContainer.make();
//open container via FileInputStream
int data = container.open(fi, format);
IPacket packet = IPacket.make();
//read packet
int info = container.readNextPacket(packet);
System.out.println(data);
System.out.println(info);
}
results
data: 0
info: -1094995529
According to IError, an unknown error here when I tried to read a packet. I'm using xuggler 5.4
First of all, streams must be seekable(like FSDataInputStream in hadoop), otherwise Xuggler cannot handle it, FileInputStream is not such kind of stream, sad.... Actually, seek() function is important for Xuggler to read a media file
Now, to work on seekable stream.
I have found solution, Xuggler actually can handle streams via IURLPROTOCOLHANDLER, I created my custom class which implements iurlprotocolhandler and it "works". I learned from this Example, which use stream FSDataInputStream.