8

所以如果我运行:

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

它给了我一个 5 秒的来自该网络流的视频快照,该视频被放入 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";

    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;
  }

也许最好的方法是使用 inputstream 以某种方式将 ffmpeg 流式传输到 xuggle 容器?或者也许还有另一种方法可以将 webstream 流式传输到 java?

4

1 回答 1

6

rtmp 源字符串应采用以下格式

String rtmpSourceUrl = "rtmp://hostname/appName/streamName"; 

然后我建议像下面这样创建阅读器

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);

这能解决你的问题吗?

于 2013-02-25T17:44:27.477 回答