Dynamic self-adapting code rate selection method based on MPEG-DASH agreementTechnical field
The invention belongs to technical field of video transmission, it is related to streaming media video based on MPEG-DASH agreement or audioA kind of transmission, and in particular to dynamic self-adapting code rate selection method based on MPEG-DASH agreement.
Background technique
Currently, being continuously increased with network bandwidth, demand of the people to media information is also constantly increasing.According to CiscoCompany shows that, by 2017, media flow will occupy the 86% of whole network flow, all kinds of matchmakers in the report that May in year is issuedBody application will become a part indispensable in people's informatized life.Current various multimedia application layer go out not thoroughly, theyCollection audio is provided for people, video, picture and text are in the comprehensive experience of one.It is intended that obtaining more rapidly, more smooth, higher qualityMedia services experience, how to meet this demand become current stream media technology a big difficulty.
Stream media technology refers to the technology using streaming manner transmission media data, its main feature is by servicingDevice is continuous to user, transmits media data in real time.In the system using stream media technology, user is without waiting for total dataDownloading is completed to play out, that is, realizes the effect played in downloading, greatly reduces user and starts the time and to userThe demand of side cache size.Traditional RTP/RTSP stream media technology is carried out data transmission using udp protocol, therefore is only capable of providingInsecure transmission.Additionally due to RTP/RTSP stream media technology needs specific streaming media server, cause lower deployment cost compared withIt is high.For these problems, HTTP dynamic self-adapting Streaming Media (DASH, Dynamic Adaptive Streaming overHTTP) technology becomes the new lover of Streaming Media circle in recent years.The technology uses HTTP/TCP agreement framework, provides reliably for userData transmission.The technology uses 80 ports simultaneously, therefore can easily pass through firewall.Furthermore DASH technology can weighWith common Web server, lower deployment cost is low.Finally, the media table of the same media content different quality rank of the technical supportShow, especially moving end subscriber can be according to capacity of equipment, buffer size and the real-time adjustment request of real-time network bandwidth situationMedia quality rank, have the characteristics of dynamic self-adapting.Therefore, DASH technology has obtained all kinds of manufacturers and standardization bodyExtensive concern is expected to become next-generation mainstream stream media technology.
But MPEG-DASH agreement defines only MPD file structure and Streaming Media slice format, there is no provide clientThe process or mechanism of end selection slice file, to a certain extent dynamic self-adapting code rate selection method based on DASH agreementQuality directly determines the height of streaming media efficiency and the viewing experience of user, so the dynamic based on DASH agreement is adaptiveCode rate selection method has very big research and development space, and does not have similar techniques appearance also now.
Summary of the invention
To achieve the above object, the present invention provides a kind of dynamic self-adapting code rate selection side based on MPEG-DASH agreementMethod, realizes and improves video quality as far as possible under the premise of smooth playing, greatly enhances user's viewing experience.
The technical scheme adopted by the invention is that the dynamic self-adapting code rate selection method based on MPEG-DASH agreement, toolBody follows the steps below:
Step 1, the HTTP connection of server and client is established;
Step 2, user end to server sends HTTP Get request, and request downloading MPD file simultaneously stores;
Step 3, server, which receives, carries out response to client after the request of client and sends MPD file, and client is to MPDFile is downloaded and parses to the MPD file of downloading;In order to allow video to start to play as early as possible, according to parsing MPDRange of code rates corresponding to the URL of the obtained video slicing of file first downloads a part of video segment, service with minimum code rateDevice gives client transmission video segment file after receiving request, and client is downloaded slice file;
Step 4, network bandwidth when being sliced to step 3 foradownloaded video calculates, and counts and records and uses KalmanFilter forecasting method predicts network bandwidth when downloading next video slicing;
Step 5, according to the obtained prediction bandwidth of step 4 and in conjunction with current cache area video segment residue situation to downloadingThe code rate of next video segment makes a choice;
Step 6, step 4-5 is jumped to if video segment is completed without all downloadings, continues to execute prediction and downloadedJourney, otherwise exits cyclic process, and method terminates.
Further, the detailed process of the step 1 is:
Step 11: one URL object of creation;
Step 12: one HTTP link of creation;
Step 13: obtaining data using IO stream.
Further, the detailed process of the step 2 is:
Step 21: judging that MPD file whether there is, then return to 1 if it exists and otherwise return to 0;
Step 22: file being downloaded in the absence of file;
Step 23: the file completed to downloading stores.
Further, the detailed process of the step 3 is:
Step 31: obtaining the specified attribute of Representation element in MPD file, it is only necessary to id, width are obtained,Tri- attributes of height;
Step 32: obtaining the URL of each grade video segment in MPD file;
Step 33: being downloaded according to the video segment that minimum code rate is chosen in the address URL obtained by parsing MPD file.
Further, the detailed process of the step 4 is:
Step 41: obtaining the network bandwidth b of downloading slicingn:
Wherein: tn(e) time that n-th of slice downloading is completed is indicated;Tn (s) indicate n-th slice start downloading whenBetween;R (n) indicates the selected code rate of n-th of slice;θ indicates that each slice plays duration, and value is 2 seconds;bnIt is n-thThe network download bandwidth value of a slice;
Step 42: establish system state equation and measurement equation:
Wherein: bn+1It is the prediction download bandwidth value of (n+1)th slice;Yn+1It is n+1 slice bandwidth measuring value;A is shapeState transfer matrix reflects system from the download bandwidth of n-th of slice to (n+1)th state change;unIt is n-th of sliceDominant vector;B is control allocation matrix;qnAnd rn+1It is system noise and measurement noise, q respectivelynStatistical property E [qn]=0,rn+1Statistical property E [rn+1]=0;H is observing matrix;
Step 43: by the optimum bandwidth value of n-th of fragmentRemove the state value of (n+1)th fragment of predictionDue to mouldThe random disturbances q of typenDo not know in advance, soBy the prediction download bandwidth of next fragment withThe optimal download bandwidth of a upper fragment be considered as it is identical, even A=1, dominant vector un=0, it obtains:
Step 44: by last error covariance pnWith system noise qnCovariance Q predict new error covarianceI.e.
Wherein Q is system noise qnCovariance, type belongs to white Gaussian noise;For (n+1)th slicer error association sideThe predicted value of difference, i.e., new error covariance;
Step 45: calculating kalman gainHere measured valueFor calculated value so H=1 is
Wherein R is measurement noise rn+1Covariance;
Step 46: rightCorrection updates,
At this timeFor the optimum bandwidth of (n+1)th fragment;Yn+1The bandwidth measuring value being sliced for (n+1)th;
Step 47: continuing step 48 if not yet all downloading is completed if slice, otherwise exit entire prediction process;
Step 48: the iteration for the optimum bandwidth value of next step the n-th+2 slices of estimation is updated operation, that is, updatespn+1Value:
Pn+1It is the optimum bandwidth deviation of (n+1)th slice;
Step 49, step 43 is jumped to, repeats always to step 47 to terminate.
Further, the detailed process of the step 5 is:
Step 51: if video slicing not all complete by downloading, i.e., there are still prediction bandwidth, thening follow the steps 52, otherwiseDownloading process terminates;
Step 52:
In order to ensure buffer area does not occur overflow and underflow, at the same ensure buffer area can effectively cancellation bandwidth fluctuation madeAt the true bring of forecasting inaccuracy play and stagnate or a possibility that buffer overflow, now to two time thresholds of setting buffersqminAnd qmax, the code to be chosen is determined according to the threshold values of setting buffers and already existing fragment number and prediction bandwidthRate value.
Further, the detailed process of the step 52 is:
Step 521:
Calculate n-th of fragment snThe remaining duration in buffer area after the completion of downloading:
T(tn(e))=T (tn(s))+θ-(tn(e)-tn(s)) (8)
Wherein T (tn(e)) indicate that n-th of fragment has downloaded rear buffer area duration, while being also to start downloading (n+1)th to cutThe duration of buffer area when piece, T (tn(s)) duration of buffer area when indicating to start to download n-th of fragment, while being also to have downloaded theThe duration of buffer area when n-1 fragment;
Step 522:
As T (tn+1(s)) < qminWhen buffer area slice a possibility that being finished, in order to ensure there are enough views in buffer areaFrequency slice must assure that T (tn+1(e))≥qmin, then its code rate needs to meet:
The value that the formula equal sign left side is calculated only is denoted as ψ without meaning by ψ, code rate r (n+1) value selected by (n+1)thFor max (r (1), ψ), but since code rate value is series of discrete value, so final under the premise of guaranteeing that video playing is smoothCode rate value be distance max (r (1), ψ) it is nearest take fixed code rate value downwards, wherein r (1) be when video segment generates mostSmall code rate;
Step 523:
As T (tn+1(s)) > qmaxWhen buffer area have enough slices, a possibility that overflow goes out is loaded under continuing, in order to trueProtecting buffer area, overflow does not guarantee T (tn+1(e))≤qmax, then its code rate needs to meet:
The value that the formula equal sign left side obtains only is denoted as ξ without meaning by ξ;
For situation one: r (p) >=ξ in order to guarantee video pictures shake as small as possible, the code rate value of selection is ξ, simultaneously becauseCode rate value is series of discrete value, so code rate value final under the premise of guaranteeing that video playing is smooth is distance ξ nearestFixed code rate value is taken upwards;
When situation two: r (p) < ξ, buffer area overflow must be will appear by continuing downloading, in order to avoid such case occurs thenStart sleep mechanism, i.e. downloading can be suspended a period of time, and n-th of fragment s is recalculated in pause laternIt is buffered after the completion of downloadingThe remaining duration in area continues code rate judgement, and wherein r (p) is maximal rate when video segment generates;
Step 524:
Work as qmin≤T(tn+1(s))≤qmaxWhen, the fragment number of buffer area is in an optimal range, the value model of code rateIt encloses are as follows:
In order to reduce code rate fluctuation, code rate value is identical as a upper slice code rate value holding: r (n+1)=r (n).
Beneficial effects of the present invention: the present invention is the adaptively selected algorithm of dynamic code rate based on DASH agreement, is related toBandwidth prediction and buffer queue management realize video quality and change with the dynamic of network condition.Algorithm is filtered using KalmanWave predicts bandwidth, greatly improves precision of prediction, and the bandwidth predicted is combined with buffer area restrictive condition, finallyIt determines the code rate of slice to be downloaded and downloads the slice file of the code rate.It ensure that and mentioned as far as possible under the premise of smooth playingHigh video playing quality greatly enhances user's viewing experience.
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 belowThere 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 thisSome embodiments of invention for those of ordinary skill in the art without creative efforts, can be withIt obtains other drawings based on these drawings.
Fig. 1 is the client of the embodiment of the present invention and the connection interactive process figure of server.
Fig. 2 is the MPD structural schematic diagram of the embodiment of the present invention.
Fig. 3 is the flow chart of the code rate adaptive algorithm of the embodiment of the present invention.
Specific embodiment
Below in conjunction in the embodiment of the present invention, technical solution in the embodiment of the present invention is clearly and completely retouchedIt states, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.Based on the present inventionIn embodiment, every other implementation obtained by those of ordinary skill in the art without making creative effortsExample, shall fall within the protection scope of the present invention.
As shown in Figure 1, the embodiment of the invention provides a kind of dynamic self-adapting code rate selections based on MPEG-DASH agreementMethod, including following functions: establishing the HTTP connection, downloading and storage MPD file, parsing MPD of server and clientFile, code rate are adaptively selected.
Thinking is as follows: initially setting up the HTTP connection of server and client, client is from clothes after the completion of connection is establishedBusiness device downloading MPD file simultaneously stores it and is parsed;Secondly in order to shorten the broadcasting that buffer time carries out video as early as possible, andInitial data is accumulated for subsequent bandwidth prediction, according to the obtained range of code rates of parsing MPD file first with minimum code rate downloading onePartial video slice is simultaneously calculated, counted and is recorded to network bandwidth when downloading partial video slice, and uses karrGraceful filter forecasting method predicts network bandwidth when downloading next video slicing;Last basis obtained prediction aboveBandwidth and current cache area video segment residue situation make a choice to the code rate for downloading next video segment, to make to be broadcastIt puts video quality and dynamically adapts to different network situations.
Specifically follow the steps below:
Step 1,
Initially set up the HTTP connection of server and client;Since DASH is using HTTP as transport protocol in application layer, and HTTP is based on Transmission Control Protocol, so the session of client and server needs to establish connection in transport layer.
The detailed process of its HTTP connection for establishing server and client are as follows:
Step 11: one URL object of creation;
Step 12: one HTTP link of creation;
Step 13: obtaining data using IO stream.
Step 2,
Then user end to server sends HTTP Get request, and request downloading MPD file simultaneously stores.
Detailed process are as follows:
Step 21: judging that MPD file whether there is, then return to 1 if it exists and otherwise return to 0;
Step 22: file being downloaded in the absence of file;
Step 23: the file completed to downloading stores.
Step 3,
Server, which receives, to carry out response to client after the request of client and sends MPD file, client to MPD file intoRow is downloaded and is parsed to the MPD file of downloading;In order to allow video to start to play as early as possible, according to parsing MPD file instituteRange of code rates corresponding to the URL of obtained video slicing first downloads a part of video segment with minimum code rate, and server receivesVideo segment file is sent to client after request, client is downloaded slice file.The structure of MPD file such as Fig. 2 instituteShow.
Detailed process are as follows:
Step 31: the specified attribute of Representation element in MPD file is obtained, only needs to obtain id here,Tri- attributes of width, height;
Step 32: obtaining the URL of each grade video segment in MPD file;
Step 33: being downloaded according to the video segment that minimum code rate is chosen in the address URL obtained by parsing MPD file.
Step 4,
Network bandwidth when to step 3 foradownloaded video slice calculates, and counts and records and uses Kalman filtering pre-Survey method predicts network bandwidth when downloading next video slicing.
Fig. 3 is the flow chart of the adaptively selected algorithm of code rate, although after client is downloaded and parses to MPD fileThe URL of video file has been obtained, but can't be directly downloaded to make user obtain better audiovisual experience, it is necessary to passed throughCross the adaptively selected strategy of code rate.
The specific steps of which are as follows:
Step 41: obtaining the network bandwidth b of downloading slicingn:
Wherein: tn(e) time that n-th of slice downloading is completed is indicated;tn(s) indicate n-th slice start downloading whenBetween;R (n) indicates the selected code rate of n-th of slice;θ indicates that each slice plays duration, and here, each slice playsDuration is all identical, and being all cut into its value of identical time span when carrying out video cutting encapsulation is 2 seconds;bnIt is n-thThe network download bandwidth value of slice.
Step 42: establish system state equation and measurement equation:
Wherein: bn+1It is the prediction download bandwidth value of (n+1)th slice;Yn+1It is n+1 slice bandwidth measuring value;A is shapeState transfer matrix reflects system from the download bandwidth of n-th of slice to (n+1)th state change;unIt is n-th of sliceDominant vector;B is control allocation matrix;qnAnd rn+1It is system noise and measurement noise, q respectivelynStatistical property E [qn]=0,rn+1Statistical property E [rn+1]=0;H is observing matrix.
Step 43: by the optimum bandwidth value of n-th of fragmentRemove the state value of (n+1)th fragment of predictionDue to mouldThe random disturbances q of typenDo not know in advance, soDue to the variation range of bandwidth under usual conditionIt is not very big, it is possible to regard the optimal download bandwidth of the prediction download bandwidth of next fragment and a upper fragment as oneSample, even A=1, dominant vector un=0, it obtains:
Step 44: by last error covariance pnWith system noise qnCovariance Q predict new error covarianceI.e.
Wherein Q is system noise qnCovariance, type belongs to white Gaussian noise;It is assisted for (n+1)th slicer errorThe predicted value of variance, i.e., new error covariance.
Step 45: calculating kalman gainHere measured valueFor calculated value so H=1 is
Wherein R is measurement noise rn+1Covariance;
Step 46: rightCorrection updates,
At this timeFor the optimum bandwidth of (n+1)th fragment;Yn+1The bandwidth measuring value being sliced for (n+1)th.
Step 47: continuing step 48 if not yet all downloading is completed if slice, otherwise exit entire prediction process.
Step 48: the iteration for the optimum bandwidth value of next step the n-th+2 slices of estimation is updated operation, that is, updatespn+1Value:
Pn+1It is the optimum bandwidth deviation of (n+1)th slice;
Step 49, step 43 is jumped to, repeats always to step 47 to terminate.
Step 5: according to the obtained prediction bandwidth of step 4 and combining video segment residue situation in current cache area to downloadingThe code rate of next video segment makes a choice, detailed process are as follows:
Step 51: if video slicing not all complete by downloading, i.e., there are still prediction bandwidth, thening follow the steps 52, otherwiseDownloading process terminates.
Step 52:
In order to ensure buffer area does not occur overflow and underflow, at the same ensure buffer area can effectively cancellation bandwidth fluctuation madeAt the true bring of forecasting inaccuracy play and stagnate or a possibility that buffer overflow, now to two time thresholds of setting buffersqminAnd qmax, the code to be chosen is determined according to the threshold values of setting buffers and already existing fragment number and prediction bandwidthRate value.
Wherein, step 52 specifically:
Step 521:
Calculate n-th of fragment snThe remaining duration in buffer area after the completion of downloading:
T(tn(e))=T (tn(s))+θ-(tn(e)-tn(s)) (8)
Wherein T (tn(e)) indicate that buffer area duration after n-th of fragment download (while being also to start to download (n+1)th to cutThe duration of buffer area when piece), T (tn(s)) indicate that the duration of buffer area when starting to download n-th of fragment (while being also to have downloaded theThe duration of buffer area when n-1 fragment).
Step 522:
As T (tn+1(s)) < qminWhen buffer area slice a possibility that being finished, in order to ensure there are enough views in buffer areaFrequency slice must assure that T (tn+1(e))≥qmin, then its code rate needs to meet:
ψ has no meaning, and the value that the formula equal sign left side is calculated only is denoted as ψ.Code rate r (n+1) selected by (n+1)thValue should be max (r (1), ψ), but since code rate value is series of discrete value, so in the premise for guaranteeing video playing smoothnessDown final code rate value be distance max (r (1), ψ) it is nearest take fixed code rate value downwards.Wherein r (1) is video segment generationWhen minimum code rate.
Step 523:
As T (tn+1(s)) > qmaxWhen buffer area have enough slices, a possibility that overflow goes out is loaded under continuing, in order to trueProtecting buffer area, overflow not must assure that T (tn+1(e))≤qmax, then its code rate needs to meet:
ξ similarly has no concrete meaning, and the value that the formula equal sign left side obtains only is denoted as ξ;
Situation one: r (p) >=ξ is in order to guarantee video pictures shake as small as possible, and the code rate value of selection should be ξ, simultaneouslySince code rate value is series of discrete value, thus code rate value final under the premise of guaranteeing that video playing is smooth be distance ξ mostClose takes fixed code rate value upwards.
When situation two: r (p) < ξ, buffer area overflow must be will appear by continuing downloading, in order to avoid such case occurs thenStart sleep mechanism, i.e. downloading can be suspended a period of time, and n-th of fragment s is recalculated in pause laternIt is buffered after the completion of downloadingThe remaining duration in area continues code rate judgement.Wherein r (p) is maximal rate when video segment generates.
Step 524:
Work as qmin≤T(tn+1(s))≤qmaxWhen, the fragment number of buffer area is in an optimal range, the value model of code rateIt encloses are as follows:
In order to reduce code rate fluctuation, code rate value is identical as a upper slice code rate value holding: r (n+1)=r (n).
Step 6: jumping to step 4-5 if video segment is completed without all downloadings, continue to execute prediction and downloadedJourney, otherwise exits cyclic process, and method terminates.
The present invention in bandwidth prediction using the method for Kalman prediction, due to the principle of this method defer to it is pre-Survey-modified iteration process, so ensure that its bandwidth prediction precision;Hold secondly as mobile client has storageInsufficient actual conditions are measured, such case most probably causes buffer area that " spilling " phenomenon occurs, when lower overflow occurs for buffer area,Meeting is so that video playing is stagnated, and when overflowing in generation, and bandwidth resources cannot be made full use of to improve video playing quality.In order to solve this problem it joined buffer area control strategy again, and by the way that bandwidth prediction is controlled the side combined with buffer areaMethod predicts the code rate of video segment to be downloaded, and selected slice code rate can be made both to be able to satisfy the practical feelings of client-cache in this wayIt the problem of condition, reduction is brought by buffer overflow, preferentially ensure that video smooth playing, and selected code rate can be made to meet networkBandwidth actual change situation guarantees video quality, greatly enhances user's viewing experience.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the scope of the present invention.It is allAny modification, equivalent replacement, improvement and so within the spirit and principles in the present invention, are all contained in protection scope of the present inventionIt is interior.