The method for realizing H264 video circulation HLS video flowing using GPU
Technical field
It is the present invention relates to the technical field of the audio-video of internet conversion, in particular to a kind of to realize that H264 is regarded using GPU
The method of frequency circulation HLS video flowing.
Background technique
In the construction of novel smart city, city operations administrative center (hereinafter referred to as center) plays key effect, in
Heart access does an innings business datum, video data and sensing data from committee comprising a variety of, constitutes early warning detection system, wherein
Video data includes the bayonet video flowing of the king's peace monitoring video flow in emphasis section, traffic intersection, these video flowings pass through
Ethernet passive optical network (EPON) converges to unified video platform, then shares agreement (GB28181 by national standard video
Agreement) access video synthesis management platform, pass through video synthesis and manages platform pushing video flow data to warning monitoring system
On displayed page, need to show relevant video data according to actual business.
But existing browser, there are security mechanism, the broadcasting of current video needs the browser using Microsoft
Object type extension component OCX.After the plug-in unit for installing OCX on a web browser, browser front end calls OCX to connect by JS script
Mouthful, then far call Video service product request video flowing, obtain video data.
However the method for OCX control can only use in specific browser (IE or compatible browser), there are browsers
The problem of edition compatibility, greatly limits the application range and user experience of video flowing.
Summary of the invention
In view of the problems of the existing technology, the main object of the present invention is to provide a kind of utilization GPU realization H264 video
The method of circulation HLS video flowing eliminates limitation of the browser to video playing plug-in unit OCX, so that video data can be by any
The browser of HLS is supported to play out.
To achieve the above object, the method proposed by the present invention for realizing H264 video circulation HLS video flowing using GPU,
Include the following steps:
S1, video equipment playing catalog information is obtained from video server by 28181 agreement of national standard, selected specific
Session initiation Protocol is retransmited after video flowing number, the data that program request obtains RTP video flowing are carried out to the video flowing of dedicated tunnel;
S2, judge the data payload type encapsulated in the data protocol of RTP video flowing;If RTP video flowing is H264 code stream,
Transcoding is then carried out using H264 transcoding technology;If RTP video flowing is PS code stream, is demultiplexed using PS, audio-video is separated into solution
Code takes out H264 video stream data;
S3, encapsulation is repacked to H264 video stream data according to HLS protocol by stream sectionaliser, creation meets HLS association
The fragment of view, new fragment are divided using the key frame of H264 video flowing as node, the corresponding MPEG-TS of each fragment
Packet generates M3U8 index file according to the corresponding relationship of fragment and MPEG-TS packet, and MPEG-TS packet saves as mpeg 2 transport stream
Stream file, M3U8 index file save as M3U8 playlist;
S4 reads M3U8 playlist by HTTP server, requests and play to list in M3U8 playlist in order
Mpeg 2 transport stream stream file;
Wherein, the process in the step 3 operates in GPU.
In embodiments of the present invention, in the step S3, when creation meets the fragment of HLS protocol, judge that current slice is
It is no to terminate, to continue being continuously generated for new fragment.
In embodiments of the present invention, in the step S3, creation is when meeting the fragment of HLS protocol, it is every generate one it is new
New fragment from removal in M3U8 index file and is updated in M3U8 index file by fragment by the fragment of failure.
In embodiments of the present invention, in the step S3, creation is when meeting the fragment of HLS protocol, it is every generate one it is new
Fragment saves the corresponding MPEG-TS packet of the fragment in the form of mpeg 2 transport stream stream file into virtual flash disk.
In embodiments of the present invention, several MPEG-TS packets are a series of equal small media file of times.
Technical solution of the present invention eliminates browser pair by converting HLS stream for the GB28181 video flowing of national standard agreement
The limitation of video playing plug-in unit OCX can be used any browser playing video data for supporting HLS, while support
Android phone end and apple IOS mobile phone terminal check video;HLS live streaming media is transmitted using general http protocol, is not had to
Consider the problems of independent setting firewall and port proxy, simplifies the process of deployment and O&M;It is handled and is regarded using high performance GPU
Frequently, the speed of video processing is faster, more efficient.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below
There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with
The structure shown according to these attached drawings obtains other attached drawings.
Fig. 1 is the flow diagram of one embodiment of the invention;
Fig. 2 is application principle figure of the invention;
The object of the invention is realized, the embodiments will be further described with reference to the accompanying drawings for functional characteristics and advantage.
Specific embodiment
The present invention proposes a kind of method for realizing H264 video circulation HLS video flowing using GPU.
Referring to Fig.1-2, Fig. 1 is the flow diagram of one embodiment of the invention, and Fig. 2 is application principle figure of the invention.
As shown in Figs. 1-2, in embodiments of the present invention, the side that H264 video circulation HLS video flowing is realized using GPU
Method comprising following steps:
S1, GPU video code conversion server obtain video equipment by 28181 agreement of national standard from video server and play mesh
Information is recorded, Session initiation Protocol is retransmited after selecting specific video flowing number, program request is carried out to the video flowing of dedicated tunnel and is obtained
Take the data of RTP video flowing.The video server can be king's peace monitor video server, the bayonet video of traffic intersection
The video server of server etc. or other access video synthesis management platforms.
S2, judge the data payload type encapsulated in the data protocol of RTP video flowing.If RTP video flowing is H264 code stream,
Transcoding is then carried out using H264 transcoding technology, extracts the H264 video stream data in H264 code stream;If RTP video flowing is PS code
Stream is then demultiplexed using PS, and audio-video is separated decoding, takes out H264 video stream data.
S3, encapsulation is repacked to H264 video stream data according to HLS protocol by stream sectionaliser, creation meets HLS association
The fragment of view, new fragment are divided using the key frame of H264 video flowing as node, and each fragment correspondence is packaged into one
MPEG-TS packet generates M3U8 index file according to the corresponding relationship of fragment and MPEG-TS packet, and MPEG-TS packet saves as MPEG-2
Transport stream stream file, M3U8 index file save as M3U8 playlist.In embodiments of the present invention, several MPEG-TS packets are
A series of equal small media file of times.
It in embodiments of the present invention, further include judging current slice when creation meets the fragment of HLS protocol in step S3
Whether should terminate, to continue being continuously generated for new fragment.
S4 reads M3U8 playlist using general http protocol by HTTP server, requests and play in order
The mpeg 2 transport stream stream file listed in M3U8 playlist.
Wherein, the treatment process in step S3 meets the fragment of HLS protocol as created, and fragment correspondence is packaged into MPEG-
TS packet generates the processes such as M3U8 index file and is all made of GPU operation.Specifically, GPU is with 300 frames/second speed to H264 video
Stream is handled, and single channel GPU highest handles 10 road videos simultaneously every time, has greatly accelerated the processing speed to H264 video flowing.
In embodiments of the present invention, every to generate a new point when creation meets the fragment of HLS protocol in step S3
New fragment from removal in M3U8 index file and is updated in M3U8 index file by piece by the fragment of failure.It is broadcasting as a result,
In complete session life cycle when putting, when new media file (i.e. a corresponding MEPG-TS packet of fragment), the rope of update
Quotation part is received by HTTP server, and most newly added media file, the media text of failure are enumerated in the index file of update
Part is removed from index file, to realize the smooth playing of video, avoids the occurrence of pause or media file vacancy.
In embodiments of the present invention, in step S3, when creation meets the fragment of HLS protocol, one new fragment of every generation,
The corresponding MPEG-TS packet of the fragment is saved in the form of mpeg 2 transport stream stream file into virtual flash disk.Virtual memory
Disk is that a part of memory (RAM) is modeled as hard disk by virtual memory disc tool to obtain virtual hard disk, and MPEG-TS packet is stored
It can be written and read at any time in virtual flash disk, and speed is quickly, accelerate the processing speed to video flowing.
Technical solution of the present invention eliminates browser pair by converting HLS stream for the GB28181 video flowing of national standard agreement
The limitation of video playing plug-in unit OCX can be used any browser playing video data for supporting HLS, while support
Android phone end and apple IOS mobile phone terminal check video;HLS live streaming media is transmitted using general http protocol, is not had to
Consider the problems of independent setting firewall and port proxy, simplifies the process of deployment and O&M;It is handled and is regarded using high performance GPU
Frequently, the speed of video processing is faster, more efficient.
The above description is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all at this
Under the inventive concept of invention, using equivalent structure transformation made by description of the invention and accompanying drawing content, or directly/use indirectly
It is included in other related technical areas in scope of patent protection of the invention.