使用 live555 将 H264 流式传输到 VLC

use live555 to stream H264 to VLC

我尝试在没有 RTSP 的情况下通过 RTP 将 H264 流式传输到 VLC,即从 IP 摄像机接收 H.264 流,并将其发送到另一台主机上的 VLC。 VLC 打开 URL “rtp://@:12345”。 请注意,openRTSP 做同样的事情,但使用 H264VideoFileSink class 将数据输出到文件中,我替换了那部分代码:

 if (strcmp(subsession->mediumName(), "video") == 0) {
    if (strcmp(subsession->codecName(), "H264") == 0) {
      // For H.264 video stream, we use a special sink that adds 'start codes',
      // and (at the start) the SPS and PPS NAL units:
      //fileSink = H264VideoFileSink::createNew(*env, outFileName,
            //            subsession->fmtp_spropparametersets(),
            //            fileSinkBufferSize, oneFilePerFrame);

      char const* outputAddressStr = "192.168.1.123"; // this could also be unicast
      struct in_addr outputAddress;
      outputAddress.s_addr = our_inet_addr(outputAddressStr);

      const Port outputPort(12345);
      unsigned char const outputTTL = 255;

      Groupsock outputGroupsock(*env, outputAddress, outputPort, outputTTL);
      rtpSink = H264VideoRTPSink::createNew(*env, &outputGroupsock, 96);
   }
…

那么,

    subsession->sink = rtpSink;
    subsession->sink->startPlaying(*(subsession->readSource()),
        subsessionAfterPlaying,
        subsession);

结果是 openRTSP 是 运行 但 VLC 什么也没收到。我用Wireshark检查,没有数据包发送到目标IP和端口。

我也试试testMP3Streamer,用上面的单播地址替换多播地址。 VLC 可以播放它。 有人可以给我一些建议吗?

您的代码中有几个错误,首先是 Groupsock 范围太窄,接下来需要 H264 Framer 来提供 H264VideoRTPSink,如您在 H264VideoRTPSink.cpp 中所见:

Boolean H264VideoRTPSink::sourceIsCompatibleWithUs(MediaSource& source) {
  // Our source must be an appropriate framer:
  return source.isH264VideoStreamFramer();
}

然后把所有的东西放在一起会得到类似的东西:

char const* outputAddressStr = "192.168.1.123"; 
struct in_addr outputAddress;
outputAddress.s_addr = our_inet_addr(outputAddressStr);

const Port outputPort(12345);
unsigned char const outputTTL = 255;

Groupsock* outputGroupsock = new Groupsock(*env, outputAddress, outputPort, outputTTL);
rtpSink = H264VideoRTPSink::createNew(*env, outputGroupsock, 96);

subsession->addFilter(H264VideoStreamDiscreteFramer::createNew(*env, subsession->readSource()));