live555音视频同步

live555音视频同步

通过testOnDemandRTSPServer.cpp实现,仅需修改部分代码即可,

具体思路:

流式传输音频+视频很简单:只需调用“addSubsession()”两次 - 一次用于视频源,另一次用于音频源。(这样你的“ServerMediaSession”对象包含两个“ServerMediaSubsession”对象 - 一个用于视频,一个用于音频。)

但是,为了音频/视频同步正常工作,每个源(视频和音频)必须生成正确的“每个帧的“fPresentationTime”值,并且这些“必须”与“挂钟”时间对齐 - 即,与调用“gettimeofday()”时获得的时间相同。

注意

测试用的h264和mp3尽量从同一个mp4上进行提取。以验证同步问题。

提取具体操作:

Mp4文件提取详细H.264和MP3文件_泷fyk的博客-CSDN博客

现成的我已提取好的文件:

音视频同步h264-live555(水龙吟)-直播技术文档类资源-CSDN文库

音视频同步测试mp3-live555(水龙吟)资源-CSDN文库

具体代码(对testOnDemandRTSPServer.cpp进行修改)

#include "liveMedia.hh"

#include "BasicUsageEnvironment.hh"
#include "announceURL.hh"

UsageEnvironment* env;

// To make the second and subsequent client for each stream reuse the same
// input stream as the first client (rather than playing the file from the
// start for each client), change the following "False" to "True":
//单播、组播开关,false为单播,true为组播,单播每个链接接入时都会重新播放,组播的话会随着上一个接入流的位置进行播放
//经过实测,组播模式各链接同步流畅,延迟很小。
Boolean reuseFirstSource = false;

// To stream *only* MPEG-1 or 2 video "I" frames
// (e.g., to reduce network bandwidth),
// change the following "False" to "True":
Boolean iFramesOnly = False;

static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
			   char const* streamName, char const* inputFileName); // forward

猜你喜欢

转载自blog.csdn.net/qq_45865950/article/details/132753061