问题描述
所以如果我运行:
ffmpeg -t 10 -re -irtmp://170.93.143.150/rtplive / app = rtplive / playpath = e000990f025f0075004d823633235daa swfUrl = http://www.chart.state.md.us/video/mediaplayer/player.swf pageUrl = http://www.chart.state.md.us/video/video .asp?feed = e000990f025f0075004d823633235daa stop = 5000 flashver =`LNX 11,2,202,262` live = truetest.flv -report
它给我一个5秒的视频从该webstream的卡通将被放入test.flv。
现在我想在java中使用xuggle做同样的事情,除非我尝试打开这个容器,把错误发送给我,并将x设置为-1:
public IMediaReader grabStream(IMediaReader reader)throws IOException
{
String rtmp =rtmp://170.93.143.150/rtplive/;
rtmp = rtmp +app = rtplive /;
rtmp = rtmp +playpath = e000990f025f0075004d823633235daa;
rtmp = rtmp +swfUrl = http://www.chart.state.md.us/video/mediaplayer/player.swf;
rtmp = rtmp +pageUrl = http://www.chart.state.md.us/video/video.asp?feed = e000990f025f0075004d823633235daa;
rtmp = rtmp +flashver =`LNX 11,2,202,262`;
rtmp = rtmp +live = true;新新新旗新新新新新旗新新旗新新旗200新新新旗新新旗200新新新新新旗新新旗新新旗新新款:
IMediaReader newReader = ToolFactory.makeReader(container);
int x = container.open(rtmp,IContainer.Type.READ,null,true,false);
if(x< 0)
{
IError ie = IError.make(x);
System.out.println(Open error:+ ie.getType()。toString());
throw new RuntimeException(failed to open with error+ x);
}
return newReader;
}
也许最好的方式是将ffmpeg流入一个xuggle容器使用输入流不知何故?或者还有另一种方式可以将Webstream流传输到java?
rtmp源字符串应为以下格式
String rtmpSourceUrl =rtmp:// hostname / appName / streamName;
然后,我建议创建阅读器,如下所示
$ pre>
IContainerFormat inFormat = IContainerFormat.make();
inFormat.setInputFormat(flv); //设置输入格式以避免FFMPEG
// probing
IMediaReader reader = ToolFactory.makeReader(rtmpSourceUrl);
reader.setQueryMetaData(false);
reader.setBufferedImageTypeToGenerate(-1);
reader.getContainer()。setForcedVideoCodec(ID.CODEC_ID_FLV1);
reader.getContainer()。open(rtmpSourceUrl,IContainer.Type.READ,inFormat,
true,false);
这是否解决了您的问题?
So if I run:
ffmpeg -t 10 -re -i "rtmp://170.93.143.150/rtplive/ app=rtplive/ playpath=e000990f025f0075004d823633235daa swfUrl=http://www.chart.state.md.us/video/mediaplayer/player.swf pageUrl=http://www.chart.state.md.us/video/video.asp?feed=e000990f025f0075004d823633235daa stop=5000 flashver=`LNX 11,2,202,262` live=true" test.flv -report
It gives me a 5 second snapsnot of video from that webstream that gets put into test.flv.Now I would like to do the same thing in java using xuggle except everytime I try and open the container it errors out on me and sets x to -1:
public IMediaReader grabStream(IMediaReader reader) throws IOException
{
String rtmp = "rtmp://170.93.143.150/rtplive/";
rtmp = rtmp + " app=rtplive/";
rtmp = rtmp + " playpath=e000990f025f0075004d823633235daa";
rtmp = rtmp + " swfUrl=http://www.chart.state.md.us/video/mediaplayer/player.swf";
rtmp = rtmp + " pageUrl=http://www.chart.state.md.us/video/video.asp?feed=e000990f025f0075004d823633235daa";
rtmp = rtmp + " flashver=`LNX 11,2,202,262`";
rtmp = rtmp + " live=true";
IContainer container = IContainer.make();
IMediaReader newReader = ToolFactory.makeReader(container);
int x = container.open(rtmp, IContainer.Type.READ, null, true, false);
if (x < 0)
{
IError ie = IError.make(x);
System.out.println("Open error: " + ie.getType().toString());
throw new RuntimeException("failed to open with error" + x);
}
return newReader;
}
Maybe the best way to do it is to stream in ffmpeg to a xuggle container using inputstream somehow? Or maybe there is another way to stream in a webstream to java?
The rtmp source string should be in the following format
String rtmpSourceUrl = "rtmp://hostname/appName/streamName";
Then I would recommend creating the reader like the following
IContainerFormat inFormat = IContainerFormat.make();
inFormat.setInputFormat("flv"); // set the input format to avoid FFMPEG
// probing
IMediaReader reader = ToolFactory.makeReader(rtmpSourceUrl);
reader.setQueryMetaData(false);
reader.setBufferedImageTypeToGenerate(-1);
reader.getContainer().setForcedVideoCodec(ID.CODEC_ID_FLV1);
reader.getContainer().open(rtmpSourceUrl , IContainer.Type.READ, inFormat,
true, false);
Does this solve your problem?
这篇关于如何在java中使用xugg来读取一个实时的Webstream? (我可以在ffmpeg中做,只是不要挣扎)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!