A kind of device and method for video file dynamically being generated as the ts file
Technical field
The present invention relates to the Internet video field, especially relate to a kind of device and method for video file dynamically being generated as the ts file.
Background technology
Online sees that with web browser the user of video is more and more, and at present popular is to watch at web browser with the flash plug-in unit.The clear and definite flash that do not support of apple ios system, the solution that apple provides is the livestreaming technology, exactly a video is divided into a plurality of ts small documents.(the livestreaming technology is that a kind of html5 that Apple proposes does not pass through plug-in unit, the local technology of supporting video playback).The video of playing adds that by a text take m3u8 as suffix a group of mean people ts file consists of.M3u8 file the inside is the address information of these little ts files.The m3u8 file should finish with #EXT-X-ENDLIST.If not, expression m3u8 file do not comprise all ts files, player should be asked again.
Video website has two schemes for the support of ipad at present, and a kind of is static the generation, stores harddisk memory into after generating in advance, directly transfers when needing, and a kind of is dynamic generation, and namely interim the generation is placed in the internal memory when request, uses rear deletion.The static benefit that generates is that the user experiences, and shortcoming is to double content delivering system cdn storage, and it is too large to adjust the segmentation scheme cost; The benefit that dynamically generates is province content dissemination system cdn storage, and the burst scheme can be adjusted at any time, and shortcoming is all to need to regenerate once poor user experience when asking at every turn.
The scheme that this patent proposes also is dynamic generation, gets on but generation ts file is transferred to client from server, has so both saved the memory capacity of content delivering system cdn, alleviates again the server burden.
Summary of the invention
The invention provides a kind of device for video file dynamically being generated as the ts file, this device comprises: content delivering system, be positioned at server end, and provide the segmentation video to download by the http agreement; The websocket interface is used for realizing two-way communication at web browser and server end, accepts the request of web browser downloading video files, and the segmentation video on the content delivering system is downloaded in the web browser; Dynamic generation module in the web browser is used for dynamically generating the ts file, and the list of videos formatted file is provided simultaneously.
Further, described web browser is the html5 web browser, this web browser is provided with a label and is called video, this label is used for defining video, this label has attribute src, for wanting the address of displaying video, this address is corresponding with the list of videos formatted file that provides, and web browser can be asked successively the ts file of the inside and be resolved, plays.
Further, when the user sent the displaying video request by web browser, web browser was searched the address among the src, and web browser is to this Address requests list of videos formatted file.
Further, described web browser can this list of videos formatted file of repetitive requests.
The present invention also provides a kind of method for video file dynamically being generated as the ts file, it is characterized in that the method may further comprise the steps: step (1) is used for accepting the request of web browser downloading video files at the websocket interface of web browser and server end realization two-way communication; Step (2) content delivering system downloads to the segmentation video in the web browser by the http agreement; Dynamic generation module in step (3) web browser dynamically generates the ts file, and the list of videos formatted file is provided simultaneously.
Further, web browser is the html5 web browser described in the step (3), this web browser is provided with a label and is called video, this label is used for defining video, this label has attribute src, for wanting the address of displaying video, this address is corresponding with the list of videos formatted file that provides, and web browser can be asked successively the ts file of the inside and be resolved, plays.
Further, when the user sent the displaying video request by web browser, web browser was searched the address among the src, and web browser is to this Address requests list of videos formatted file.
Further, described web browser can this list of videos formatted file of repetitive requests.
Description of drawings
Fig. 1 is the schematic diagram that illustrates according to device of the present invention.
Fig. 2 is the schematic diagram according to the inventive method.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage are become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments:
As shown in Figure 1, device according to the present invention has three large modules:
1. content delivering system cdn: be positioned at server end, provide flv or mp4 segmentation video to download by the http agreement.
2. be used for the websocket interface in web browser and server end realization two-way communication: accept web browser downloading video files (m3u8 file, the ts file) request is the flv(on the content delivering system cdn or mp4) the segmentation video downloads in the web browser.
3. the dynamic generation module in the web browser is used for dynamically generating the ts file, and list of videos form m3u8 file is provided simultaneously.Described web browser is the html5 web browser, and wherein newly-increased label is called video, and this label is used for defining video, for example vidclip or other video flowings, and there is attribute src the inside, for wanting the address of displaying video.This address is corresponding with the m3u8 file that provides, in case obtain this file, web browser just can be asked the ts file of the inside successively, then resolves, plays.
3 when the user sends the displaying video request by web browser, web browser search address among the src, web browser is to this Address requests m3u8 file.Present patent application is when the websocket interface accepts request, the dynamic ts file that generates of web browser needs.The address of these ts files is write in the m3u8 file, and this m3u8 file is made (not the having #EXT-X-ENDLIST) of live formula, and web browser can this m3u8 file of repetitive requests like this.For the ts file, dynamically generate the same with server.
As shown in Figure 2, the method according to this invention may further comprise the steps: step (1) is used for accepting the request of web browser downloading video files at the websocket interface of web browser and server end realization two-way communication; Step (2) content delivering system downloads to the segmentation video in the web browser by the http agreement; Dynamic generation module in step (3) web browser dynamically generates the ts file, and the m3u8 file is provided simultaneously.
Web browser is the html5 web browser described in the step (3), this web browser is provided with a label and is called video, this label is used for defining video, this label has attribute src, for wanting the address of displaying video, this address is corresponding with the list of videos formatted file that provides, and web browser can be asked successively the ts file of the inside and be resolved, plays.
When the user sent the displaying video request by web browser, web browser was searched the address among the src, and web browser is to this Address requests list of videos formatted file.
Described web browser can this list of videos formatted file of repetitive requests.
The obtained technique effect of the present invention is: alleviate the server burden, save bandwidth.
More than be the detailed description that the preferred embodiments of the present invention are carried out, but those of ordinary skill in the art should be appreciated that within the scope of the present invention, and guided by the spirit, various improvement, interpolation and replacement all are possible.These are all in the protection range that claim of the present invention limits.