CN116527981A - Multipath video synchronization method, system, device and storage medium - Google Patents
Multipath video synchronization method, system, device and storage medium Download PDFInfo
- Publication number
- CN116527981A CN116527981A CN202310627643.8A CN202310627643A CN116527981A CN 116527981 A CN116527981 A CN 116527981A CN 202310627643 A CN202310627643 A CN 202310627643A CN 116527981 A CN116527981 A CN 116527981A
- Authority
- CN
- China
- Prior art keywords
- video stream
- offset value
- reference time
- time offset
- file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/43—Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
- H04N21/4302—Content synchronisation processes, e.g. decoder synchronisation
- H04N21/4307—Synchronising the rendering of multiple content streams or additional data on devices, e.g. synchronisation of audio on a mobile phone with the video output on the TV screen
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/20—Servers specifically adapted for the distribution of content, e.g. VOD servers; Operations thereof
- H04N21/21—Server components or server architectures
- H04N21/218—Source of audio or video content, e.g. local disk arrays
- H04N21/2187—Live feed
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/20—Servers specifically adapted for the distribution of content, e.g. VOD servers; Operations thereof
- H04N21/23—Processing of content or additional data; Elementary server operations; Server middleware
- H04N21/242—Synchronization processes, e.g. processing of PCR [Program Clock References]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/47—End-user applications
- H04N21/472—End-user interface for requesting content, additional data or services; End-user interface for interacting with content, e.g. for content reservation or setting reminders, for requesting event notification, for manipulating displayed content
- H04N21/47217—End-user interface for requesting content, additional data or services; End-user interface for interacting with content, e.g. for content reservation or setting reminders, for requesting event notification, for manipulating displayed content for controlling playback functions for recorded or on-demand content, e.g. using progress bars, mode or play-point indicators or bookmarks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/60—Network structure or processes for video distribution between server and client or between remote clients; Control signalling between clients, server and network components; Transmission of management data between server and client, e.g. sending from server to client commands for recording incoming content stream; Communication details between server and client
- H04N21/65—Transmission of management data between client and server
- H04N21/658—Transmission by the client directed to the server
- H04N21/6587—Control parameters, e.g. trick play commands, viewpoint selection
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/80—Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
- H04N21/83—Generation or processing of protective or descriptive data associated with content; Content structuring
- H04N21/845—Structuring of content, e.g. decomposing content into time segments
- H04N21/8456—Structuring of content, e.g. decomposing content into time segments by decomposing the content in the time domain, e.g. in time segments
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Databases & Information Systems (AREA)
- Human Computer Interaction (AREA)
- Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)
Abstract
Description
技术领域technical field
本发明涉及视频处理技术领域,尤其涉及一种多路视频同步方法、系统、装置及存储介质。The present invention relates to the technical field of video processing, in particular to a multi-channel video synchronization method, system, device and storage medium.
背景技术Background technique
HLS(HTTP Live Streaming,基于HTTP的自适应码率流媒体传输协议)作为一种成熟、稳定、高效的音视频传输协议,拥有着广泛的应用领域和优越的性能特点,在数字化娱乐和信息化交流中发挥越来越重要的作用,提供更好的服务和体验。HLS可应用于各类场景,如视频直播、点播、在线教育、远程会议等,为用户提供清晰流畅的视听效果,同时也方便了内容提供商的发布和管理。As a mature, stable and efficient audio and video transmission protocol, HLS (HTTP Live Streaming, an adaptive bit rate streaming media transmission protocol based on HTTP) has a wide range of application fields and superior performance characteristics. Communication plays an increasingly important role in providing better service and experience. HLS can be applied to various scenarios, such as video live broadcast, on-demand, online education, remote conferences, etc., to provide users with clear and smooth audio-visual effects, and also facilitate the release and management of content providers.
在相关技术中,多路HLS视频流同步有两种模式。传统模式1:多路HLS视频流同步通过在流媒体服务器把多路视频流合并成一路视频流的方式实现,这种方式使得用户无法单独对某路或某几路视频流进行操作,如放大、缩小某路视频流或者改变几路视频流的页面布局方式,同时,大大增加了流媒体服务器的转码压力。传统模式2:对已经生成好并保证多路视频的第一帧图像的视频源时间相同的视频文件进行播放进度同步,例如MP4等格式的点播文件,无法满足包括HLS直播在内的各种直播场景。In related technologies, there are two modes for synchronizing multiple channels of HLS video streams. Traditional mode 1: The synchronization of multiple HLS video streams is realized by combining multiple video streams into one video stream on the streaming media server. , Zoom out of a certain video stream or change the page layout of several video streams, and at the same time, greatly increase the transcoding pressure of the streaming media server. Traditional mode 2: Synchronize the playback progress of video files that have been generated and ensure that the video source time of the first frame of multi-channel video is the same. For example, on-demand files in MP4 and other formats cannot meet various live broadcasts including HLS live broadcasts. Scenes.
发明内容Contents of the invention
有鉴于此,本发明实施例的目的是提供一种多路视频同步方法、系统、装置及存储介质,能够在直播场景中对多路视频流进行同步,且对每路视频流可单独控制。In view of this, the purpose of the embodiments of the present invention is to provide a multi-channel video synchronization method, system, device and storage medium, which can synchronize multiple video streams in a live broadcast scene, and each video stream can be controlled independently.
一方面,本发明实施例提供了一种多路视频同步方法,应用于播放端,包括以下步骤:On the one hand, the embodiment of the present invention provides a multi-channel video synchronization method, which is applied to the playback terminal and includes the following steps:
获取流媒体服务器发送的索引文件和媒体分片文件;其中,所述索引文件包括每个所述媒体分片文件的第一帧图像的基准时间偏移值信息,所述媒体分片文件包括当前视频流从推流端推流到所述流媒体服务器的网络延迟时间;Obtain the index file and the media segment file sent by the streaming media server; wherein, the index file includes the reference time offset value information of the first frame image of each of the media segment files, and the media segment file includes the current The network delay time for the video stream to be pushed from the streaming end to the streaming media server;
根据当前视频流播放的当前时间位置、每个所述媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,并从所述索引文件获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值;According to the current time position played by the current video stream, the relative time relationship between the first frame image and the last frame image of each said media segment file, determine the first media segment file of the initial playback of each video stream, and from The index file obtains the reference time offset value of the first frame image of the first media segment file initially played by each video stream;
按照预设时间间隔,根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值;According to the preset time interval, according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the first frame image of each video stream initially played The time of the first frame image of each media segment file determines the reference time offset value of the current frame of each video stream;
按照所述预设时间间隔,根据每路视频流当前帧的基准时间偏移值计算最大基准时间偏移值、最小基准时间偏移值和平均基准时间偏移值,根据所述最大基准时间偏移值与所述最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据所述平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作;所述同步操作包括刷新、快进或暂停。According to the preset time interval, calculate the maximum reference time offset value, the minimum reference time offset value and the average reference time offset value according to the reference time offset value of the current frame of each video stream, and calculate the maximum reference time offset value according to the maximum reference time offset value. The difference between the offset value and the minimum reference time offset value is used to synchronize the normally played video stream, or according to the difference between the average reference time offset value and the reference time offset value of the current frame of each video stream The relationship performs a synchronous operation on a normally played video stream; the synchronous operation includes refreshing, fast forwarding or pausing.
可选地,所述根据当前视频流播放的当前时间位置、每个所述媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,具体包括:Optionally, according to the current time position played by the current video stream, and the relative time relationship between the first frame image and the last frame image of each media segment file, the first media to be initially played by each video stream is determined. Fragmented files, specifically including:
分别每路视频流中每个媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流中每个媒体分片文件的时长;The relative time relationship between the first frame image and the last frame image of each media segment file in each video stream determines the duration of each media segment file in each video stream;
按照时间顺序将每路视频流中每个媒体分片文件的时长进行累加,得到每路视频流中每个媒体分片文件的累加时间;Accumulate the duration of each media segment file in each video stream in chronological order to obtain the cumulative time of each media segment file in each video stream;
将所述每路当前视频流播放的当前时间位置与每路视频流的累加时间进行匹配,确定每路视频流初始播放的第一个媒体分片文件。The current time position played by each current video stream is matched with the cumulative time of each video stream to determine the first media segment file initially played by each video stream.
可选地,所述根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值,具体包括:Optionally, according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the first frame image of each video stream initially played, The time of the first frame image of each media segment file determines the reference time offset value of the current frame of each video stream, specifically including:
计算每路视频流的当前时间与每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间的差值;Calculate the difference between the current time of each video stream and the time of the first frame image of the first media segment file initially played by each video stream;
根据所述差值与每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值确定每路视频流当前帧的基准时间偏移值。The reference time offset value of the current frame of each video stream is determined according to the difference value and the reference time offset value of the first frame image of the first media segment file initially played by each video stream.
可选地,所述根据所述最大基准时间偏移值与所述最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据所述平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作,具体包括:Optionally, the normal playing video stream is synchronized according to the difference between the maximum reference time offset value and the minimum reference time offset value, or according to the average reference time offset value and each The relationship between the reference time offset values of the current frame of the video stream performs synchronous operations on the normally played video stream, specifically including:
对于正常播放的视频流,若所述最大基准时间偏移值与所述最小基准时间偏移值的差值大于预设阈值,刷新各路视频流;For a normally played video stream, if the difference between the maximum reference time offset value and the minimum reference time offset value is greater than a preset threshold, refresh each video stream;
若所述最大基准时间偏移值与所述最小基准时间偏移值的差值小于所述预设阈值,且所述平均基准时间偏移值大于当前帧的基准时间偏移值,将该路视频流快进第一预设时间段;If the difference between the maximum reference time offset value and the minimum reference time offset value is less than the preset threshold, and the average reference time offset value is greater than the reference time offset value of the current frame, the path The video stream is fast forwarded to the first preset time period;
若所述最大基准时间偏移值与所述最小基准时间偏移值的差值小于所述预设阈值,且所述平均基准时间偏移值小于当前帧的基准时间偏移值,将该路视频流暂停第二预设时间段。If the difference between the maximum reference time offset value and the minimum reference time offset value is smaller than the preset threshold, and the average reference time offset value is smaller than the reference time offset value of the current frame, the path The video stream is paused for a second preset time period.
可选地,所述方法还包括:Optionally, the method also includes:
对于未正常播放的视频流,暂停同步操作,直至重新正常播放;所述未正常播放包括暂停状态、视频加载中状态或视频加载失败状态中的任意一种。For video streams that are not being played normally, the synchronous operation is suspended until normal playback is resumed; the abnormal playing includes any one of a paused state, a video loading state, or a video loading failure state.
另一方面,本发明实施例提供了一种多路视频同步方法,应用于推流端,包括:On the other hand, the embodiment of the present invention provides a multi-channel video synchronization method, which is applied to the streaming terminal, including:
计算当前视频流从推流端推流到流媒体服务器的网络延迟时间;Calculate the network delay time of the current video stream from the streaming end to the streaming server;
将视频流和网络延迟时间发送给流媒体服务器,以使所述流媒体服务器生成索引文件和媒体分片文件,其中,所述索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息。Send the video stream and the network delay time to the streaming media server, so that the streaming media server generates index files and media fragment files, wherein the index files include the reference time of the first frame image of each media fragment file Offset information.
可选地,所述网络延迟时间的通过以下方法计算:Optionally, the network delay time is calculated by the following method:
向流媒体服务器的网络延时查询接口发送第一请求,接收所述网络延时查询接口的反馈信息,记录发送第一请求的第一时刻和接收反馈信息的第四时刻;所述反馈信息包括第一请求进入所述网络延时查询接口的第二时刻和第一请求离开所述网络延时查询接口的第三时刻;Send the first request to the network delay query interface of the streaming media server, receive the feedback information of the network delay query interface, record the first moment of sending the first request and the fourth moment of receiving the feedback information; the feedback information includes The second time when the first request enters the network delay query interface and the third time when the first request leaves the network delay query interface;
根据所述第一时刻、所述第四时刻、所述第二时刻和所述第三时刻计算网络延迟时间。Calculate the network delay time according to the first moment, the fourth moment, the second moment and the third moment.
可选地,所述方法还包括:Optionally, the method also includes:
计算至少3次网络延迟时间;Calculate the network delay time at least 3 times;
去掉至少3次网络延迟时间中的最大值和最小值,得到剩余的网络延迟时间;Remove the maximum and minimum values of at least 3 network delay times to obtain the remaining network delay time;
将网络延迟时间更新为剩余的网络延迟时间的平均值。Update the network delay time to the average of the remaining network delay times.
另一方面,本发明实施例提供了一种多路视频同步方法,应用于流媒体服务器,包括:On the other hand, the embodiment of the present invention provides a multi-channel video synchronization method applied to a streaming media server, including:
接收推流端发送的视频流和网络延迟时间;Receive the video stream and network delay time sent by the streaming end;
根据所述视频流生成索引文件和媒体分片文件;其中,所述索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,所述媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间。Generate an index file and a media fragment file according to the video stream; wherein, the index file includes the reference time offset value information of the first frame image of each media fragment file, and the media fragment file includes the current video stream The network delay time for streaming to the streaming media server.
可选地,所述基准时间偏移值信息通过以下方法计算:Optionally, the reference time offset value information is calculated by the following method:
向时间基准服务器的查询接口发送第二请求;Send a second request to the query interface of the time reference server;
接收时间基准服务器的查询接口反馈的基准时间偏移值信息。Receive the reference time offset value information fed back by the query interface of the time reference server.
另一方面,本发明实施例提供了一种多路视频同步系统,应用于播放端,包括:On the other hand, the embodiment of the present invention provides a multi-channel video synchronization system, which is applied to the playback terminal, including:
第一模块,用于获取流媒体服务器发送的索引文件和媒体分片文件;其中,所述索引文件包括每个所述媒体分片文件的第一帧图像的基准时间偏移值信息,所述媒体分片文件包括当前视频流从推流端推流到所述流媒体服务器的网络延迟时间;The first module is used to obtain the index file and the media segment file sent by the streaming media server; wherein, the index file includes the reference time offset value information of the first frame image of each of the media segment files, and the The media segment file includes the network delay time for the current video stream to be pushed from the streaming end to the streaming server;
第二模块,用于根据当前视频流播放的当前时间位置、每个所述媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,并从所述索引文件获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值;The second module is used to determine the first media to be initially played by each video stream according to the current time position played by the current video stream, and the relative time relationship between the first frame image and the last frame image of each media fragment file Fragmentation file, and obtain the reference time offset value of the first frame image of the first media fragmentation file of the first media fragmentation file of each road video stream initial play from described index file;
第三模块,用于按照预设时间间隔,根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值;The third module is used to, according to the preset time interval, according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the current time of each video stream. The time of the first frame image of the first media fragment file played initially by the stream determines the reference time offset value of the current frame of each video stream;
第四模块,用于按照所述预设时间间隔,根据每路视频流当前帧的基准时间偏移值计算最大基准时间偏移值、最小基准时间偏移值和平均基准时间偏移值,根据所述最大基准时间偏移值与所述最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据所述平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作;所述同步操作包括刷新、快进或暂停。The fourth module is used to calculate the maximum reference time offset value, the minimum reference time offset value and the average reference time offset value according to the reference time offset value of the current frame of each video stream according to the preset time interval, according to The difference between the maximum reference time offset value and the minimum reference time offset value performs a synchronous operation on the normally played video stream, or according to the average reference time offset value and the reference time of the current frame of each video stream The relationship between the offset values performs a synchronous operation on a normally played video stream; the synchronous operation includes refreshing, fast forwarding or pausing.
另一方面,本发明实施例提供了一种多路视频同步系统,应用于推流端,包括:On the other hand, the embodiment of the present invention provides a multi-channel video synchronization system, which is applied to the streaming end, including:
第五模块,用于计算当前视频流从推流端推流到流媒体服务器的网络延迟时间;The fifth module is used to calculate the network delay time of the current video stream from the streaming end to the streaming server;
第六模块,用于将视频流和网络延迟时间发送给流媒体服务器,以使所述流媒体服务器生成索引文件和媒体分片文件。The sixth module is used to send the video stream and network delay time to the streaming media server, so that the streaming media server can generate index files and media segment files.
另一方面,本发明实施例提供了一种多路视频同步系统,应用于流媒体服务器,包括:On the other hand, an embodiment of the present invention provides a multi-channel video synchronization system applied to a streaming media server, including:
第七模块,用于接收推流端发送的视频流和网络延迟时间;The seventh module is used to receive the video stream and network delay time sent by the streaming end;
第八模块,用于根据所述视频流生成索引文件和媒体分片文件;其中,所述索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,所述媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间。The eighth module is used to generate an index file and a media fragment file according to the video stream; wherein, the index file includes the reference time offset value information of the first frame image of each media fragment file, and the media fragment The slice file includes the network delay time when the current video stream is pushed to the streaming media server.
另一方面,本发明实施例提供了一种多路视频同步装置,包括:On the other hand, an embodiment of the present invention provides a multi-channel video synchronization device, including:
至少一个处理器;at least one processor;
至少一个存储器,用于存储至少一个程序;at least one memory for storing at least one program;
当所述至少一个程序被所述至少一个处理器执行,使得所述至少一个处理器实现上述推流端、流媒体服务器或播放端任意一端的视频同步方法。When the at least one program is executed by the at least one processor, the at least one processor is made to implement the video synchronization method at any one of the streaming end, the streaming media server, or the playback end.
另一方面,本发明实施例提供了一种计算机可读存储介质,其中存储有处理器可执行的程序,所述处理器可执行的程序在由处理器执行时用于执行上述推流端、流媒体服务器或播放端任意一端的视频同步方法。On the other hand, an embodiment of the present invention provides a computer-readable storage medium, which stores a processor-executable program, and the processor-executable program is used to execute the above streaming end, A video synchronization method at either end of the streaming media server or playback end.
另一方面,本发明实施例提供了一种多路视频同步系统,包括流媒体服务器以及与所述流媒体服务器连接的推流端和播放端;其中,On the other hand, an embodiment of the present invention provides a multi-channel video synchronization system, including a streaming media server and a streaming end and a playing end connected to the streaming media server; wherein,
所述推流端,用于执行上述推流端的视频同步方法;The streaming end is used to execute the video synchronization method of the streaming end mentioned above;
所述流媒体服务器,用于执行流媒体服务器的视频同步方法;The streaming media server is used to execute the video synchronization method of the streaming media server;
所述播放端,用于执行播放端的视频同步方法。The playback terminal is used to execute the video synchronization method of the playback terminal.
实施本发明实施例包括以下有益效果:本实施例中首先,通过推流端计算当前视频流从推流端推流到流媒体服务器的网络延迟时间,并将网络延迟时间发送流媒体服务器,考虑了视频流从推流端推流到流媒体服务器的网络延时导致的视频时间误差;接着,通过媒体服务器对视频流生成索引文件和媒体分片文件,并将索引文件和媒体分片文件发送给播放端,其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间,通过基准时间偏移值信息考虑了不同流媒体服务器之间由于系统时间误差导致视频时间误差,可适用于多个不同的流媒体服务器;接着,播放端接收索引文件和媒体分片文件后,确定每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值,进而确定每路视频流当前帧的基准时间偏移值,并根据每路视频流当前帧的基准时间偏移值对正常播放的视频流进行同步操作,通过获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值确定每路视频流当前帧的基准时间偏移值,计算方法简单且无需解析媒体分片文件数据包,通过每路视频流当前帧的基准时间偏移值对正常播放的视频流进行同步操作,同步效果好,时间准确率可达到毫秒级别,可实现在直播场景中对多路视频流进行同步,且对每路视频流可单独控制。Implementing the embodiment of the present invention includes the following beneficial effects: first, in this embodiment, the network delay time of the current video stream from the stream pushing end to the streaming media server is calculated by the streaming end, and the network delay time is sent to the streaming media server, considering The video time error caused by the network delay of the video stream from the streaming end to the streaming media server is eliminated; then, the media server generates an index file and a media segment file for the video stream, and sends the index file and media segment file For the player, the index file includes the reference time offset value information of the first frame image of each media segment file, and the media segment file includes the network delay time for the current video stream to be pushed to the streaming media server, passing the reference time The offset value information takes into account the video time error caused by the system time error between different streaming media servers, and can be applied to multiple different streaming media servers; then, after the player receives the index file and the media fragment file, it determines the video time error of each channel. The base time offset value of the first frame image of the first media fragment file played initially by the stream, and then determine the base time offset value of the current frame of each video stream, and according to the base time offset value of the current frame of each video stream The offset value is used to synchronize the normal playing video stream, and determine the base time offset value of the current frame of each video stream by obtaining the base time offset value of the first frame image of the first media segment file initially played by each video stream. Shift value, the calculation method is simple and does not need to analyze the data packet of the media fragment file, and the normal playback video stream is synchronized through the reference time offset value of the current frame of each video stream, the synchronization effect is good, and the time accuracy can reach the millisecond level , which can realize the synchronization of multiple video streams in the live broadcast scene, and can control each video stream independently.
附图说明Description of drawings
图1是本发明实施例提供的一种多路视频同步系统的结构示意图;Fig. 1 is a schematic structural diagram of a multi-channel video synchronization system provided by an embodiment of the present invention;
图2是本发明实施例提供的一种应用于播放端的多路视频同步方法的步骤流程示意图;Fig. 2 is a schematic flow chart of the steps of a multi-channel video synchronization method applied to a playback terminal provided by an embodiment of the present invention;
图3是本发明实施例提供的一种确定视频流初始播放的第一个媒体分片文件的步骤流程示意图;Fig. 3 is a schematic flow chart of steps for determining the first media segment file for initial playback of a video stream provided by an embodiment of the present invention;
图4是本发明实施例提供的一种确定视频流当前帧的基准时间偏移值的步骤流程示意图;FIG. 4 is a schematic flowchart of steps for determining a reference time offset value of a current frame of a video stream provided by an embodiment of the present invention;
图5是本发明实施例提供的一种对多路视频进行同步操作的步骤流程示意图;FIG. 5 is a schematic flowchart of steps for synchronizing multiple channels of video provided by an embodiment of the present invention;
图6是本发明实施例提供的一种应用于推流端的多路视频同步方法的步骤流程示意图;Fig. 6 is a schematic flow chart of the steps of a multi-channel video synchronization method applied to the streaming terminal provided by an embodiment of the present invention;
图7是本发明实施例提供的一种应用于流媒体服务器的多路视频同步方法的步骤流程示意图;FIG. 7 is a schematic flow chart of the steps of a multi-channel video synchronization method applied to a streaming media server provided by an embodiment of the present invention;
图8是本发明实施例提供的一种应用于播放端的多路视频同步系统的结构框图;FIG. 8 is a structural block diagram of a multi-channel video synchronization system applied to a playback terminal provided by an embodiment of the present invention;
图9是本发明实施例提供的一种应用于推流端的多路视频同步系统的结构框图;FIG. 9 is a structural block diagram of a multi-channel video synchronization system applied to the streaming end provided by an embodiment of the present invention;
图10是本发明实施例提供的一种应用于流媒体服务器的多路视频同步系统的结构框图;FIG. 10 is a structural block diagram of a multi-channel video synchronization system applied to a streaming media server provided by an embodiment of the present invention;
图11是本发明实施例提供的一种路视频同步系统装置的结构框图。Fig. 11 is a structural block diagram of a road video synchronization system device provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面结合附图和具体实施例对本发明做进一步的详细说明。对于以下实施例中的步骤编号,其仅为了便于阐述说明而设置,对步骤之间的顺序不做任何限定,实施例中的各步骤的执行顺序均可根据本领域技术人员的理解来进行适应性调整。The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. For the step numbers in the following embodiments, it is only set for the convenience of illustration and description, and the order between the steps is not limited in any way. The execution order of each step in the embodiments can be adapted according to the understanding of those skilled in the art sexual adjustment.
可以理解,本发明实施例所使用的术语“第一”、“第二”等可在本文中用于描述各种概念,但除非特别说明,这些概念不受这些术语限制。这些术语仅用于将一个概念与另一个概念区分。It can be understood that terms such as "first" and "second" used in the embodiments of the present invention may be used to describe various concepts herein, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another.
本发明实施例所使用的术语“至少一个”、“多个”、“每个”、“任一”等,至少一个包括一个、两个或两个以上,多个包括两个或两个以上,每个是指对应的多个中的每一个,任一是指多个中的任意一个。The terms "at least one", "multiple", "each", "any", etc. used in the embodiments of the present invention, at least one includes one, two or more, and multiple includes two or more , each refers to each of the corresponding plurality, and any refers to any one of the plurality.
在相关技术中,多路HLS流媒体同步有两种模式,一种模式不能对每路视频流进行独立操作,另外一种模式受诸多条件的限制,无法应用到直播场景中。HLS流媒体播放延时原因主要有:1、推流服务器推流到流媒体服务器的网络延时;2、CDN分发延时、播放端下拉延时、解码渲染延时等。In related technologies, there are two modes for multi-channel HLS streaming media synchronization. One mode cannot independently operate each video stream, and the other mode is limited by many conditions and cannot be applied to live broadcast scenarios. The main reasons for the delay of HLS streaming media playback are: 1. The network delay of the streaming server pushing the stream to the streaming media server; 2. CDN distribution delay, playback end pull-down delay, decoding rendering delay, etc.
基于上述情况,本发明实施例提供了一种多路视频同步方法、系统、装置和存储介质,首先,通过推流端计算当前视频流从推流端推流到流媒体服务器的网络延迟时间,并将网络延迟时间发送流媒体服务器,考虑了视频流从推流端推流到流媒体服务器的网络延时导致的视频时间误差;接着,通过媒体服务器对视频流生成索引文件和媒体分片文件,并将索引文件和媒体分片文件发送给播放端,其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间,通过基准时间偏移值信息考虑了不同流媒体服务器之间由于系统时间误差导致视频时间误差,可适用于多个不同的流媒体服务器;接着,播放端接收索引文件和媒体分片文件后,确定每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值,进而确定每路视频流当前帧的基准时间偏移值,并根据每路视频流当前帧的基准时间偏移值对正常播放的视频流进行同步操作,通过获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值确定每路视频流当前帧的基准时间偏移值,计算方法简单且无需解析媒体分片文件数据包,通过每路视频流当前帧的基准时间偏移值对正常播放的视频流进行同步操作,可实现在直播场景中对多路视频流进行同步,同步效果好,时间准确率可达到毫秒级别,且对每路视频流可单独控制。Based on the above situation, embodiments of the present invention provide a multi-channel video synchronization method, system, device, and storage medium. First, the network delay time of the current video stream from the streaming end to the streaming media server is calculated through the streaming end, And send the network delay time to the streaming media server, taking into account the video time error caused by the network delay of the video stream from the streaming end to the streaming media server; then, generate index files and media fragment files for the video stream through the media server , and send the index file and media segment file to the player, where the index file includes the reference time offset value information of the first frame image of each media segment file, and the media segment file includes the current video stream pushed to The network delay time of the streaming media server, through the reference time offset value information, considers the video time error caused by the system time error between different streaming media servers, and can be applied to multiple different streaming media servers; then, the player receives the index file and the media fragment file, determine the reference time offset value of the first frame image of the first media fragment file initially played by each video stream, and then determine the reference time offset value of the current frame of each video stream, and Synchronize the normally played video streams according to the reference time offset value of the current frame of each video stream, by obtaining the reference time offset value of the first frame image of the first media segment file initially played by each video stream Determine the reference time offset value of the current frame of each video stream. The calculation method is simple and does not need to parse the media fragment file data packet. The normal playback video stream is synchronized through the reference time offset value of the current frame of each video stream. It can realize the synchronization of multiple video streams in the live broadcast scene, the synchronization effect is good, the time accuracy can reach the millisecond level, and each video stream can be controlled separately.
参阅图1,图1为本发明实施例提供的一种多路视频同步方法的实施环境的示意图,多路视频同步方法应用于多路视频同步系统中,多路视频同步系统包括推流端110、流媒体服务器120和播放端130。推流端110计算当前视频流的网络延迟时间,并将拍摄的视频流和当前视频流的网络时间发送给流媒体服务器120;流媒体服务器120将接收的视频流制作成索引文件和媒体分片文件,并将索引文件和媒体分片文件发送给播放端130;播放端130接收索引文件和媒体分片文件后,同时同步播放多路视频流。Referring to Fig. 1, Fig. 1 is a schematic diagram of an implementation environment of a multi-channel video synchronization method provided by an embodiment of the present invention, the multi-channel video synchronization method is applied in a multi-channel video synchronization system, and the multi-channel video synchronization system includes a streaming terminal 110 , streaming media server 120 and player 130. The streaming terminal 110 calculates the network delay time of the current video stream, and sends the captured video stream and the network time of the current video stream to the streaming media server 120; the streaming media server 120 makes the received video stream into index files and media fragments file, and send the index file and the media fragment file to the playback terminal 130; after the playback terminal 130 receives the index file and the media fragment file, it simultaneously plays multiple video streams synchronously.
需要说明的是,推流端110与流媒体服务器120通过有线或无线方式连接,流媒体服务器120与播放端130通过有线或无线方式连接。流媒体服务器120也可以是多个流媒体服务器组成的集群,集群中流媒体服务器的数量根据实际应用的需求确定。本申请实施例中所涉及的推流端110或播放端130包括但不限于智能手机、电脑、智能语音交互设备、智能家电、车载终端、飞行器等。It should be noted that the streaming end 110 is connected to the streaming media server 120 by wire or wirelessly, and the streaming media server 120 is connected to the playback end 130 by wire or wirelessly. The streaming media server 120 may also be a cluster composed of multiple streaming media servers, and the number of streaming media servers in the cluster is determined according to actual application requirements. The push stream terminal 110 or the playback terminal 130 involved in the embodiment of the present application includes, but is not limited to, smart phones, computers, smart voice interaction devices, smart home appliances, vehicle terminals, aircraft, and the like.
参阅图2,本发明实施例提供了一种多路视频同步方法,应用于播放端,包括以下步骤:Referring to Fig. 2, the embodiment of the present invention provides a kind of multi-channel video synchronous method, is applied to the playback end, comprises the following steps:
S110、获取流媒体服务器发送的索引文件和媒体分片文件;其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流从推流端推流到流媒体服务器的网络延迟时间。S110, obtain the index file and the media segment file sent by the streaming media server; wherein, the index file includes the reference time offset value information of the first frame image of each media segment file, and the media segment file includes the current video stream from the pushed The network delay time when the streaming end pushes the stream to the streaming media server.
播放端接收流媒体服务器发送的索引文件和媒体分片文件。在本实施例中,索引文件包括但不限于M3U8文件,媒体分片文件包括但不限于TS文件。媒体分片文件的第一帧图像的基准时间偏移值信息在索引文件中的位置根据实际应用确定,当前视频流从推流端推流到流媒体服务器的网络延迟时间在媒体分片文件的位置根据实际应用确定,本实施例不做具体限制。The playback end receives the index file and the media segment file sent by the streaming media server. In this embodiment, the index file includes but not limited to M3U8 file, and the media segment file includes but not limited to TS file. The position of the reference time offset value information of the first frame image of the media segment file in the index file is determined according to the actual application. The network delay time of the current video stream from the streaming end to the streaming server is within the The location is determined according to actual applications, and is not specifically limited in this embodiment.
S120、根据当前视频流播放的当前时间位置、每个媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,并从索引文件获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值。S120, according to the current time position of the current video stream playback, the relative time relationship between the first frame image and the last frame image of each media segment file, determine the first media segment file for the initial playback of each video stream, and from The index file obtains the reference time offset value of the first frame image of the first media segment file initially played by each video stream.
在HLS播放端播放视频时,M3U8文件包括了多个TS文件,播放器并不一定是从M3U8文件中TS文件列表中的第一个TS文件开始播放,所以需要通过分析当前视频播放的当前位置和每个TS切片的第一帧的相对时间及最后一帧的相对时间的关系,确认当前播放端每路流最开始播放的是哪个TS文件,然后获取该路视频流的第一帧对应的基准时间偏移值(单位毫秒)。When playing video on the HLS player side, the M3U8 file includes multiple TS files, and the player does not necessarily start playing from the first TS file in the TS file list in the M3U8 file, so it needs to analyze the current position of the current video playback The relationship between the relative time of the first frame and the relative time of the last frame of each TS slice, confirm which TS file is played at the beginning of each stream on the current player, and then obtain the corresponding TS file of the first frame of the video stream The base time offset value (in milliseconds).
S130、按照预设时间间隔,根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值。S130. According to the preset time interval, according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the initial playback time of each video stream The time of the first frame image of the first media segment file determines the reference time offset value of the current frame of each video stream.
需要说明的是,预设时间间隔指视频同步的时间间隔,预设时间间隔根据实际应用确定,本实施例不做具体限制,例如,预设时间间隔设置为1秒。It should be noted that the preset time interval refers to the time interval of video synchronization, and the preset time interval is determined according to the actual application. This embodiment does not make specific limitations. For example, the preset time interval is set to 1 second.
播放端通过计算每路视频流最开始播放的TS文件的第一帧对应的基准时间偏移值、当前视频流播放时间、当前TS文件播放到的最新一帧对应的生成这帧时的基准时间偏移值计算每路视频流当前帧的基准时间偏移值,获取的基准时间已经考虑到了推流端推流延时的因素,更准确。其中,当前视频流播放时间可通过网页H5原生js可直接获取,当前TS文件播放到的最新一帧对应的生成这帧时的基准时间偏移值可通过当前TS文件的文件名获取。需要说明的是,当上述时间单位不一致,进行单位转换,例如,最开始播放的TS文件的第一帧对应的基准时间偏移值的单位为秒,当前视频流播放时间的单位为毫秒,计算过程中,需要将毫秒和秒进行换算。The playback end calculates the reference time offset value corresponding to the first frame of the TS file played at the beginning of each video stream, the current video stream playback time, and the reference time when the frame is generated corresponding to the latest frame played by the current TS file The offset value calculates the reference time offset value of the current frame of each video stream, and the obtained reference time has taken into account the delay factor of the streaming end, which is more accurate. Among them, the current video stream playback time can be directly obtained through the native js of the web page H5, and the reference time offset value corresponding to the latest frame played by the current TS file when generating this frame can be obtained through the file name of the current TS file. It should be noted that when the above time units are inconsistent, unit conversion is performed. For example, the unit of the reference time offset value corresponding to the first frame of the TS file played at the beginning is seconds, and the unit of the current video stream playback time is milliseconds. Calculate During the process, milliseconds and seconds need to be converted.
S140、按照预设时间间隔,根据每路视频流当前帧的基准时间偏移值计算最大基准时间偏移值、最小基准时间偏移值和平均基准时间偏移值,根据最大基准时间偏移值与最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作;同步操作包括刷新、快进或暂停。S140. According to the preset time interval, calculate the maximum reference time offset value, the minimum reference time offset value and the average reference time offset value according to the reference time offset value of the current frame of each video stream, and calculate the maximum reference time offset value according to the maximum reference time offset value The difference between the minimum reference time offset value and the normal playback video stream is synchronized, or according to the relationship between the average reference time offset value and the reference time offset value of the current frame of each video stream. Streams perform synchronous operations; synchronous operations include flushing, fast-forwarding, or pausing.
同理,预设时间间隔指视频同步的时间间隔,预设时间间隔根据实际应用确定,本实施例不做具体限制,例如,预设时间间隔设置为1秒。Similarly, the preset time interval refers to the time interval of video synchronization, and the preset time interval is determined according to the actual application. This embodiment does not make specific limitations. For example, the preset time interval is set to 1 second.
具体地,播放端首先根据每路视频流当前帧的基准时间偏移值确定最大基准时间偏移值、最小基准时间偏移值和平均基准时间偏移值等特征参数,然后根据这些特征参数对正常播放的视频流进行同步操作,或根据这些特征参数与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作。Specifically, the player first determines characteristic parameters such as the maximum reference time offset value, the minimum reference time offset value, and the average reference time offset value based on the reference time offset value of the current frame of each video stream, and then determines the Synchronize the normally played video streams, or perform synchronous operations on the normally played video streams according to the relationship between these characteristic parameters and the reference time offset value of the current frame of each video stream.
可选地,播放端的多路视频同步方法还包括:Optionally, the multi-channel video synchronization method at the playback end also includes:
S150、对于未正常播放的视频流,暂停同步操作,直至重新正常播放;未正常播放包括暂停状态、视频加载中状态或视频加载失败状态中的任意一种。S150. For the video stream that is not being played normally, the synchronous operation is suspended until it is played normally again; the abnormal playing includes any one of a paused state, a video loading state, or a video loading failure state.
需要说明的是,参与同步的视频流不包括处于暂停状态、视频加载中状态或者视频加载失败等未正常播放的视频流,当这三种视频流正常播放后即可参与视频同步。对未正常播放的视频流暂停同步操作,可以减少不必要的计算量,减轻运算压力。It should be noted that the video streams participating in the synchronization do not include the video streams that are not playing normally, such as those in the paused state, the video loading state, or the video loading failure. When these three video streams are playing normally, they can participate in the video synchronization. Pausing the synchronous operation of the video stream that is not played normally can reduce the unnecessary calculation amount and reduce the calculation pressure.
可选地,参阅图3,根据当前视频流播放的当前时间位置、每个媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,具体包括:Optionally, referring to FIG. 3, the first media to be initially played by each video stream is determined according to the current time position played by the current video stream, and the relative time relationship between the first frame image and the last frame image of each media segment file. Fragmented files, specifically including:
S121、分别每路视频流中每个媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流中每个媒体分片文件的时长;S121. The relative time relationship between the first frame image and the last frame image of each media segment file in each video stream determines the duration of each media segment file in each video stream;
S122、按照时间顺序将每路视频流中每个媒体分片文件的时长进行累加,得到每路视频流中每个媒体分片文件的累加时间;S122. Accumulate the duration of each media segment file in each video stream according to time sequence, to obtain the accumulated time of each media segment file in each video stream;
S123、将每路当前视频流播放的当前时间位置与每路视频流的累加时间进行匹配,确定每路视频流初始播放的第一个媒体分片文件。S123. Match the current time position played by each current video stream with the accumulated time of each video stream, and determine the first media segment file initially played by each video stream.
具体地,最后一帧图像的播放时间减去第一帧图像的播放时间可得到每个媒体分片文件的时长;按照媒体分片的播放时间顺序将每路视频流中每个媒体分片文件的时长进行累加,得到每路视频流中每个媒体分片文件的累加时间;当前视频流播放的当前时间位置在某个累加时间范围内,将该累加时间范围内对应的媒体分片文件作为第一个媒体分片文件。Specifically, the duration of each media segment file can be obtained by subtracting the playback time of the first frame image from the playback time of the last frame image; The accumulated time of each media fragment file in each video stream is accumulated; the current time position of the current video stream playback is within a certain accumulation time range, and the corresponding media fragment file within the accumulation time range is used as The first media slice file.
具体地,获取每路视频流第一个播放的TS文件的函数如下:Specifically, the function to obtain the first TS file played by each video stream is as follows:
Fb=fb(Tscx,Tsd1,Tsf1,Tsd2,Tsf2,Tsd3,Tsf3……Tsdn,Tsfn)Fb=fb(Tsc x ,Tsd 1 ,Tsf 1 ,Tsd 2 ,Tsf 2 ,Tsd 3 ,Tsf 3 ...Tsd n ,Tsf n )
其中,Fb为当前流第一个播放的TS文件的文件名,fb为获取当前流第一个播放的TS文件的文件名的函数,Tscx为第x个播放器初始播放时的currentTime(视频播放的当前初始位置),Tsd1为第一个TS文件的总时长,Tsf1为第一个TS文件的文件名,Tsdn为第n个TS文件的总时长,Tsfn为第n个TS文件的文件名;当Tsc∈[0,Tsd1),则返回Tsf1,当 则返回Tsfn。Among them, Fb is the file name of the TS file played first in the current stream, fb is a function to obtain the file name of the TS file played first in the current stream, and Tsc x is the currentTime when the xth player initially plays (video The current initial position of playback), Tsd 1 is the total duration of the first TS file, Tsf 1 is the file name of the first TS file, Tsd n is the total duration of the nth TS file, Tsf n is the nth TS The file name of the file; when Tsc∈[0,Tsd 1 ), then return Tsf 1 , when Then return Tsf n .
在一个具体的实施例中,HLS播放端记录每路HLS视频流初始时间:In a specific embodiment, the HLS player records the initial time of each HLS video stream:
当每路HLS视频流开始播放时,记录每个播放器的currentTime(视频初始播放的currentTime,这个时间是播放器自己生成的时间)。示例性地,有3路视频流,分别将第一路视频流记为Tsc1,第二路视频流记为Tsc2,第三路视频流记为Tsc3。When each HLS video stream starts to play, record the currentTime of each player (the currentTime of the initial video playback, this time is the time generated by the player itself). Exemplarily, there are 3 video streams, and the first video stream is marked as Tsc 1 , the second video stream is marked as Tsc 2 , and the third video stream is marked as Tsc 3 .
分析当前播放的HLS的M3U8文件信息:当每个HLS视频开始播放时,通过分析对应的M3U8文件信息,获取第一个播放的TS文件(不一定是从第一个TS文件开始播放)。Analyze the M3U8 file information of the currently playing HLS: When each HLS video starts to play, by analyzing the corresponding M3U8 file information, obtain the first played TS file (not necessarily starting from the first TS file).
在一个具体的实施例中,shili.m3u8文件内容如下:In a specific embodiment, the content of the shili.m3u8 file is as follows:
#EXTM3U#EXTM3U
#EXT-X-VERSION:3#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:4176#EXT-X-MEDIA-SEQUENCE:4176
#EXT-X-TARGETDURATION:10#EXT-X-TARGETDURATION:10
#EXTINF:9.493,1234#EXTINF: 9.493,1234
73e162672dd62b880192796a1816b998_20.ts73e162672dd62b880192796a1816b998_20.ts
#EXTINF:8.322,10727#EXTINF: 8.322,10727
d5b8473b826887491449319f277c7c06_40.tsd5b8473b826887491449319f277c7c06_40.ts
#EXTINF:2.633,19049#EXTINF: 2.633,19049
e88dd1fd8aa1b880e16618de42e25230_125.tse88dd1fd8aa1b880e16618de42e25230_125.ts
这个M3U8文件里有3个TS文件的信息,第一个TS文件信息为:There are 3 TS file information in this M3U8 file, the first TS file information is:
#EXTINF:9.493,1234#EXTINF: 9.493,1234
73e162672dd62b880192796a1816b998_20.ts73e162672dd62b880192796a1816b998_20.ts
第一行包括2个值,2个值直接用英文逗号分割,其中第一个值表示当前的TS文件时长9.493秒,也就是当前TS文件第一帧的时间为0(单位秒)的话,最后一帧则为9.493(单位秒);第二个值(此处为1234)表示当前视频文件第一帧对应的基准时间偏移值(单位毫秒)。The first line includes 2 values, which are directly separated by commas. The first value indicates that the current TS file is 9.493 seconds long, that is, if the first frame time of the current TS file is 0 (in seconds), the last One frame is 9.493 (in seconds); the second value (here, 1234) represents the reference time offset value (in milliseconds) corresponding to the first frame of the current video file.
第二行包含了当前TS文件的视频文件名称,播放器通过这个名称下载ts视频文件。(此处文件名中的20)表示当前视频流的推流端推流到流媒体服务器网络延时(单位毫秒)。The second line contains the video file name of the current TS file, and the player downloads the ts video file through this name. (20 in the file name here) indicates the network delay (in milliseconds) of the current video stream push end to the streaming media server.
第二个TS文件信息为:The second TS file information is:
#EXTINF:8.322,10727#EXTINF: 8.322,10727
d5b8473b826887491449319f277c7c06_40.tsd5b8473b826887491449319f277c7c06_40.ts
第一行包括2个值,2个值直接用英文逗号分割,其中第一个值表示当前的TS文件时长8.322秒,也就是当前TS文件第一帧的时间为9.493(单位秒,以当前M3U8文件中的第一个TS文件的第一帧为起始时间)的话,最后一帧则为9.493+8.322=17.815(单位秒);第二个值(此处为10727)表示当前视频文件第一帧对应的基准时间偏移值(单位毫秒)。The first line includes 2 values, the 2 values are directly separated by English commas, the first value indicates that the current TS file is 8.322 seconds long, that is, the time of the first frame of the current TS file is 9.493 (in seconds, in the current M3U8 If the first frame of the first TS file in the file is the start time), the last frame is 9.493+8.322=17.815 (unit second); the second value (here is 10727) indicates that the current video file is the first The reference time offset value corresponding to the frame (in milliseconds).
第二行包含了当前TS文件的视频文件名称,播放器通过这个名称下载ts视频文件(此处文件名中的40)表示当前视频流的推流端推流到流媒体服务器网络延时(单位毫秒)。The second line contains the video file name of the current TS file. The player downloads the ts video file through this name (40 in the file name here) indicates the network delay (unit: millisecond).
第三个TS文件信息为:The third TS file information is:
#EXTINF:2.633,19049#EXTINF: 2.633,19049
e88dd1fd8aa1b880e16618de42e25230_125.tse88dd1fd8aa1b880e16618de42e25230_125.ts
第一行包括2个值,2个值直接用英文逗号分割,其中第一个值表示当前的TS文件时长2.633秒,也就是当前TS文件第一帧的时间为17.815(单位秒,以当前M3U8文件中的第一个TS文件的第一帧为起始时间)的话,最后一帧则为9.493+8.322+2.633=20.448(单位秒);第二个值(此处为19049)表示当前视频文件第一帧对应的基准时间偏移值(单位毫秒)。第二行包含了当前TS文件的视频文件名称,播放器通过这个名称下载ts视频文件(此处文件名中的125)表示当前视频流的推流端推流到流媒体服务器网络延时(单位毫秒)。The first line includes 2 values, which are directly separated by English commas. The first value indicates that the current TS file is 2.633 seconds long, that is, the time of the first frame of the current TS file is 17.815 (in seconds, in the current M3U8 If the first frame of the first TS file in the file is the start time), the last frame is 9.493+8.322+2.633=20.448 (in seconds); the second value (19049 here) represents the current video file The reference time offset value corresponding to the first frame (in milliseconds). The second line contains the video file name of the current TS file, through which the player downloads the ts video file (125 in the file name here) indicates the network delay (unit: millisecond).
当每个HLS视频开始播放时,判断当前播放器的Tsc1是在以上3个TS文件中哪个文件的起始时间内,即可判断当前流第一个播放是是哪个TS文件。例如:当0≤Tsc1<9.493,则表示当前播放器初始播放的是第一个TS文件;17.815≤Tsc1<20.448,则表示当前播放器初始播放的是第三个TS文件。When each HLS video starts to play, judge whether the Tsc1 of the current player is within the start time of which of the above three TS files, and then judge which TS file is the first to play in the current stream. For example: when 0≤Tsc1<9.493, it means that the current player initially plays the first TS file; 17.815≤Tsc1<20.448, then it means that the current player initially plays the third TS file.
可选地,参阅图4,根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值,具体包括:Optionally, referring to FIG. 4 , according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the initial playback time of each video stream The time of the first frame image of the first media segment file determines the reference time offset value of the current frame of each video stream, including:
S131、计算每路视频流的当前时间与每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间的差值;S131. Calculate the difference between the current time of each video stream and the time of the first frame image of the first media segment file initially played by each video stream;
S132、根据差值与每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值确定每路视频流当前帧的基准时间偏移值。S132. Determine the reference time offset value of the current frame of each video stream according to the difference value and the reference time offset value of the first frame image of the first media segment file initially played by each video stream.
在一个具体的实施例中,计算每路流播放到的具体基准时间偏移值(以流媒体服务器时间计量)的公式为:In a specific embodiment, the formula for calculating the specific reference time offset value (measured in streaming media server time) played by each stream is:
Tx=Tssx+(Tcx-Tscx)×1000T x =Tss x +(Tc x -Tsc x )×1000
其中,Tx表示第X路视频流播放到的最新一帧的基准时间偏移值,Tssx表示第X路视频流开始播放的第一个TS文件第一帧对应的流媒体服务器基准时间偏移值,单位为毫秒;Tcx表示第X路视频流最新的当前时间currentTime值,单位为秒;Tscx表示第X路视频流开始播放第一个TS文件第一帧的当前时间currentTime值,单位为秒。Among them, Tx represents the reference time offset value of the latest frame played by the X-th video stream, and Tss x represents the stream media server’s reference time offset corresponding to the first frame of the first TS file starting to play the X-th video stream Value, in milliseconds; Tc x indicates the latest current time value of the Xth video stream, in seconds; Tsc x indicates the current time currentTime value of the Xth video stream starting to play the first frame of the first TS file, in units for seconds.
例如,获取每路HLS流播放的当前时间(currentTime)以及播放时长,每路HLS流播放的当前时间如下:第一路视频流的当前时间记为Tc1,第二路视频流的当前时间记为Tc2,第三路视频流的当前时间记为Tc3;每路HLS流播放的当前时长如下:第一路视频流的当前时长记为Tt1=Tc1-Tsc1,第二路视频流的当前时长记为Tt2=Tc2-Tsc2,第三路视频流的当前时长记为Tt3=Tc3-Tsc3;每路流初始播放的第一个TS文件最新一帧的基准时间偏移值如下:第一路视频流初始播放的第一个TS文件的第一帧的基准时间偏移值记为Tss1,第二路视频流初始播放的第一个TS文件的第一帧的基准时间偏移值记为Tss2,第三路视频流初始播放的第一个TS文件的第一帧的基准时间偏移值记为Tss3。每路HLS流播放的当前帧的基准时间偏移值计算如下:第一路视频流播放到的最新一帧的基准时间偏移值:T1=Tss1+(Tc1-Tsc1)×1000,第二路视频流播放到的最新一帧的基准时间偏移值:T2=Tss2+(Tc2-Tsc2)×1000,第三路视频流播放到的最新一帧的基准时间偏移值:T3=Tss3+(Tc3-Tsc3)×1000。For example, to obtain the current time (currentTime) and playback duration of each HLS stream, the current time of each HLS stream is as follows: the current time of the first video stream is recorded as Tc 1 , and the current time of the second video stream is recorded as is Tc 2 , the current time of the third video stream is recorded as Tc 3 ; the current duration of each HLS stream is as follows: the current duration of the first video stream is recorded as Tt 1 = Tc 1 -Tsc 1 , the second video stream The current duration of the stream is recorded as Tt 2 = Tc 2 -Tsc 2 , and the current duration of the third video stream is recorded as Tt 3 = Tc 3 -Tsc 3 ; the benchmark of the latest frame of the first TS file initially played by each stream The time offset value is as follows: the reference time offset value of the first frame of the first TS file initially played by the first video stream is recorded as Tss 1 , and the first frame of the first TS file initially played by the second video stream is recorded as Tss 1 . The reference time offset value of the frame is recorded as Tss 2 , and the reference time offset value of the first frame of the first TS file initially played by the third video stream is recorded as Tss 3 . The reference time offset value of the current frame played by each HLS stream is calculated as follows: The reference time offset value of the latest frame played by the first video stream: T 1 =Tss 1 +(Tc 1 -Tsc 1 )×1000 , the reference time offset value of the latest frame played by the second video stream: T 2 =Tss 2 +(Tc 2 -Tsc 2 )×1000, the reference time offset value of the latest frame played by the third video stream Shift value: T 3 =Tss 3 +(Tc 3 −Tsc 3 )×1000.
可选地,参阅图5,根据最大基准时间偏移值与最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作,具体包括:Optionally, referring to FIG. 5 , the normal playing video stream is synchronized according to the difference between the maximum reference time offset value and the minimum reference time offset value, or according to the average reference time offset value and the current frame of each video stream The relationship between the reference time offset values of the normal playback video stream is synchronized, including:
S141、对于正常播放的视频流,若最大基准时间偏移值与最小基准时间偏移值的差值大于预设阈值,刷新各路视频流;S141. For a normally played video stream, if the difference between the maximum reference time offset value and the minimum reference time offset value is greater than a preset threshold, refresh each video stream;
S142、若最大基准时间偏移值与最小基准时间偏移值的差值小于预设阈值,且平均基准时间偏移值大于当前帧的基准时间偏移值,将该路视频流快进第一预设时间段;S142. If the difference between the maximum reference time offset value and the minimum reference time offset value is less than the preset threshold, and the average reference time offset value is greater than the reference time offset value of the current frame, fast forward the video stream to the first preset time period;
S143、若最大基准时间偏移值与最小基准时间偏移值的差值小于预设阈值,且平均基准时间偏移值小于当前帧的基准时间偏移值,将该路视频流暂停第二预设时间段。S143. If the difference between the maximum reference time offset value and the minimum reference time offset value is less than the preset threshold, and the average reference time offset value is less than the reference time offset value of the current frame, suspend the video stream for the second preview Set time period.
需要说明的是,预设阈值根据实际应用确定,本实施例不做具体限制,例如,预设阈值取值为80秒。第一预设时间段或第二预设时间段根据平均基准时间偏移值与当前帧的基准时间偏移值的大小确定。It should be noted that the preset threshold is determined according to an actual application and is not specifically limited in this embodiment. For example, the preset threshold is 80 seconds. The first preset time period or the second preset time period is determined according to the magnitude of the average reference time offset value and the reference time offset value of the current frame.
具体地,通过比较每路视频流播放到最新一帧的具体基准时间偏移值Tx;计算各路视频流最大Tx记作Tmax,各路流最小Tx记作Tmin。如果Tmax-Tmin大于一定的阈值(例如100秒)执行同步操作,同步操作分为2种方案。首先判断是否符合同步方案1:当Tmax-Tmin过大时,超过一个设定的阈值,例如3000毫秒,则通过播放器刷新各路参与同步的视频流进行同步,否则使用同步方案2;同步方案2:通过计算获得各路流播放到最新一帧的具体基准时间偏移值的平均的值记作Tpj,然后将每路视频流的Tx值与Tpj做比较,播放慢的流快进到Tpj-Tx毫秒,播放快的视频流通过暂停Tx-Tpj的时长后再开始播放,以达到各路流同步播放的效果。当Tmax-Tmin过大时,超过一个设定的阈值,这种情况使用同步方案2效果不好,会引起视频频繁重新加载的情况,故采用同步方案1。Specifically, the maximum T x of each video stream is calculated as Tmax, and the minimum T x of each stream is recorded as Tmin by comparing the specific reference time offset value T x of each video stream played to the latest frame. If Tmax-Tmin is greater than a certain threshold (for example, 100 seconds), the synchronization operation is performed, and the synchronization operation is divided into two schemes. First judge whether it meets the synchronization scheme 1: when Tmax-Tmin is too large and exceeds a set threshold, such as 3000 milliseconds, then use the player to refresh the video streams participating in synchronization for synchronization, otherwise use synchronization scheme 2; synchronization scheme 2: Calculate and obtain the average value of the specific reference time offset value of each stream played to the latest frame as Tpj, and then compare the T x value of each video stream with Tpj, and fast-forward the slow stream to Tpj-T x milliseconds, the fast-playing video stream starts playing after pausing for the duration of T x- Tpj, so as to achieve the effect of synchronous playback of all streams. When Tmax-Tmin is too large, it exceeds a set threshold. In this case, the effect of using synchronization scheme 2 is not good, and it will cause frequent reloading of the video, so synchronization scheme 1 is used.
参阅图6,本发明实施例提供了一种多路视频同步方法,应用于推流端,包括:Referring to Fig. 6, the embodiment of the present invention provides a multi-channel video synchronization method, which is applied to the streaming end, including:
S210、计算当前视频流从推流端推流到流媒体服务器的网络延迟时间;S210. Calculate the network delay time of the current video stream from the streaming end to the streaming media server;
S220、将视频流和网络延迟时间发送给流媒体服务器,以使流媒体服务器生成索引文件和媒体分片文件,其中,所述索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息。S220. Send the video stream and network delay time to the streaming media server, so that the streaming media server generates an index file and a media segment file, wherein the index file includes the reference time of the first frame image of each media segment file Offset information.
具体地,推流端首先计算当前视频流从推流端推流到流媒体服务器的网络延迟时间,然后将将多路视频流和网络延迟时间发送给流媒体服务器;流媒体服务器接收多路视频流和网络延迟时间后,生成索引文件和媒体分片文件。Specifically, the streaming terminal first calculates the network delay time of the current video stream from the streaming terminal to the streaming server, and then sends the multiple video streams and network delay time to the streaming server; the streaming server receives multiple video streams After stream and network delay time, generate index file and media fragment file.
可选地,网络延迟时间的通过以下方法计算:Optionally, the network delay time is calculated by the following method:
S211、向流媒体服务器的网络延时查询接口发送第一请求,接收网络延时查询接口的反馈信息,记录发送第一请求的第一时刻和接收反馈信息的第四时刻;反馈信息包括第一请求进入网络延时查询接口的第二时刻和第一请求离开网络延时查询接口的第三时刻;S211. Send the first request to the network delay query interface of the streaming media server, receive the feedback information from the network delay query interface, and record the first moment of sending the first request and the fourth moment of receiving the feedback information; the feedback information includes the first The second moment when the request enters the network delay query interface and the third moment when the first request leaves the network delay query interface;
S212、根据第一时刻、第四时刻、第二时刻和第三时刻计算网络延迟时间。S212. Calculate the network delay time according to the first moment, the fourth moment, the second moment and the third moment.
具体地,推流端向流媒体服务器的网络延时查询接口发送请求,并接收反馈信息,然后根据反馈信息、发送时刻和接收时刻计算网络延迟时间。例如,计算出每路流从推流端到流媒体服务器的网络延迟的毫秒数(记做TTLYS),并做记录。TTLYS的计算方法为从推流端发送请求到流媒体服务器提供的网络延时查询接口,推流端记录发送请求时间TTLFS(毫秒数)及接收返回值时间TTLFH(毫秒数),网络延时查询接口返回的数据包括请求进入接口时间TTLJR(毫秒数),及请求离开接口时间TTLLK(毫秒数)。推流端推流到流媒体服务器网络延时计算公式为:TTLYS=(TTLFH-TTLFS-(TTLLK-TTLJR))/2。Specifically, the streaming end sends a request to the network delay query interface of the streaming media server, receives feedback information, and then calculates the network delay time according to the feedback information, sending time and receiving time. For example, calculate and record the number of milliseconds of network delay from the streaming end to the streaming media server for each stream (recorded as T TLYS ). The calculation method of T TLYS is to send the request from the streaming end to the network delay query interface provided by the streaming media server. The streaming end records the sending request time T TLFS (in milliseconds) and the time of receiving the return value T TLFH (in milliseconds). The data returned by the delay query interface includes the time T TLJR (number of milliseconds) when the request enters the interface, and the time T TLLK (number of milliseconds) when the request leaves the interface. The formula for calculating the network delay of streaming from the streaming end to the streaming media server is: T TLYS =(T TLFH -T TLFS -(T TLLK -T TLJR ))/2.
可选地,方法还包括:Optionally, the method also includes:
S2121、计算至少3次网络延迟时间;S2121. Calculate the network delay time at least 3 times;
S2122、去掉至少3次网络延迟时间中的最大值和最小值,得到剩余的网络延迟时间;S2122. Remove the maximum and minimum values of at least three network delay times to obtain the remaining network delay time;
S2123、将网络延迟时间更新为剩余的网络延迟时间的平均值。S2123. Update the network delay time to the average value of the remaining network delay time.
为了提高推流端推流到流媒体服务器网络延时的准确性,TTLYS需要测试大于或等于3次,然后去掉一个最大值和一个最小值,剩余的值取平均数记作TTLYSPJ。例如,计算4次网络延迟时间分别为:1s、0.5s、0.8s、0.9s,去掉最大值1s和最小值0.5s,网络延迟时间的平均值为(0.8+0.9)/2=0.85s,最终计算得到的网络延迟时间为0.85s。In order to improve the accuracy of the network delay from the streaming end to the streaming media server, T TLYS needs to be tested more than or equal to 3 times, then remove a maximum value and a minimum value, and take the average of the remaining values as T TLYSPJ . For example, calculate the network delay time 4 times as: 1s, 0.5s, 0.8s, 0.9s, remove the maximum value of 1s and the minimum value of 0.5s, the average value of the network delay time is (0.8+0.9)/2=0.85s, The final calculated network delay time is 0.85s.
参阅图7,本发明实施例提供了一种多路视频同步方法,应用于流媒体服务器,包括:Referring to Fig. 7, the embodiment of the present invention provides a kind of multi-channel video synchronous method, is applied to streaming media server, comprises:
S310、接收推流端发送的视频流和网络延迟时间;S310. Receive the video stream and the network delay time sent by the streaming end;
S320、根据视频流生成索引文件和媒体分片文件;其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间。S320, generate an index file and a media fragment file according to the video stream; wherein, the index file includes the reference time offset value information of the first frame image of each media fragment file, and the media fragment file includes the current video stream pushed to the stream The network latency of the media server.
具体地,流媒体服务器接收推流端发送的视频流和网络延迟时间,然后根据视频流和网络延迟时间生成索引文件和媒体分片文件。需要说明的是,基准时间偏移值信息和网络延迟时间的存储位置根据实际应用确定,本实施例不做具体限制。Specifically, the streaming media server receives the video stream and network delay time sent by the streaming end, and then generates index files and media segment files according to the video stream and network delay time. It should be noted that the storage locations of the reference time offset value information and the network delay time are determined according to actual applications, and are not specifically limited in this embodiment.
在一个具体的实施例中,在流媒体服务器对视频推流进行切片(生成TS文件)时将每个切片的第一帧对应的基准时间偏移值信息写入到M3U8文件中当前切片对应的#EXTINF的duration值后面,中间英文逗号分割;同时将当前视频流推流到流媒体服务器的网络延迟的毫秒数TTLYS包含在当前TS文件的名称中,中间用符号和其它文件名部分隔开。例如,TS文件名xxxx_20.ts中20为当前视频流推流到流媒体服务器的网络延迟的毫秒数。M3U8的示例文件如下:In a specific embodiment, when the streaming server slices the video push stream (generates a TS file), the reference time offset value information corresponding to the first frame of each slice is written into the M3U8 file corresponding to the current slice. After the duration value of #EXTINF, the middle English comma is separated; at the same time, the number of milliseconds T TLYS of the network delay for pushing the current video stream to the streaming media server is included in the name of the current TS file, separated by symbols and other file names in the middle . For example, 20 in the TS file name xxxx_20.ts is the number of milliseconds of network delay for the current video stream to be pushed to the streaming media server. The sample file of M3U8 is as follows:
shili.m3u8文件内容为:The content of the shili.m3u8 file is:
#EXTM3U#EXTM3U
#EXT-X-VERSION:3#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:4176#EXT-X-MEDIA-SEQUENCE:4176
#EXT-X-TARGETDURATION:10#EXT-X-TARGETDURATION:10
#EXTINF:9.493,1234#EXTINF: 9.493,1234
73e162672dd62b880192796a1816b998_20.ts73e162672dd62b880192796a1816b998_20.ts
#EXTINF:8.322,10727#EXTINF: 8.322,10727
d5b8473b826887491449319f277c7c06_40.tsd5b8473b826887491449319f277c7c06_40.ts
#EXTINF:2.633,19049#EXTINF: 2.633,19049
e88dd1fd8aa1b880e16618de42e25230_125.tse88dd1fd8aa1b880e16618de42e25230_125.ts
可选地,基准时间偏移值信息通过以下方法计算:Optionally, the reference time offset value information is calculated by the following method:
S321、向时间基准服务器的查询接口发送第二请求;S321. Send a second request to the query interface of the time reference server;
S322、接收时间基准服务器的查询接口反馈的基准时间偏移值信息。S322. Receive reference time offset value information fed back by the query interface of the time reference server.
具体地,时间基准服务器为流媒体服务器集群提供统一的基准时间偏移值获取服务。首先通过ntp服务或者chrony时间同步服务器等方式使时间基准服务器保持与某标准时间保持一致。然后在时间基准服务器提供基准时间偏移值接口服务,以为当前流媒体服务器集群提供一致的基准时间偏移值获取服务,基准时间偏移值为从当前流媒体服务器集群启用时间到现在过了多少毫秒,这样可以减少传输的数据量,同时对流媒体服务器集群的时间进行统一。通过提供统一的基准时间偏移值接口查询服务,可以避免不同流媒体服务器之间的时间不一致的问题。Specifically, the time reference server provides a unified reference time offset value acquisition service for the stream media server cluster. First, make the time reference server consistent with a certain standard time through the ntp service or the chrony time synchronization server. Then provide the reference time offset value interface service on the time reference server to provide a consistent reference time offset value acquisition service for the current streaming media server cluster. The reference time offset value is how much time has passed since the current streaming media server cluster was enabled Milliseconds, which can reduce the amount of data transmitted, and at the same time unify the time of the streaming server cluster. By providing a unified reference time offset value interface query service, the problem of time inconsistency between different streaming media servers can be avoided.
参阅图8,本发明实施例提供了一种多路视频同步系统,应用于播放端,包括:Referring to Fig. 8, an embodiment of the present invention provides a multi-channel video synchronization system applied to a playback terminal, including:
第一模块,用于获取流媒体服务器发送的索引文件和媒体分片文件;其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流从推流端推流到流媒体服务器的网络延迟时间;The first module is used to obtain the index file and the media segment file sent by the streaming media server; wherein, the index file includes the reference time offset value information of the first frame image of each media segment file, and the media segment file includes the current The network delay time of the video stream from the streaming end to the streaming server;
第二模块,用于根据当前视频流播放的当前时间位置、每个媒体分片文件的第一帧图像与最后一帧图像的相对时间关系确定每路视频流初始播放的第一个媒体分片文件,并从索引文件获取每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值;The second module is used to determine the first media segment for initial playback of each video stream according to the current time position played by the current video stream, and the relative time relationship between the first frame image and the last frame image of each media segment file file, and obtain the reference time offset value of the first frame image of the first media segment file initially played by each video stream from the index file;
第三模块,用于按照预设时间间隔,根据每路视频流初始播放的第一个媒体分片文件的第一帧图像的基准时间偏移值、每路视频流的当前时间、每路视频流初始播放的第一个媒体分片文件的第一帧图像的时间确定每路视频流当前帧的基准时间偏移值;The third module is used to, according to the preset time interval, according to the reference time offset value of the first frame image of the first media segment file initially played by each video stream, the current time of each video stream, and the current time of each video stream. The time of the first frame image of the first media fragment file played initially by the stream determines the reference time offset value of the current frame of each video stream;
第四模块,用于按照预设时间间隔,根据每路视频流当前帧的基准时间偏移值计算最大基准时间偏移值、最小基准时间偏移值和平均基准时间偏移值,根据最大基准时间偏移值与最小基准时间偏移值的差值对正常播放的视频流进行同步操作,或根据平均基准时间偏移值与每路视频流当前帧的基准时间偏移值之间的关系对正常播放的视频流进行同步操作;同步操作包括刷新、快进或暂停。The fourth module is used to calculate the maximum reference time offset value, the minimum reference time offset value and the average reference time offset value according to the reference time offset value of the current frame of each video stream according to the preset time interval. The difference between the time offset value and the minimum reference time offset value is used to synchronize the normal playing video stream, or according to the relationship between the average reference time offset value and the reference time offset value of the current frame of each video stream Synchronous operations are performed on the normal playing video stream; synchronous operations include refreshing, fast-forwarding, or pausing.
参阅图9,本发明实施例提供了一种多路视频同步系统,应用于推流端,包括:Referring to Figure 9, an embodiment of the present invention provides a multi-channel video synchronization system, which is applied to the push stream end, including:
第五模块,用于计算当前视频流从推流端推流到流媒体服务器的网络延迟时间;The fifth module is used to calculate the network delay time of the current video stream from the streaming end to the streaming server;
第六模块,用于将视频流和网络延迟时间发送给流媒体服务器,以使流媒体服务器生成索引文件和媒体分片文件。The sixth module is used to send the video stream and network delay time to the streaming media server, so that the streaming media server can generate index files and media segment files.
参阅图10,本发明实施例提供了一种多路视频同步系统,应用于流媒体服务器,包括:Referring to Fig. 10, an embodiment of the present invention provides a multi-channel video synchronization system applied to a streaming media server, including:
第七模块,用于接收推流端发送的视频流和网络延迟时间;The seventh module is used to receive the video stream and network delay time sent by the streaming end;
第八模块,用于根据视频流生成索引文件和媒体分片文件;其中,索引文件包括每个媒体分片文件的第一帧图像的基准时间偏移值信息,媒体分片文件包括当前视频流推流到流媒体服务器的网络延迟时间。The eighth module is used to generate an index file and a media fragment file according to the video stream; wherein, the index file includes the reference time offset value information of the first frame image of each media fragment file, and the media fragment file includes the current video stream The network delay time for streaming to the streaming media server.
参阅图11,本发明实施例提供了一种多路视频同步装置,包括:Referring to Figure 11, an embodiment of the present invention provides a multi-channel video synchronization device, including:
至少一个处理器;at least one processor;
至少一个存储器,用于存储至少一个程序;at least one memory for storing at least one program;
当至少一个程序被至少一个处理器执行,使得至少一个处理器实现上述推流端、流媒体服务器或播放端任意一端的视频同步方法。When at least one program is executed by at least one processor, the at least one processor implements the video synchronization method at any one of the streaming end, the streaming media server, or the playback end.
其中,存储器作为一种非暂态计算机可读存储介质,可用于存储非暂态软件程序以及非暂态性计算机可执行程序。存储器可以包括高速随机存取存储器,还可以包括非暂态存储器,例如至少一个磁盘存储器件、闪存器件、或其他非暂态固态存储器件。在一些实施方式中,存储器可选包括相对于处理器远程设置的远程存储器,这些远程存储器可以通过网络连接至处理器。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。Wherein, the memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer executable programs. The memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid-state storage devices. In some embodiments, the memory may optionally include remote memory located remotely from the processor, and these remote memories may be connected to the processor through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
此外,本申请实施例还公开了一种计算机程序产品或计算机程序,计算机程序产品或计算机程序存储在计算机可读存介质中。计算机设备的处理器可以从计算机可读存储介质读取该计算机程序,处理器执行该计算机程序,使得该计算机设备执行上述的方法。同样地,上述方法实施例中的内容均适用于本存储介质实施例中,本存储介质实施例所具体实现的功能与上述方法实施例相同,并且达到的有益效果与上述方法实施例所达到的有益效果也相同。In addition, the embodiment of the present application also discloses a computer program product or computer program, and the computer program product or computer program is stored in a computer-readable storage medium. The processor of the computer device can read the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above method. Similarly, the content in the above-mentioned method embodiments is applicable to this storage medium embodiment. The functions realized by this storage medium embodiment are the same as those of the above-mentioned method embodiments, and the beneficial effects achieved are the same as those achieved by the above-mentioned method embodiments. The beneficial effects are also the same.
本发明实施例还提供了一种计算机可读存储介质,该计算机可读存储介质存储有处理器可执行的程序,所述处理器可执行的程序在被处理器执行时用于实现上述的方法。An embodiment of the present invention also provides a computer-readable storage medium, the computer-readable storage medium stores a processor-executable program, and the processor-executable program is used to implement the above method when executed by the processor .
可以理解的是,上文中所公开方法中的全部或某些步骤、系统可以被实施为软件、固件、硬件及其适当的组合。某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器、数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘(DVD)或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。It can be understood that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware and an appropriate combination thereof. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit . Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). As known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile media implemented in any method or technology for storage of information, such as computer readable instructions, data structures, program modules, or other data. permanent, removable and non-removable media. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cartridges, tape, magnetic disk storage or other magnetic storage devices, or can Any other medium used to store desired information and which can be accessed by a computer. In addition, as is well known to those of ordinary skill in the art, communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media .
参阅图1,本发明实施例提供了一种多路视频同步系统,包括流媒体服务器以及与流媒体服务器连接的推流端和播放端;其中,Referring to Fig. 1, an embodiment of the present invention provides a multi-channel video synchronization system, including a streaming media server and a streaming end and a playing end connected to the streaming media server; wherein,
推流端,用于执行上述推流端的视频同步方法;The push stream end is used to execute the video synchronization method of the above push stream end;
流媒体服务器,用于执行流媒体服务器的视频同步方法;The streaming media server is used to implement the video synchronization method of the streaming media server;
播放端,用于执行播放端的视频同步方法。The playback terminal is used to implement the video synchronization method of the playback terminal.
具体地,对于推流端,其主要通过视频拍摄装置来实现,并且其可具体包括至少一个摄像头和传输部件;流媒体服务器也可以是流媒体服务器集群,流媒体服务器包括处理器和存储器;对于播放端,其主要通过播放装置来实现,并且其可具体包括至少播放器和处理器。Specifically, for the streaming end, it is mainly realized by a video shooting device, and it may specifically include at least one camera and a transmission component; the streaming media server may also be a streaming media server cluster, and the streaming media server includes a processor and a memory; for The playback end is mainly realized by a playback device, and may specifically include at least a player and a processor.
可见,上述方法实施例中的内容均适用于本系统实施例中,本系统实施例所具体实现的功能与上述方法实施例相同,并且达到的有益效果与上述方法实施例所达到的有益效果也相同。It can be seen that the content in the above-mentioned method embodiments is applicable to this system embodiment, and the functions realized by this system embodiment are the same as those of the above-mentioned method embodiments, and the beneficial effects achieved are also the same as those achieved by the above-mentioned method embodiments. same.
在一个具体的购物直播应用场景中,推流端在推送视频流之前,计算当前视频流的网络延时时间,然后,推流端将同一商品不同侧面的多路视频流和网络延迟时间发送给流媒体服务器集群;流媒体服务器集群中的一个或多个流媒体服务器接收商品的多路视频流后,分别从时间基准服务器获取基准时间偏移值信息,然后,根据多路视频流、基准时间偏移值信息和网络延迟时间生成索引文件和媒体分片文件,变将索引文件和媒体分片文件发送给推流端;推流端接收索引文件和媒体分片文件后,首先,确定每路视频流初始播放的第一个媒体分片文件,以及第一个媒体分片文件的第一帧图像的基准时间偏移值,然后,按照预设时间间隔,确定每路视频流当前帧的基准时间偏移值,并根据每路视频流当前帧的基准时间偏移值对正常播放的视频流进行刷新、快进或暂停等同步操作。In a specific live shopping application scenario, the stream pusher calculates the network delay time of the current video stream before pushing the video stream, and then the stream pusher sends multiple video streams and network delay times of different sides of the same product to Streaming media server cluster; one or more streaming media servers in the streaming media server cluster receive the multi-channel video streams of the product, respectively obtain the reference time offset value information from the time reference server, and then, according to the multiple video streams, reference time Offset value information and network delay time generate index files and media fragment files, and then send the index files and media fragment files to the streaming end; after the streaming end receives the index files and media fragment files, first, determine the The first media segment file for the initial playback of the video stream, and the reference time offset value of the first frame image of the first media segment file, and then, according to the preset time interval, determine the reference of the current frame of each video stream Time offset value, and according to the reference time offset value of the current frame of each video stream, perform synchronous operations such as refreshing, fast forwarding, or pausing the normally played video stream.
以上是对本发明的较佳实施进行了具体说明,但本发明创造并不限于所述实施例,熟悉本领域的技术人员在不违背本发明精神的前提下还可做作出种种的等同变形或替换,这些等同的变形或替换均包含在本申请权利要求所限定的范围内。The above is a specific description of the preferred implementation of the present invention, but the invention is not limited to the described embodiments, and those skilled in the art can also make various equivalent deformations or replacements without violating the spirit of the present invention. , these equivalent modifications or replacements are all within the scope defined by the claims of the present application.
Claims (13)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310627643.8A CN116527981A (en) | 2023-05-30 | 2023-05-30 | Multipath video synchronization method, system, device and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310627643.8A CN116527981A (en) | 2023-05-30 | 2023-05-30 | Multipath video synchronization method, system, device and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN116527981A true CN116527981A (en) | 2023-08-01 |
Family
ID=87394231
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310627643.8A Pending CN116527981A (en) | 2023-05-30 | 2023-05-30 | Multipath video synchronization method, system, device and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116527981A (en) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2017028675A1 (en) * | 2015-08-18 | 2017-02-23 | 中兴通讯股份有限公司 | Playing method, device and system for live streaming channel |
| CN107071509A (en) * | 2017-05-18 | 2017-08-18 | 北京大生在线科技有限公司 | The live video precise synchronization method of multichannel |
| CN111787365A (en) * | 2020-07-17 | 2020-10-16 | 易视腾科技股份有限公司 | Multi-channel audio and video synchronization method and device |
| CN113382210A (en) * | 2021-08-12 | 2021-09-10 | 深圳市有为信息技术发展有限公司 | Processing method of multi-channel monitoring video data, streaming media server and electronic equipment |
| CN115474083A (en) * | 2022-11-02 | 2022-12-13 | 灵长智能科技(杭州)有限公司 | Multi-channel audio and video synchronous live broadcast method and system |
-
2023
- 2023-05-30 CN CN202310627643.8A patent/CN116527981A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2017028675A1 (en) * | 2015-08-18 | 2017-02-23 | 中兴通讯股份有限公司 | Playing method, device and system for live streaming channel |
| CN107071509A (en) * | 2017-05-18 | 2017-08-18 | 北京大生在线科技有限公司 | The live video precise synchronization method of multichannel |
| CN111787365A (en) * | 2020-07-17 | 2020-10-16 | 易视腾科技股份有限公司 | Multi-channel audio and video synchronization method and device |
| CN113382210A (en) * | 2021-08-12 | 2021-09-10 | 深圳市有为信息技术发展有限公司 | Processing method of multi-channel monitoring video data, streaming media server and electronic equipment |
| CN115474083A (en) * | 2022-11-02 | 2022-12-13 | 灵长智能科技(杭州)有限公司 | Multi-channel audio and video synchronous live broadcast method and system |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US12382119B2 (en) | Synchronizing program presentation | |
| KR102484054B1 (en) | Establishment and use of temporal mapping based on interpolation using low-rate fingerprinting to facilitate frame-accurate content modification | |
| JP7053943B2 (en) | Dynamic control of fingerprint rate to facilitate time-accurate modification of media content | |
| US9832507B2 (en) | System and method for synchronizing media output devices connected on a network | |
| CA2976437C (en) | Methods and apparatus for reducing latency shift in switching between distinct content streams | |
| US10110657B2 (en) | System and method for pushing live media content in an adaptive streaming environment | |
| US20180352286A1 (en) | Media content synchronization | |
| JPWO2012096372A1 (en) | Content playback apparatus, content playback method, distribution system, content playback program, recording medium, and data structure | |
| CN105325005B (en) | Content supply device, content supply method, storage medium, terminal device, and content supply system | |
| US9118742B2 (en) | Delivering a video stream | |
| EP2891323B1 (en) | Rendering time control | |
| US9635082B2 (en) | Method of saving content to a file on a server and corresponding device | |
| CN116527981A (en) | Multipath video synchronization method, system, device and storage medium | |
| CN112866763B (en) | Sequence number generation method, server and storage medium of HLS multi-code rate stream slice | |
| KR102166780B1 (en) | Method of synchronisation during the processing, by a multimedia player, of an item of multimedia content transmitted by an mbms service | |
| GB2544796A (en) | Video content synchronisation | |
| HK1212128B (en) | Rendering time control |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |