Disclosure of Invention
The technical problem mainly solved by the application is to provide a computer-readable storage medium, a streaming media transmission method, a fragment information generation method, a streaming media playing method and a streaming media playing device, which can reduce the time delay during live video playing.
In order to solve the above technical problem, one technical solution adopted in the embodiments of the present application is: a transmission method of streaming media is provided, and the transmission method comprises the following steps: acquiring fragmentation information of the streaming media; carrying out fragmentation processing on the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information; transmitting or receiving the streaming media fragments according to the sequence indicated by the fragment information; the streaming media after the fragmentation processing comprises a last streaming media fragment and a plurality of non-last streaming media fragments, and the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment.
Wherein, the time lengths of a plurality of non-last streaming media fragments are equal.
The time lengths of a plurality of non-last streaming media fragments all satisfy the following formula: t = n × tgop(ii) a Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs the key frame time interval of the streaming media.
The time length of the last streaming media fragment satisfies the following formula: t is tlast=N×tgop+ T% T; wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
Wherein n is more than or equal to 1 and less than or equal to 3.
Before the step of obtaining the fragmentation information of the streaming media, the method comprises the following steps: receiving a streaming media playing request of a terminal; sending a request for information on the streaming media to the source station; receiving information of streaming media fed back by a source station; analyzing the duration of the streaming media from the streaming media information; the step of acquiring the fragmentation information of the streaming media comprises the following steps: and acquiring the fragment information of the streaming media according to the duration of the streaming media.
Wherein t is less than or equal to 10 secondslastLess than or equal to 60 seconds.
After the step of fragmenting the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information, the method comprises the following steps: and sending the fragment information to the terminal to allow the terminal to download and play the plurality of streaming media fragments according to the sequence indicated by the fragment information.
In order to solve the above technical problem, another technical solution adopted in the embodiment of the present application is: a method for generating fragmentation information is provided, the method comprising: acquiring related information of streaming media; generating fragmentation information of the streaming media according to the related information of the streaming media and a preset fragmentation algorithm, and storing the fragmentation information; the preset fragmentation algorithm is configured to divide the streaming media into a last streaming media fragment and a plurality of non-last streaming media fragments, wherein the time length of the last streaming media fragment is greater than the time length of the non-last streaming media fragment; the fragment information is used for processing the streaming media into a plurality of streaming media fragments, indicating the sequence of transmitting, receiving or playing the streaming media fragments, and indicating the duration of each streaming media fragment.
The preset fragmentation algorithm comprises the following steps: the time lengths of a plurality of non-last streaming media fragments are equal.
Wherein, the related information of the streaming media comprises the key frame time interval of the streaming media;
the preset slicing algorithm comprises the following steps: t = n × tgop;
Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs the key frame time interval of the streaming media.
Wherein, the related information of the streaming media comprises the total duration of the streaming media;
the preset slicing algorithm comprises the following steps: t is tlast=N×tgop+T%t;
Wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
In order to solve the above technical problem, another technical solution adopted in the embodiment of the present application is: a method for playing streaming media is provided, and the method for playing the streaming media comprises the following steps: receiving fragmentation information of the streaming media, wherein the fragmentation information is used for fragmenting the streaming media into a plurality of streaming media fragments, indicating the sequence of sending, receiving or playing the plurality of streaming media fragments, and indicating the duration of each streaming media fragment; downloading and playing a plurality of streaming media fragments according to the sequence indicated by the fragment information; the streaming media after the fragmentation processing comprises a last streaming media fragment and a plurality of non-last streaming media fragments, and the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment.
Wherein, the time lengths of a plurality of non-last streaming media fragments are equal.
The time lengths of a plurality of non-last streaming media fragments all satisfy the following formula: t = n × tgop;
Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs the key frame time interval of the streaming media.
The time length of the last streaming media fragment satisfies the following formula: t is tlast=N×tgop+T%t;
Wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
In order to solve the above technical problem, another technical solution adopted in the embodiment of the present application is: there is provided a streaming media delivery device comprising a processor and a memory electrically connected to the processor, the memory for storing a computer program, the processor for invoking the computer program to perform the above method.
In order to solve the above technical problem, another technical solution adopted in the embodiments of the present application is: there is provided a computer readable storage medium for storing a computer program that can be invoked to perform the above-described method.
The embodiment of the application acquires the fragment information of the streaming media; carrying out fragmentation processing on the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information; transmitting or receiving the streaming media fragments according to the sequence indicated by the fragment information; the streaming media after the fragmentation processing comprises the last streaming media fragment and a plurality of non-last streaming media fragments, the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment, and the problem that the playing abnormality occurs because some last fragments of the playing terminal cannot be requested due to the fact that the number of fragments actually cut out is inconsistent with the list information which is informed to the playing terminal due to the fact that the key frame interval of an actual code stream is not uniform can be reduced to the maximum probability.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be further noted that, for the convenience of description, only some of the structures related to the present application are shown in the drawings, not all of the structures. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first", "second", etc. in this application are used to distinguish between different objects and not to describe a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
Referring to fig. 1, fig. 1 is a schematic flow chart illustrating a streaming media transmission method according to an embodiment of the present application.
In this embodiment, the streaming media transmission method may include the following steps:
step S101: and acquiring the fragment information of the streaming media.
In this embodiment, the execution subject of the streaming media transmission method may be a server. Such as HLS servers. The step of obtaining the fragmentation information of the streaming media may include: the server receives a streaming media playing request of the terminal; the server sends a request for information of the streaming media to the source station; the server receives the information of the streaming media fed back by the source station; and analyzing the time length T of the streaming media from the streaming media information.
In one example, the request for information of the streaming media may be an RTSP request or an RTMP request. The information of the streaming media may be SDP information or metadata information. When a terminal requests to request an HLS server to order a certain streaming media, the HLS server first sends an RTSP request to a source station to obtain SDP (Session Description Protocol) information, or sends an RTMP request to obtain Metadata information (Metadata), then parses the SDP information or the Metadata information to obtain a playing time T of the streaming media, and then generates an M3U8 list (containing fragment information) of the streaming media according to the playing time T and a predetermined slicing rule and returns the M3U8 list to the terminal. By the above mode, when the playing request is received, the playing duration T of the actual streaming media resource is obtained from the source station, and the situation that the list fed back to the terminal is inconsistent with the cut fragment is avoided as much as possible.
The terminal may be an electronic device with a playing function, such as a smart phone, a tablet computer, a desktop computer, a notebook computer, and so on.
The streaming media may be audio or video.
The predetermined slicing rule at least satisfies that the streaming media after the slicing processing comprises the last streaming media slice and a plurality of non-last streaming media slices, and the duration of the last streaming media slice is longer than the duration of the non-last streaming media slices. The time length of the last streaming media fragment is set to be relatively long, so that the deviation problem of the actual code stream caused by uneven key frame intervals during actual slicing can be buffered, the actual fragment number is ensured to be consistent with that described by the M3U8 list fed back to the playing terminal at the maximum probability, and the terminal can normally play the streaming media resource.
Optionally, the predetermined slicing rule further satisfies that the time lengths of a plurality of non-last streaming media slices after the slicing processing are equal, so that the HLS on-demand dragging precision can be ensured.
In one embodiment, the time durations of the plurality of non-last streaming media segments all satisfy the following formula: t = n × tgop(ii) a Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs a key frame (i.e., I-frame) time interval of the streaming media.
In one embodiment, the duration of the last streaming media segment satisfies the following formula: t is tlast=N×tgop+ T% T; wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
Alternatively, 1 ≦ n ≦ 3. In this embodiment, the duration of each slice is not suitable for too long, and each slice has 1-3 key frame time intervals (t)gop) The time length is long, so that the HLS on-demand dragging precision can be ensured.
Alternatively, 10 seconds ≦ tlastLess than or equal to 60 seconds, thereby ensuring HLS pointAnd (5) playing and dragging precision.
Wherein, the fragmentation information further includes the total fragmentation number, i.e. the total number of the streaming media fragments. The total number of slices satisfies the following formula: num = (T-T)last)/t+1。
Optionally, N is more than or equal to 1 and less than or equal to N and N is a value slightly larger than N, so that the HLS on-demand dragging precision can be ensured.
Step S102: and carrying out fragmentation processing on the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information.
Step S103: and sending or receiving the streaming media fragments according to the sequence indicated by the fragment information, wherein the streaming media after fragment processing comprises the last streaming media fragment and a plurality of non-last streaming media fragments, and the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment.
After the step of fragmenting the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information, the method may include the following steps:
sending the fragment information to the terminal to allow the terminal to download and play the plurality of streaming media fragments according to the sequence indicated by the fragment information
In an application example, it is assumed that the playing time T of the streaming media resource is 31 seconds, and the key frame interval time T of the streaming media code streamgopFor 2 seconds, N in this embodiment is 1, N is 5, that is, the time duration t of the non-last streaming media segment is one gop time duration t =1 × 2=2 seconds, and the time duration t of the last segment is t =1 × 2 secondslast=5 × 2+31%2=11 seconds, and the total number of slices num = (31-11)/2+1=11 slices. Then, according to the slicing rule, 11 slices can be actually cut, the time length of the last slice is 11 seconds, the deviation problem existing in the actual slicing process caused by the fact that the key frame interval is not uniform in the actual code stream can be buffered, the actual number of the slices is ensured to be consistent with that described by the M3U8 list fed back to the playing terminal at the maximum probability, and the terminal can normally play the section of streaming media resources.
Further, the present application also provides a method for generating fragmentation information, please refer to fig. 2, and fig. 2 is a schematic flow diagram of a method for generating fragmentation information according to an embodiment of the present application.
In this embodiment, the method for generating the fragmentation information may include:
step S201: and acquiring related information of the streaming media.
Step S202: and generating the fragmentation information of the streaming media according to the related information of the streaming media and a preset fragmentation algorithm, and storing the fragmentation information.
The preset fragmentation algorithm is configured to divide the streaming media into a last streaming media fragment and a plurality of non-last streaming media fragments, wherein the time length of the last streaming media fragment is longer than the time length of the non-last streaming media fragment.
The fragment information is used for processing the streaming media into a plurality of streaming media fragments, indicating the sequence of transmitting, receiving or playing the streaming media fragments, and indicating the duration of each streaming media fragment.
The preset slicing algorithm comprises the following steps: the time lengths of a plurality of non-last streaming media fragments are equal.
The related information of the streaming media includes a key frame time interval of the streaming media.
The preset slicing algorithm comprises the following steps: t = n × tgop。
Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs the key frame time interval of the streaming media.
The related information of the streaming media includes a total duration of the streaming media.
The preset slicing algorithm comprises the following steps: t is tlast=N×tgop+T%t。
Wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
Further, the present application also provides a method for playing streaming media, please refer to fig. 3, and fig. 3 is a schematic flow chart of the method for playing streaming media according to the embodiment of the present application.
In this embodiment, the method for playing streaming media may include:
step S301: receiving the slicing information of the streaming media.
The fragment information is used for fragmenting the streaming media into a plurality of streaming media fragments, indicating the sequence of transmitting, receiving or playing the streaming media fragments, and indicating the duration of each streaming media fragment.
Step S302: and downloading and playing the plurality of streaming media fragments according to the sequence indicated by the fragment information.
The streaming media after the fragmentation processing comprises a last streaming media fragment and a plurality of non-last streaming media fragments, and the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment.
Wherein, the time lengths of a plurality of non-last streaming media fragments are equal.
The time lengths of a plurality of non-last streaming media fragments all satisfy the following formula: t = n × tgop。
Wherein t is the duration of the non-last streaming media segment, n is a positive integer, and t isgopIs the key frame time interval of the streaming media.
The time length of the last streaming media fragment satisfies the following formula: t is tlast=N×tgop+T%t。
Wherein, tlastThe time length of the last streaming media fragment, N is a positive integer and N>n and T are the total duration of the streaming media.
Referring to fig. 4, fig. 4 is a schematic diagram of a hardware structure of a streaming media transmission device according to an embodiment of the present application.
In this embodiment, the streaming media transmission device may at least include aprocessor 21 and amemory 22 electrically connected to theprocessor 21, where thememory 22 is used to execute a computer program, and theprocessor 21 is used to call the computer program to execute the method of any one of the above embodiments.
In the embodiment of the present application, the streaming media transmission device may be a server, and for example, may be an HLS server. In other embodiments, other transmission devices may be used, and a transmission device that slices the transport stream media by using the method of the present application is within the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other manners. For example, the above-described device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
Embodiments of the present invention also provide a computer-readable storage medium for storing a computer program, which can be executed by a processor to implement the method provided in the above embodiments. It is understood that the method executed by the computer program stored in the readable storage medium in this embodiment is similar to the method provided in the foregoing embodiments, and the principle and steps thereof are the same, and are not described herein again.
The storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, which can store program codes.
The embodiment of the application acquires the fragment information of the streaming media; carrying out fragmentation processing on the streaming media into a plurality of streaming media fragments according to the indication of the fragmentation information; transmitting or receiving the streaming media fragments according to the sequence indicated by the fragment information; the streaming media after the fragmentation processing comprises the last streaming media fragment and a plurality of non-last streaming media fragments, the time length of the last streaming media fragment is longer than that of the non-last streaming media fragment, and the problem that the playing abnormality occurs because some last fragments of the playing terminal cannot be requested due to the fact that the number of fragments actually cut out is inconsistent with the list information which is informed to the playing terminal due to the fact that the key frame interval of an actual code stream is not uniform can be reduced to the maximum probability.
The above embodiments are merely examples and are not intended to limit the scope of the present disclosure, and all modifications, equivalents, and flow charts using the contents of the specification and drawings of the present disclosure or those directly or indirectly applied to other related technical fields are intended to be included in the scope of the present disclosure.