Method for triggering mobile phone HTML5 low-delay live video based on early warning information
Technical Field
The invention relates to a method for live broadcasting of a video, in particular to a method for triggering a mobile phone HTML5 low-delay live broadcasting of a video based on early warning information.
Background
In the traditional alarm, videos are generally kept as evidence for later viewing, and in order to improve user experience, event images need to be viewed immediately while events occur, so that the images and texts can be presented in time.
With the development and popularization of mobile internet technology, mobile video playing is just needed, but currently, low-delay video playing at a mobile phone end is mostly realized based on customized apps and cannot be applied to qq and WeChat, meanwhile, the mobile phone has multiple platforms such as andoid, iphone, ipad and windows phone, and a large amount of labor cost is consumed for independently developing the apps for each platform.
The standard html5 video playing delay supported by qq, WeChat, andoid, iphone, ipad and windows phone platforms is generally over 10S, and the requirement of timely and synchronous display of early warning information and image content cannot be met.
The existing http protocol has the following disadvantages:
(1) stateless and data-non-continuity: the two requests are unrelated, the data requests are not in sequence, and the video playing is an ordered continuous action;
(2) mode of operation of the request receipt: only the client can actively send data, the server cannot actively send data, the video data cannot be sent out in time, and time delay is increased;
(3) the HLS protocol developed by apple requires that the video file table be reported first and then the video be downloaded: only the real-time video can be cached, a file table is generated and then sent to the client, and the client downloads the video for playing, so that the time delay is further increased;
(4) by integrating the above 3 files, the file size of the server becomes a factor affecting the delay again when the file is generated due to the difference of the client, the file table is generated too slowly due to the too large file, too much invalid network transmission overhead is increased due to the too small file, and meanwhile, the file which is not started by the key frame cannot be decoded independently due to the fact that the video playing is started by the key frame, so that the infinite reduction of the file is limited.
Disclosure of Invention
The invention aims to solve the technical problems that the standard HTML5 video playing delay is generally more than 10S, and the requirement of timely and synchronous display of early warning information and image content cannot be met, and provides a method for triggering a mobile phone HTML5 low-delay live video based on the early warning information, so that the problems in the background technology are solved.
The invention is realized by the following technical scheme:
the method for triggering the mobile phone HTML5 low-delay live video based on the early warning information comprises the following steps:
s1: the server acquires real-time video stream data from the video acquisition terminal;
s2: when playing a video, a client acquires a random address and then sends a request of the random address to a server;
s3: the server obtains the acquisition condition of the client data according to the request of the random address;
s4: the server sends real-time video stream data to the client according to the acquisition condition of the client data;
s5: and the client plays the real-time video stream data.
On the basis of the scheme, the method further comprises the following steps:
the client data in step S3 includes: acquired video data and non-acquired video data.
On the basis of the scheme, the method further comprises the following steps:
the method between the step S3 and the step S4 further comprises the steps of:
s31: and the server controls the transmission sequence of the real-time video stream data according to the acquisition conditions of the acquired video data and the video data which are not acquired.
On the basis of the scheme, the method further comprises the following steps:
the step S4 includes the sub-steps of:
s41: the server analyzes the real-time video stream data and judges whether effective data is used for requesting receipt, if the effective data exists, the step S42 is executed, otherwise, the step S43 is executed;
s42: sending the valid data to the client;
s43: waiting for the data required by the client, if the data required by the client is received within the preset time, executing the step S42, otherwise, executing the step S44;
s44: stop sending all data to this client.
On the basis of the scheme, the method further comprises the following steps:
the S4 specifically includes:
s41: the method comprises the steps that a server generates a file table before video data are obtained, video data which do not have files in the file table are recorded as liability data, and when a client requests a specific file table, if the video data in the file table are not generated, the video data are recorded as overdue data; analyzing the real-time video stream data and judging whether effective data is used for requesting receipt, if so, executing a step S42, otherwise, executing a step S43;
s42: sending the valid data to the client;
s43: setting a overdue grace period for the client, waiting for data required by the client, if receiving supplementary data required by the client within the overdue grace period, executing the step S42 and continuing to play the video on the client, otherwise executing the step S44;
s44: and taking the video playing request as a bad account, stopping sending the video data to the client and finishing playing the video.
On the basis of the scheme, the method further comprises the following steps:
and in the program operation process, the program predicts the data volume of the liability to the client side in the next batch according to the liability data and the overdue data, so as to balance the liability data volume and the overdue data volume.
Compared with the prior art, the invention has the following advantages and beneficial effects:
the invention improves the standard html5 supported by qq, WeChat, andoid, iphone, ipad, windows phone and other platforms, so that the low-delay effect of the special app is achieved, the codes are written once, the whole platform is universal, and the development cost is reduced.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 is a flow chart of the method of the present invention;
FIG. 2 is a flow chart of playing a conventional html5 video;
FIG. 3 is a flow chart of the improved html5 video playing method;
FIG. 4 is a graph of data liability versus overdue amount for the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to examples and accompanying drawings, and the exemplary embodiments and descriptions thereof are only used for explaining the present invention and are not meant to limit the present invention.
Example (b):
as shown in fig. 1, the method for triggering the mobile phone HTML5 live video with low delay based on the warning information includes:
s1: the server acquires real-time video stream data from the video acquisition terminal;
s2: when playing a video, a client acquires a random address and then sends a request of the random address to a server;
s3: the server obtains the acquisition condition of the client data according to the request of the random address;
s4: the server sends real-time video stream data to the client by combining the acquisition condition of the client data and adopting a long polling method and a loan prediction method;
s5: and the client plays the real-time video stream data.
The client data in S3 includes the acquired video data and the non-acquired video data.
The method further comprises the step that the server controls the transmission sequence of the real-time video stream data according to the acquired video data and the acquired video data.
The S4 includes: when receiving a request of a random address, the server analyzes real-time video stream data and judges whether valid data are used for requesting receipt, and if the valid data exist, the server sends the valid data to the client; if the data is not valid, adding overdue, sending the data to the client when the data required by the client can be provided, and if the data required by the client cannot be prepared for a long time, considering the data as bad account and stopping all the data of the client.
The S4 further includes: the method comprises the steps that a server firstly generates a file table before video data are obtained, video data which do not have files in the file table are recorded as liability data, and when a client requests a specific file table, if the video data in the file table are not generated, the video data are recorded as overdue data; if the video data is supplemented in the grace period, the video data is sent to the client and the video is continuously played at the client; and if the video data are not supplemented after the grace period is exceeded, stopping sending the video data to the client and ending playing the video.
The S4 further includes: and in the program operation, the program predicts the data volume of the liability to the client side in the next batch according to the liability data and the overdue data, so as to balance the liability and the overdue volume.
Adopting a random address method: when the client plays the video, a random address is obtained first, then the random address is only used by the client, the server can know which data of the client are obtained and which data are not obtained according to the request condition of the random address, the transmission sequence of the data is controlled, and the problem of stateless and disordered http is solved;
adopting a long polling method: after adopting the random address method, the server can already analyze the working state of the client, when having a request, the server sends video data to the client at a proper time after balancing the effectiveness of the data (such as a client requests a file list, at the moment, the server finds that the file list of the server is not changed after the client requests for the last time, at the moment, if the file list sent to the client is invalid data, the connection is maintained for later processing, and the file list is immediately returned to the client when the file list is changed);
as shown in fig. 4, the loan prediction method: the logic of playing the video by the html5 is that a file list is taken first and then the video is downloaded, the file list and the video can be transmitted to a client in time by using a random address method and a long polling method, but the file list can be generated only after the video file is generated; in order to solve the contradiction, the server generates a file table when no video exists, data which does not exist in the file table is recorded as liability, when a client requests a specific file, the file is not generated yet, the file is recorded as overdue, a long polling mechanism exists, a certain grace period exists, if the data is supplemented within the grace period, the video playing can still work, and if the data cannot be supplemented within the grace period, all the data of the client is finally played; during program operation, the program predicts the data volume of the liability for the next batch to the client according to the liability and overdue data, balances the liability and the overdue volume, and avoids the situation that data cannot be supplemented in the grace period.
Taking a Haikang video stream with a key frame interval of 50 and 25 frames/second (2 seconds and one frame key frame) as an example, as shown in FIG. 2, according to a standard flow of hls, 3 fragments need to be generated, each fragment needs to contain one frame key frame, 6S is needed for generating a file table for the first time, 2S is needed for generating (the previous two fragments use historical data) in a cache manner, as shown in FIG. 3, and after improvement, the file table can be generated directly without data, that is, the time for generating the file table is 0, the detailed comparison is as follows:
the above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.