使用Xuggler流式传输视频 [英] Streaming video with Xuggler
问题描述
我能够使用下面的代码成功地与Xuggler一起播放视频。我需要能够从inputStream而不是文件流。我尝试使用注释掉的代码来创建一个Icontainer。当我注释掉代码时,我确实修改了getTestFile方法以使用String而不是输入流。它最初正确地获得了输入流。
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.
当我在Icontainer上调用open时,它只是无限期的块。我不知道我是否正确接近这一点。我怎么做基本相同的事情,但没有使用文件和使用输入流?
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?
谢谢: - )
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();
}
}
推荐答案
我认为你需要这样做:
IContainer iContainer = IContainer.make();
if (iContainer.open(inputStream, IContainer.Type.READ, format) >= 0) {
IMediaReader mediaReader = ToolFactory.makeReader(iContainer);
...
}
...基于javadocs的说法。看起来需要使用 IContainerFormat
类的静态方法获取格式。如果您提供 null
格式, open
方法将尝试猜测容器类型......显然。
... 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.
这篇关于使用Xuggler流式传输视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!