HLS (HTTP live streaming) quick sharing method for real-time video

文档序号:1675892 发布日期:2019-12-31 浏览:10次 中文

阅读说明:本技术 一种实时视频的hls快速分享的方法 (HLS (HTTP live streaming) quick sharing method for real-time video ) 是由 吴俊杰 季金辉 杜春花 周伟 侯凝冰 于 2019-09-24 设计创作,主要内容包括:本发明公开了一种实时视频的HLS快速分享的方法,IP摄像机和服务器准备就绪,服务器周期获取IP摄像机的当前截图或者IP摄像机周期向服务器上传截图;服务器定时使用截图素材生成视频片段;服务器收到客户端的HLS媒体请求后,立即使用步骤2的视频片段生成HLS播放地址M3U8,并记为地址A,返回地址A给客户端;客户端播放该播放地址A,同时服务器开始获取该摄像机视频,开启正常的HLS转码过程。本发明即时生成播放地址,用户即时可播,无需等待。(The invention discloses a method for quickly sharing HLS of a real-time video, wherein an IP camera and a server are ready, and the server periodically acquires the current screenshot of the IP camera or uploads the screenshot to the server; the server regularly uses the screenshot material to generate a video clip; after receiving the HLS media request of the client, the server immediately generates an HLS playing address M3U8 by using the video clip in the step 2, records the HLS playing address as an address A, and returns the address A to the client; and the client plays the playing address A, and simultaneously the server starts to acquire the video of the camera and starts a normal HLS transcoding process. The invention generates the playing address instantly, and the user can play instantly without waiting.)

1. A method for quickly sharing HLS of a real-time video is characterized by comprising the following steps:

the method comprises the following steps: the IP camera and the server are ready, and the server periodically acquires the current screenshots of the IP camera or uploads the screenshots to the server periodically;

step two: the server regularly uses the screenshot material to generate a video clip;

step three: after receiving the HLS media request of the client, the server immediately uses the video fragment in the step two, fragments the video fragment according to the HLS specification, generates an M3U8 index file of the HLS at the same time, records the index file as a playing address A, and returns the playing address A to the client;

step four: and the client plays the playing address A, and simultaneously the server starts to acquire the video of the camera and starts a normal HLS transcoding process.

2. The method of claim 1 for fast HLS sharing of real-time video, wherein: the specific process of generating the video clip in the second step is

2.1, if the frame rate of the video clip is f and the duration of the video clip is r, f × r pictures are counted in a segment of video clip;

2.2 set the capture period to T1, then at least T1 × (f × r + 1) seconds are required to prepare all photos of a video clip; since the frame rate and duration of the video segment of the HLS are generally constant, the period T2> = T1 (f × r + 1) for creating the video segment;

2.3 video clip generation: the method comprises the steps of sequentially reading pictures according to the time of picture generation, decoding the pictures into image data which can be utilized by an encoder, encoding and compressing the picture data as video frames by using a video compression algorithm at a certain frame rate, and further storing the video frames as files according to an Mp4 format to form video clips.

3. A method of HLS fast sharing of real-time video according to claim 2, characterized by: the image data format that can be utilized by the encoder in 2.3 is YUV.

4. A method of HLS fast sharing of real-time video according to claim 2, characterized by: the 2.3 video compression algorithm adopts H.264.

5. A method of HLS fast sharing of real-time video according to claim 2, characterized by: the process code for generating the video segment in the 2.3 is

Define a file 8128CD2002D _0_1.m3u 8:

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-MEDIA-SEQUENCE:3

#EXT-X-TARGETDURATION:8

#EXTINF:5.089,

8128CD2002D_0_1-3.ts

#EXTINF:4.255,

8128CD2002D_0_1-4.ts

#EXTINF:4.547,

8128CD2002D_0_1-5.ts

#EXT-X-DISCONTINUITY

#EXTINF:7.770,

8128CD2002D_0_1-6.ts

#EXTINF:6.000,

8128CD2002D_0_1-7.ts

8128CD2002D _0_1-6.ts and 8128CD2002D _0_1-7.ts are new media pieces, the upper part is a pre-generated media piece, and # EXT-X-DISCONTINUITY is specified according to the HLS protocol.

6. The method of claim 1 for fast HLS sharing of real-time video, wherein: the client in the fourth step is special client software or a browser.

7. The method of claim 1 for fast HLS sharing of real-time video, wherein: in the fourth step, the server starts a normal HLS transcoding process to generate a normal HLS playing address M3U8, the address B is recorded, and the new file fragment is added to the M3U8 file of the address A according to the HLS protocol specification.

Technical Field

The invention relates to a sharing method, in particular to a method for quickly sharing HLS of a real-time video, and belongs to the technical field of streaming media.

Background

The HLS sharing of the real-time video refers to distributing real-time video data based on an HLS protocol. For real-time video, the video is generally continuously acquired, and then the video is fragmented and an index file is generated simultaneously according to the HLS protocol specification (. M3U 8). In the field of broadcast television and the like, such a method is suitable.

However, in the field of video monitoring and the like, because the number of video sources is huge and is limited by the front end, the HLS processing is generally performed by the back end server. If the above-described "continuous" processing is still employed, server and bandwidth requirements are enormous. Therefore, a process of temporarily starting transcoding at the server side when viewing is needed is generally adopted. However, after the user triggers to watch the address, the address needs to be played for a certain time before being generated and played, which affects the user experience. The waiting time from triggering to playing cannot be removed, namely the server acquires the media data, the server generates the media segments, and the time is required for generating the index file (. M3U8) after the segments are generated to a certain amount.

Meanwhile, the waiting time for waiting for the streaming media to be ready is unknown to each playing end, and certain difficulty is caused to the development of the playing end, namely the playing cannot be played and the like needs to be retried.

Disclosure of Invention

The invention aims to solve the technical problem of providing a method for quickly sharing HLS of a real-time video, which can generate a playing address in real time and enable a user to play the video in real time.

In order to solve the technical problems, the technical scheme adopted by the invention is as follows:

a method for quickly sharing HLS of a real-time video is characterized by comprising the following steps:

the method comprises the following steps: the IP camera and the server are ready, and the server periodically acquires the current screenshots of the IP camera or uploads the screenshots to the server periodically;

step two: the server regularly uses the screenshot material to generate a video clip;

step three: after receiving the HLS media request of the client, the server immediately uses the video fragment in the step two, fragments the video fragment according to the HLS specification, generates an M3U8 index file of the HLS at the same time, records the index file as a playing address A, and returns the playing address A to the client;

step four: and the client plays the playing address A, and simultaneously the server starts to acquire the video of the camera and starts a normal HLS transcoding process.

Further, the specific process of generating the video segment in the second step is

2.1, if the frame rate of the video clip is f and the duration of the video clip is r, f × r pictures are counted in a segment of video clip;

2.2 set the capture period to T1, then at least T1 × (f × r + 1) seconds are required to prepare all photos of a video clip; since the frame rate and duration of the video segment of the HLS are generally constant, the period T2> = T1 (f × r + 1) for creating the video segment;

2.3 video clip generation: the method comprises the steps of sequentially reading pictures according to the time of picture generation, decoding the pictures into image data which can be utilized by an encoder, encoding and compressing the picture data as video frames by using a video compression algorithm at a certain frame rate, and further storing the video frames as files according to an Mp4 format to form video clips.

Further, the 2.3 encoder may utilize YUV as the image data format.

Further, the 2.3 video compression algorithm adopts h.264.

Further, the process code for generating the video segment in 2.3 is

Define a file 8128CD2002D _0_1.m3u 8:

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-MEDIA-SEQUENCE:3

#EXT-X-TARGETDURATION:8

#EXTINF:5.089,

8128CD2002D_0_1-3.ts

#EXTINF:4.255,

8128CD2002D_0_1-4.ts

#EXTINF:4.547,

8128CD2002D_0_1-5.ts

#EXT-X-DISCONTINUITY

#EXTINF:7.770,

8128CD2002D_0_1-6.ts

#EXTINF:6.000,

8128CD2002D_0_1-7.ts

8128CD2002D _0_1-6.ts and 8128CD2002D _0_1-7.ts are new media pieces, the upper part is a pre-generated media piece, and # EXT-X-DISCONTINUITY is specified according to the HLS protocol.

Further, the client in step four is dedicated client software or a browser.

Further, in the fourth step, the server starts a normal HLS transcoding process, generates a normal HLS playing address M3U8, records it as address B, and adds the new file fragment to the M3U8 file at address a according to the HLS protocol specification.

Compared with the prior art, the invention has the following advantages and effects: the invention provides a method for quickly sharing HLS of a real-time video, which can generate a playing address instantly and enable a user to play instantly without waiting.

Drawings

Fig. 1 is a flowchart of a method for fast HLS sharing of real-time video according to the present invention.

Detailed Description

The present invention is further illustrated by the following examples, which are illustrative of the present invention and are not to be construed as being limited thereto.

As shown in fig. 1, a method for fast sharing HLS of real-time video according to the present invention is characterized by comprising the following steps:

the method comprises the following steps: the IP camera and the server are ready, and the server periodically acquires the current screenshots of the IP camera or uploads the screenshots to the server periodically;

step two: the server regularly uses the screenshot material to generate a video clip; the specific process comprises the following steps:

2.1, if the frame rate of the video clip is f and the duration of the video clip is r, f × r pictures are counted in a segment of video clip;

2.2 set the capture period to T1, then at least T1 × (f × r + 1) seconds are required to prepare all photos of a video clip; since the frame rate and duration of the video segment of the HLS are generally constant, the period T2> = T1 (f × r + 1) for creating the video segment;

2.3 video clip generation: the method comprises the steps of sequentially reading pictures according to the time of picture generation, decoding the pictures into image data which can be utilized by an encoder, encoding and compressing the picture data as video frames by using a video compression algorithm at a certain frame rate, and further storing the video frames as files according to an Mp4 format to form video clips.

Wherein, the code realized by the 2.3 is as follows:

define a file 8128CD2002D _0_1.m3u 8:

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-MEDIA-SEQUENCE:3

#EXT-X-TARGETDURATION:8

#EXTINF:5.089,

8128CD2002D_0_1-3.ts

#EXTINF:4.255,

8128CD2002D_0_1-4.ts

#EXTINF:4.547,

8128CD2002D_0_1-5.ts

#EXT-X-DISCONTINUITY

#EXTINF:7.770,

8128CD2002D_0_1-6.ts

#EXTINF:6.000,

8128CD2002D_0_1-7.ts

8128CD2002D _0_1-6.ts and 8128CD2002D _0_1-7.ts are new media pieces, the upper part is a pre-generated media piece, and # EXT-X-DISCONTINUITY is specified according to the HLS protocol.

In this embodiment, the frame rate f of the video segment is generally 25, and the duration r is 5 seconds, so that a segment of video segment has f × r =25 × 5=125 slices in total. If the screenshot period T1 is 2, at least T1 × (f × r + 1) =2 × (25 × 5+ 1) =252 seconds are required to prepare all the photos of one video clip; the frame rate and duration of the video clips of the HLS are generally constant, and a larger number of screenshots obviously make more video clips. Based on the above conditions, a period T2> = T1 (f r + 1) of the video clip is produced.

Step three: after receiving the HLS media request of the client, the server immediately generates an HLS playing address M3U8 by using the video clip in the step 2, records the HLS playing address as an address A, and returns the address A to the client;

the video slicing is to slice the video segment generated in step two as required by the HLS specification, that is, to divide a video segment with a longer time (generally more than 30 s) into video segments with a certain duration (for example, 5 s).

Step four: and the client plays the playing address A, and simultaneously the server starts to acquire the video of the camera and starts a normal HLS transcoding process. The client is special client software or a browser. And the server starts a normal HLS transcoding process to generate a normal HLS playing address M3U8, the address B is recorded, and the new file fragment is added to the M3U8 file of the address A according to the HLS protocol specification.

The invention provides a method for quickly sharing HLS of a real-time video, which can generate a playing address instantly and enable a user to play instantly without waiting. The present invention is based on the HLS streaming protocol, and the idea of solving the problem should not be limited to this protocol. The present invention is exemplified by a monitoring system using an IP camera and a backend server, and is not limited to this application field.

Although the present invention has been described with reference to a preferred embodiment, it should be understood that various changes, substitutions and alterations can be made herein without departing from the spirit and scope of the invention as defined by the appended claims.

8页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:发送装置及方法、接收装置及方法及计算机可读存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类