live555中openRTSP这个程序接收buffer,保存文件在哪实现的啊?

时间:2022-06-02 15:26:11
如题。
最近在学习live555,看到openRTSP的时候卡壳了。
希望对这个有研究的各位高手不吝赐教啊。
有如下几个问题:
1.如何保存自定义名字的文件?
2.接收buffer具体在哪一步实现?
3.保存文件在哪一步实现?

33 个解决方案

#1


我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。

#2


帖子沉了,自己顶一下。

#3


有人知道如何跟踪openRTSP程序的运行么?

#4


filesink文件中

#5


楼主能贴下解决这个问题的代码否

#6


引用 5 楼  的回复:
楼主能贴下解决这个问题的代码否

代码在live555的网站上可以直接下载到啊

#7


live555代码我有,就是openRTSP保存H264流需要修改的地方没解决,跟楼主的第一个问题一样的

#8


引用 7 楼  的回复:
live555代码我有,就是openRTSP保存H264流需要修改的地方没解决,跟楼主的第一个问题一样的


// Create an output file for each desired stream:
char outFileName[1000];
if (singleMedium == NULL) {
  // Output file name is
  //     "<filename-prefix><medium_name>-<codec_name>-<counter>"
  static unsigned streamCounter = 0;
  snprintf(outFileName, sizeof outFileName, "%s%s-%s-%d",
   fileNamePrefix, subsession->mediumName(),
   subsession->codecName(), ++streamCounter);
} else {
  sprintf(outFileName, "stdout");
}

#9


已找到,谢谢。第二个问题也帮下忙贴下代码,就是接受buffer保存到文件

#10


引用 9 楼  的回复:
已找到,谢谢。第二个问题也帮下忙贴下代码,就是接受buffer保存到文件

void H264VideoFileSink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime) {
  unsigned char const start_code[4] = {0x00, 0x00, 0x00, 0x01};

  if (!fHaveWrittenFirstFrame) {
    // If we have PPS/SPS NAL units encoded in a "sprop parameter string", prepend these to the file:
    unsigned numSPropRecords;
    SPropRecord* sPropRecords = parseSPropParameterSets(fSPropParameterSetsStr, numSPropRecords);
    for (unsigned i = 0; i < numSPropRecords; ++i) {
      addData(start_code, 4, presentationTime);
      addData(sPropRecords[i].sPropBytes, sPropRecords[i].sPropLength, presentationTime);
    }
    delete[] sPropRecords;
    fHaveWrittenFirstFrame = True; // for next time
  }

  // Write the input data to the file, with the start code in front:
  addData(start_code, 4, presentationTime);

  // Call the parent class to complete the normal file write with the input data:
  FileSink::afterGettingFrame(frameSize, numTruncatedBytes, presentationTime);
}

void FileSink::afterGettingFrame(unsigned frameSize,
 unsigned numTruncatedBytes,
 struct timeval presentationTime) {
  if (numTruncatedBytes > 0) {
    envir() << "FileSink::afterGettingFrame(): The input frame data was too large for our buffer size ("
    << fBufferSize << ").  "
            << numTruncatedBytes << " bytes of trailing data was dropped!  Correct this by increasing the \"bufferSize\" parameter in the \"createNew()\" call to at least "
            << fBufferSize + numTruncatedBytes << "\n";
  }
  addData(fBuffer, frameSize, presentationTime);

  if (fOutFid == NULL || fflush(fOutFid) == EOF) {
    // The output file has closed.  Handle this the same way as if the
    // input source had closed:
    onSourceClosure(this);

    stopPlaying();
    return;
  }

  if (fPerFrameFileNameBuffer != NULL) {
    if (fOutFid != NULL) { fclose(fOutFid); fOutFid = NULL; }
  }

  // Then try getting the next frame:
  continuePlaying();
}

#11


没说改哪啊楼主,这是原原本本的

#12


引用 11 楼  的回复:
没说改哪啊楼主,这是原原本本的

你想怎么改?只要修改名字那就可以实现放到自定义的名字里了啊。

#13


名字是改成功了,但是保存下来的文件是0字节啊,就是buffer没写到到文件,我意思是buffer怎么写到文件,要怎么改

#14


引用 13 楼  的回复:
名字是改成功了,但是保存下来的文件是0字节啊,就是buffer没写到到文件,我意思是buffer怎么写到文件,要怎么改

看看创建sink的时候文件名有没有正确入参?
写文件都是live555自动写的,我们不用管,我们只要创建正确的filesink就OK了

#15


没改动任何地方,只是编译live555,运行openRTSP,接收到0字接

#16


我接收的是摄像头传来的流

#17


引用 16 楼  的回复:
我接收的是摄像头传来的流

摄像头是用的rtsp协议么?live555貌似只认rtsp,其他协议的话不认识。
摄像头用vlc可以正常接么?

#18


请教楼主,你的解决办法“在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。”,代码能贴下吗

#19


VLC播放摄像头时是可以的,我有试过

#20


filesink文件中,似乎找不到afternextframe这个函数

#21


引用 20 楼  的回复:
filesink文件中,似乎找不到afternextframe这个函数

void FileSink::afterGettingFrame(unsigned frameSize,
                 unsigned numTruncatedBytes,
                 struct timeval presentationTime)

#22


引用 18 楼  的回复:
请教楼主,你的解决办法“在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。”,代码能贴下吗

另外写文件这个操作是live555来执行的,不需要我们来干预

#23


但是不干预的话,写到文件的是0字节,如果楼主写文件是成功的,改动的地方应该是有的

#24


引用 23 楼  的回复:
但是不干预的话,写到文件的是0字节,如果楼主写文件是成功的,改动的地方应该是有的

我没有对程序做任何改动,程序编译完成之后直接运行是可以写文件的。

#25


楼主可否将你的live555发我邮箱,可能我版本有问题,842598566@qq.com

#26


引用 25 楼  的回复:
楼主可否将你的live555发我邮箱,可能我版本有问题,842598566@qq.com

只要在官方网站上下载下来最新代码,编译一下就OK了啊。。

#27


楼主你好 我现在编译一下LIVE555 的OPENRTSP 能够接受RTSP 的H264数据流 我现在想把数据流弄成文件(例如avi mp4)形式 因为拿VLC播放的数据流很快, 应该改哪 您知道吗?

#28


引用 27 楼 wwzzss321 的回复:
楼主你好 我现在编译一下LIVE555 的OPENRTSP 能够接受RTSP 的H264数据流 我现在想把数据流弄成文件(例如avi mp4)形式 因为拿VLC播放的数据流很快, 应该改哪 您知道吗?

“数据流很快”是什么意思啊?OPENRTSP 保存的是裸流文件,如果想要进行编码成AVI或MP4的话需要用FFMPEG,具体怎么实现我也不太清楚。可以自己去查阅相关资料

#29


  各位高手!我有一个小问题求教,就是客户端的程序获取服务器的ip和端口号的程序部分在哪儿呢?如果要将数据流导出到解码卡解码的话,是不是另外定义一个全局变量指针,指向filesink的fubuffer所指向的,然后在解码的程序里面应用这个全局变量指针就可以呢?求教了,刚弄这个,好多不懂!

#30


直接在参数指定格式,然后stdout重定向导文件即可!

#31


引用 1 楼 cll131421 的回复:
我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。
楼主 请问下这个void setupStreams()在哪里,我怎么找不到呢?

#32


引用 31 楼 allenspeaker 的回复:
Quote: 引用 1 楼 cll131421 的回复:

我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。
楼主 请问下这个void setupStreams()在哪里,我怎么找不到呢?


这个是在playcommon.cpp中。
现在我就是想得到buffer,不要别的。就是从摄像机种读过来的数据直接保存在buffer中,怎么弄?

#33


有一个-R的方法可使实现

#1


我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。

#2


帖子沉了,自己顶一下。

#3


有人知道如何跟踪openRTSP程序的运行么?

#4


filesink文件中

#5


楼主能贴下解决这个问题的代码否

#6


引用 5 楼  的回复:
楼主能贴下解决这个问题的代码否

代码在live555的网站上可以直接下载到啊

#7


live555代码我有,就是openRTSP保存H264流需要修改的地方没解决,跟楼主的第一个问题一样的

#8


引用 7 楼  的回复:
live555代码我有,就是openRTSP保存H264流需要修改的地方没解决,跟楼主的第一个问题一样的


// Create an output file for each desired stream:
char outFileName[1000];
if (singleMedium == NULL) {
  // Output file name is
  //     "<filename-prefix><medium_name>-<codec_name>-<counter>"
  static unsigned streamCounter = 0;
  snprintf(outFileName, sizeof outFileName, "%s%s-%s-%d",
   fileNamePrefix, subsession->mediumName(),
   subsession->codecName(), ++streamCounter);
} else {
  sprintf(outFileName, "stdout");
}

#9


已找到,谢谢。第二个问题也帮下忙贴下代码,就是接受buffer保存到文件

#10


引用 9 楼  的回复:
已找到,谢谢。第二个问题也帮下忙贴下代码,就是接受buffer保存到文件

void H264VideoFileSink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime) {
  unsigned char const start_code[4] = {0x00, 0x00, 0x00, 0x01};

  if (!fHaveWrittenFirstFrame) {
    // If we have PPS/SPS NAL units encoded in a "sprop parameter string", prepend these to the file:
    unsigned numSPropRecords;
    SPropRecord* sPropRecords = parseSPropParameterSets(fSPropParameterSetsStr, numSPropRecords);
    for (unsigned i = 0; i < numSPropRecords; ++i) {
      addData(start_code, 4, presentationTime);
      addData(sPropRecords[i].sPropBytes, sPropRecords[i].sPropLength, presentationTime);
    }
    delete[] sPropRecords;
    fHaveWrittenFirstFrame = True; // for next time
  }

  // Write the input data to the file, with the start code in front:
  addData(start_code, 4, presentationTime);

  // Call the parent class to complete the normal file write with the input data:
  FileSink::afterGettingFrame(frameSize, numTruncatedBytes, presentationTime);
}

void FileSink::afterGettingFrame(unsigned frameSize,
 unsigned numTruncatedBytes,
 struct timeval presentationTime) {
  if (numTruncatedBytes > 0) {
    envir() << "FileSink::afterGettingFrame(): The input frame data was too large for our buffer size ("
    << fBufferSize << ").  "
            << numTruncatedBytes << " bytes of trailing data was dropped!  Correct this by increasing the \"bufferSize\" parameter in the \"createNew()\" call to at least "
            << fBufferSize + numTruncatedBytes << "\n";
  }
  addData(fBuffer, frameSize, presentationTime);

  if (fOutFid == NULL || fflush(fOutFid) == EOF) {
    // The output file has closed.  Handle this the same way as if the
    // input source had closed:
    onSourceClosure(this);

    stopPlaying();
    return;
  }

  if (fPerFrameFileNameBuffer != NULL) {
    if (fOutFid != NULL) { fclose(fOutFid); fOutFid = NULL; }
  }

  // Then try getting the next frame:
  continuePlaying();
}

#11


没说改哪啊楼主,这是原原本本的

#12


引用 11 楼  的回复:
没说改哪啊楼主,这是原原本本的

你想怎么改?只要修改名字那就可以实现放到自定义的名字里了啊。

#13


名字是改成功了,但是保存下来的文件是0字节啊,就是buffer没写到到文件,我意思是buffer怎么写到文件,要怎么改

#14


引用 13 楼  的回复:
名字是改成功了,但是保存下来的文件是0字节啊,就是buffer没写到到文件,我意思是buffer怎么写到文件,要怎么改

看看创建sink的时候文件名有没有正确入参?
写文件都是live555自动写的,我们不用管,我们只要创建正确的filesink就OK了

#15


没改动任何地方,只是编译live555,运行openRTSP,接收到0字接

#16


我接收的是摄像头传来的流

#17


引用 16 楼  的回复:
我接收的是摄像头传来的流

摄像头是用的rtsp协议么?live555貌似只认rtsp,其他协议的话不认识。
摄像头用vlc可以正常接么?

#18


请教楼主,你的解决办法“在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。”,代码能贴下吗

#19


VLC播放摄像头时是可以的,我有试过

#20


filesink文件中,似乎找不到afternextframe这个函数

#21


引用 20 楼  的回复:
filesink文件中,似乎找不到afternextframe这个函数

void FileSink::afterGettingFrame(unsigned frameSize,
                 unsigned numTruncatedBytes,
                 struct timeval presentationTime)

#22


引用 18 楼  的回复:
请教楼主,你的解决办法“在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。”,代码能贴下吗

另外写文件这个操作是live555来执行的,不需要我们来干预

#23


但是不干预的话,写到文件的是0字节,如果楼主写文件是成功的,改动的地方应该是有的

#24


引用 23 楼  的回复:
但是不干预的话,写到文件的是0字节,如果楼主写文件是成功的,改动的地方应该是有的

我没有对程序做任何改动,程序编译完成之后直接运行是可以写文件的。

#25


楼主可否将你的live555发我邮箱,可能我版本有问题,842598566@qq.com

#26


引用 25 楼  的回复:
楼主可否将你的live555发我邮箱,可能我版本有问题,842598566@qq.com

只要在官方网站上下载下来最新代码,编译一下就OK了啊。。

#27


楼主你好 我现在编译一下LIVE555 的OPENRTSP 能够接受RTSP 的H264数据流 我现在想把数据流弄成文件(例如avi mp4)形式 因为拿VLC播放的数据流很快, 应该改哪 您知道吗?

#28


引用 27 楼 wwzzss321 的回复:
楼主你好 我现在编译一下LIVE555 的OPENRTSP 能够接受RTSP 的H264数据流 我现在想把数据流弄成文件(例如avi mp4)形式 因为拿VLC播放的数据流很快, 应该改哪 您知道吗?

“数据流很快”是什么意思啊?OPENRTSP 保存的是裸流文件,如果想要进行编码成AVI或MP4的话需要用FFMPEG,具体怎么实现我也不太清楚。可以自己去查阅相关资料

#29


  各位高手!我有一个小问题求教,就是客户端的程序获取服务器的ip和端口号的程序部分在哪儿呢?如果要将数据流导出到解码卡解码的话,是不是另外定义一个全局变量指针,指向filesink的fubuffer所指向的,然后在解码的程序里面应用这个全局变量指针就可以呢?求教了,刚弄这个,好多不懂!

#30


直接在参数指定格式,然后stdout重定向导文件即可!

#31


引用 1 楼 cll131421 的回复:
我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。
楼主 请问下这个void setupStreams()在哪里,我怎么找不到呢?

#32


引用 31 楼 allenspeaker 的回复:
Quote: 引用 1 楼 cll131421 的回复:

我自己来吧。。
1.在 void setupStreams() 中,修改 char outFileName[1000]即可得到自定义名字的文件。
2.在fileSink的afternextframe()中,通过adddata()把buffer写到指定的文件中。
楼主 请问下这个void setupStreams()在哪里,我怎么找不到呢?


这个是在playcommon.cpp中。
现在我就是想得到buffer,不要别的。就是从摄像机种读过来的数据直接保存在buffer中,怎么弄?

#33


有一个-R的方法可使实现