Article directory
live555 audio and video synchronization
Implemented through testOnDemandRTSPServer.cpp, only need to modify part of the code,
Specific ideas:
Streaming audio + video is simple: just call "addSubsession()" twice - once for the video source and once for the audio source. (This way your "ServerMediaSession" object contains two "ServerMediaSubsession" objects - one for video and one for audio.)
However, for audio/video sync to work properly, each source (video and audio) must generate correct "fPresentationTime" values for each frame, and these "must" be aligned with the "wall clock" time - i.e., with the call to "gettimeofday" ()", the time obtained is the same.
Notice
The h264 and mp3 used for testing should be extracted from the same mp4 as much as possible. to verify sync issues.
Extract specific operations:
Mp4 file extraction details H.264 and MP3 files_longfyk's blog-CSDN blog
Ready-made files that I have extracted:
Audio and video synchronization test mp3-live555 (Shuilongyin) resources-CSDN library
Specific code (modify 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