Disclosure of Invention
The embodiment of the application provides a method and a device for adjusting video code rate, which can solve the technical problems in the related technology. The technical scheme of the method and the device for adjusting the video code rate is as follows:
in a first aspect, a method for adjusting a video bitrate is provided, where the method includes:
sending the video stream with the first code rate to a target client through a bidirectional communication link;
after receiving a request for reducing the code rate sent by the target client, determining the network bandwidth condition of a network accessed by the target client;
if the network bandwidth of the network accessed by the target client is determined to be insufficient, acquiring a video stream with a second code rate to be sent, wherein the second code rate is lower than the first code rate;
and sending the video stream with the second code rate to the target client through the bidirectional communication link.
In a possible implementation manner, the determining a network bandwidth condition of a network accessed by the target client includes:
determining the data volume of a sending buffer corresponding to the target client;
and determining the network bandwidth condition of the network accessed by the target client based on the data volume of the sending buffer corresponding to the target client.
In a possible implementation manner, the determining, based on the data amount of the transmission buffer corresponding to the target client, a network bandwidth condition of a network to which the target client accesses includes:
determining the average value of the data amount of the sending buffer corresponding to all the clients, wherein the played video is the same as the video played by the target client;
and if the difference value between the data volume of the sending buffer area corresponding to the target client and the average value is larger than a target threshold value, determining that the network bandwidth of the network accessed by the target client is insufficient.
In a possible implementation manner, the request for reducing the bit rate carries an identifier of a playing video and a playing progress;
the acquiring the video stream with the second code rate to be sent includes:
and determining the video stream after the playing progress as the video stream with the second code rate to be sent in the video stream corresponding to the identifier of the playing video based on the identifier of the playing video and the playing progress.
In a possible implementation manner, after determining a network bandwidth condition of a network accessed by the target client, the method further includes:
and sending a message carrying the network condition to the target client.
In a possible implementation manner, the request for reducing the bitrate is sent when the target client detects that the duration of the remaining playable videos in the video playing buffer is less than a target duration.
In a possible implementation manner, after the sending the video with the first bitrate to the target client through the bidirectional communication link, the method further includes:
after receiving a request for increasing the code rate sent by the target client, acquiring a video stream with a third code rate to be sent, wherein the third code rate is higher than the first code rate;
and sending the video stream with the third code rate to the target client through the bidirectional communication link.
In a second aspect, an apparatus for adjusting a video bitrate is provided, the apparatus comprising:
the sending module is used for sending the video stream with the first code rate to the target client through the bidirectional communication link;
the determining module is used for determining the network bandwidth condition of a network accessed by the target client after receiving the request for reducing the code rate sent by the target client;
an obtaining module, configured to obtain a video stream with a second code rate to be sent if it is determined that a network bandwidth of a network to which the target client is accessed is insufficient, where the second code rate is lower than the first code rate;
the sending module is further configured to send the video stream with the second bitrate to the target client through the bidirectional communication link.
In one possible implementation manner, the determining module is configured to:
determining the data volume of a sending buffer corresponding to the target client;
and determining the network bandwidth condition of the network accessed by the target client based on the data volume of the sending buffer corresponding to the target client.
In one possible implementation manner, the determining module is configured to:
determining the average value of the data amount of the sending buffer corresponding to all the clients, wherein the played video is the same as the video played by the target client;
and if the difference value between the data volume of the sending buffer area corresponding to the target client and the average value is larger than a target threshold value, determining that the network bandwidth of the network accessed by the target client is insufficient.
In a possible implementation manner, the request for reducing the bit rate carries an identifier of a playing video and a playing progress;
the obtaining module is configured to:
and determining the video stream after the playing progress as the video stream with the second code rate to be sent in the video stream corresponding to the identifier of the playing video based on the identifier of the playing video and the playing progress.
In a possible implementation manner, the sending module is further configured to:
and sending a message carrying the network condition to the target client.
In a possible implementation manner, the request for reducing the bitrate is sent when the target client detects that the duration of the remaining playable videos in the video playing buffer is less than a target duration.
In a possible implementation manner, the obtaining module is further configured to:
after receiving a request for increasing the code rate sent by the target client, acquiring a video stream with a third code rate to be sent, wherein the third code rate is higher than the first code rate;
the sending module is further configured to:
and sending the video stream with the third code rate to the target client through the bidirectional communication link.
In a third aspect, a terminal is provided, where the terminal includes a memory and a processor, and the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the method for adjusting a video bitrate according to the first aspect.
In a fourth aspect, a computer-readable storage medium is provided, wherein at least one instruction is stored in the computer-readable storage medium, and the at least one instruction is loaded and executed by a processor to implement the method for adjusting video bitrate according to the first aspect.
The beneficial effects brought by the technical scheme provided by the embodiment of the application at least comprise:
the embodiment of the application provides a method for adjusting video code rate, which can be used for adjusting the video code rate. In the process of sending the video stream with the first code rate to the target client through the bidirectional communication link, after receiving a request for reducing the code rate sent by the target client, determining the network bandwidth condition of a network accessed by the target client. And if the network bandwidth of the network accessed by the target client is determined to be insufficient, acquiring the video stream with the second code rate to be sent, and sending the video stream with the second code rate to the target client through the original bidirectional communication link. Therefore, the method for adjusting the video code rate provided by the embodiment of the application sends the video stream through the bidirectional communication link, so that when the client detects that the pause in the video is likely to occur, the client can send the request for reducing the code rate to the server through the bidirectional communication link, the server can directly send the video stream to the client through the original bidirectional communication link without establishing a new link, the possibility of picture jump back and frame jump is reduced, and the watching experience of a user is effectively improved.
Detailed Description
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
Please refer to fig. 4, which illustrates an implementation environment of the method for adjusting a video bitrate according to an embodiment of the present application. The implementation environment may include aserver 01 and one or more terminals 02 (e.g., 2terminals 02 are shown in fig. 4). Each terminal 02 may establish a bidirectional communication link with theserver 02 in a wired or wireless manner, for example, a Real Time Messaging Protocol (RTMP) link may be established.
The terminal 02 may be a smart phone, a tablet computer, an MP4(moving picture experts group audio layer IV), a laptop portable computer, or a desktop computer. Each terminal 02 is installed with a client (this client may also be referred to as an application) capable of playing video, such as a live client. Theserver 01 may be a server, a server cluster composed of a plurality of servers, or a cloud computing service center. Theserver 01 may be a background server of a client installed in the terminal 02.
In the embodiment of the present application, theserver 01 sends a video stream to the terminal 02, so that the target client plays a video. In the process of playing the video, when the target client detects that video playing is about to be paused, or when the target client artificially selects to reduce the code rate, the target client may send a request for reducing the code rate to theserver 01. Theserver 01 detects the network bandwidth condition of the network accessed by the target client to determine whether the bitrate needs to be reduced, and sends the bitrate-reduced video stream to the server when the network bandwidth is determined to be insufficient, so as to ensure the smoothness of the video played by the target client.
As shown in fig. 1, a processing flow of the method for adjusting a video bitrate provided by the embodiment of the present application may include the following steps:
instep 101, a video stream at a first bitrate is transmitted to a target client over a bidirectional communication link.
Wherein the bi-directional communication link may be an RTMP link. The server and the client which establish the bidirectional communication link can both actively initiate communication and send notification signaling data or send video stream data.
The video stream may or may not be a live video stream, such as a movie or a tv show. The video stream may include both audio data and image data.
In implementation, the server sends the video stream with the first code rate to the target client in real time through the bidirectional communication link, so that the target client can play the video corresponding to the video stream. It can be appreciated that the first code rate should be larger than the lowest code rate that can be achieved, since the code rate needs to be lowered.
Instep 102, after receiving the request for reducing the bit rate sent by the target client, the network bandwidth condition of the network accessed by the target client is determined.
Network bandwidth conditions may include, among others, insufficient network bandwidth and sufficient network bandwidth.
In implementation, the target client can start a function of dynamically adjusting the code rate to ensure the smoothness of playing the video. In the process of playing the video, the target client monitors the time length of the remaining playable video in the video playing cache region in real time, if the time length is less than the target time length, it is judged that the video is likely to be jammed, and at this time, a request for reducing the code rate can be sent to the server. That is, the request for reducing the bit rate is sent when the target client detects that the duration of the remaining playable video in the video playing buffer is less than the target duration.
Or, the user can also manually select to reduce the bitrate of the video during the process of watching the video. At this time, the user may operate on the terminal, trigger the instruction to decrease the code rate, and send the request to decrease the code rate to the server when the target client detects the instruction to decrease the code rate.
After receiving a request for reducing the code rate sent by the target client, the server needs to determine the network bandwidth condition of the network accessed by the target client, and then determines whether to reduce the code rate. Because, in some cases, the target client may issue a request to reduce the bitrate in case of error, even reducing the bitrate may not solve the problem. For example, the target client sends a request for reducing the code rate to the server when detecting that the data that can be played in the buffer area is empty, but the buffer area may be slow in receiving/downloading rate, or may be slow in sending data due to a problem of a video source, or the server has a busy task, a high load and is slow in sending data, and the data is unrelated to the code rate, so that the code rate does not need to be reduced in some cases, and even if the code rate is reduced, the problem cannot be solved. Therefore, the server needs to determine the network bandwidth condition, video source condition, and server resource condition of the network to which the target client is connected.
In a possible implementation manner, the method for the server to determine the network bandwidth condition of the network to which the target client accesses may be as follows, and determine the data amount of the sending buffer corresponding to the target client. And determining the network bandwidth condition of the network accessed by the target client based on the data volume of the sending buffer corresponding to the target client.
The server side is provided with a plurality of sending buffer areas for a plurality of clients connected with the server side, the sending buffer areas are used for writing data to be sent to the clients by the server side, and after response messages (used for indicating that the clients receive certain data) returned by the clients are received, the server side deletes the data corresponding to the response messages in the sending buffer areas. Therefore, when the speeds of writing in the transmission buffers by the server are the same, the larger the data amount of a certain transmission buffer is, the lower the transmission speed corresponding to the transmission buffer is, and the network bandwidth of the target client corresponding to the transmission buffer is insufficient.
In implementation, first, the data amount of the transmission buffer corresponding to the target client is determined.
Then, in a possible implementation manner, the data amount may be compared with a set target data amount threshold, and when the data amount is greater than the target data amount threshold, it may be determined that the network bandwidth of the network to which the target client accesses is insufficient; when the data amount is less than the target data amount threshold, it may be determined that the network bandwidth of the network to which the target client accesses is sufficient.
Or, in another possible implementation manner, an average value of data amounts of sending buffers corresponding to all clients where the played video is the same as the video played by the target client is determined. And if the difference value between the data volume of the sending buffer area corresponding to the target client and the average value is larger than the target threshold value, determining that the network bandwidth of the network accessed by the target client is insufficient.
The difference between the data volume of the sending buffer corresponding to the target client and the average value is greater than the target threshold, which means that the difference between the data volume and the average value is greater than the target threshold.
In implementation, by using the average value of the data volumes of the sending buffers corresponding to all the clients that play the same video as the video played by the target client as a comparison reference, the influence of the video source itself can be reduced (for example, if the video source is poor, the sending rate is generally poor, and the data volume of the sending buffer is generally large). If the data volume of the sending buffer corresponding to the target client is larger than the average value, it can be said that the receiving speed of the target client is relatively slow, and when the data volume of the data volume exceeding the average value reaches the target threshold value, it is said that the network bandwidth of the network accessed by the target client is insufficient. If the data volume of the sending buffer zone corresponding to the target client is smaller than the average value, the receiving speed of the target client is higher, and the network bandwidth of the accessed network is sufficient.
In a possible implementation manner, in order to facilitate the user to know the network bandwidth situation, after determining the network bandwidth situation of the network to which the target client accesses, a message carrying the network situation may be sent to the target client.
In implementation, if the server determines that the network bandwidth of the network received by the target client is sufficient, the video playing will not become smooth even if the bitrate of the video is reduced, so in this case, the adjustment processing of the bitrate of the video may not be performed. In order to let the user know the reason for not reducing the video bitrate (for example, for the case that the user selects to reduce the bitrate, the user may be prompted accordingly), a message carrying the network condition may be sent to the target client, for example, the message may be "network bandwidth is sufficient at this time, and bitrate does not need to be reduced". In addition, in order to enhance the autonomy of the user, an option of "whether to continue to reduce the bit rate" may also be displayed in the interface where the target client displays the message.
If the server determines that the network bandwidth received by the target client is insufficient, the server may also send information carrying the network condition to the target client, for example, in this case, the information may be "the network bandwidth is insufficient at this time, and the code rate is to be reduced".
Instep 103, if it is determined that the network bandwidth of the network to which the target client is accessed is insufficient, a video stream with a second bitrate to be sent is obtained.
Wherein the second code rate is lower than the first code rate.
The request for reducing the code rate carries the identifier of the played video and the playing progress.
The server may store the video streams with multiple bit rates in advance.
In implementation, when it is determined that the network bandwidth of the network to which the target client accesses is insufficient, the video stream with the second bitrate needs to be sent to the target client. And, the first frame of the transmitted video stream of the second bitrate should be accurate to avoid picture back-off or frame skipping.
In a possible implementation manner, the method for obtaining the video stream with the second bitrate to be sent may be as follows, based on the identifier of the played video and the playing progress, and in the video stream corresponding to the identifier of the played video, determining that the video stream after the playing progress is the video stream with the second bitrate to be sent.
The playing progress can be a timestamp of a video frame being played when the client sends a request for reducing the code rate.
In implementation, the server may determine the video stream of the second bitrate according to the identifier of the video carried in the request for reducing bitrate. And then, according to the time stamp of the carried video frame, determining the video frame with the time stamp same as the carried time stamp in the video stream of the total second code rate. And finally, determining all video streams after the determined video frame as video streams to be sent. Thus, the possibility of picture skipping or frame skipping is reduced.
Instep 104, the video stream at the second bitrate is sent to the target client over the bidirectional communication link.
In implementation, after the video stream with the second bitrate to be sent is obtained, the video stream with the second bitrate to be sent can be sent to the target client.
In a possible implementation manner, in order to make the user know that the current bitrate has been reduced, a message carrying information that the bitrate has been reduced may be sent to the target client.
It should be added that, besides the above case of reducing the code rate, the case of increasing the code rate is also included, and the specific process may be as follows:
the first step is that after a request for increasing the code rate sent by a target client is received, a video stream with a third code rate to be sent is obtained.
Wherein the third bitrate is higher than the first bitrate if the request to increase bitrate is sent after the target client sends the video stream of the first bitrate over the bidirectional communication link. The third bitrate is higher than the second bitrate if the request to increase bitrate is sent after the target client sends the video stream at the second bitrate over the bidirectional communication link.
The request for increasing the code rate also carries the identifier and the playing progress of the playing video. The playing progress may be a timestamp of a video frame being played when the client sends a request to increase the bitrate.
In implementation, in the process of playing the video, the target client monitors the remaining time length of the video that can be played in the video playing buffer area in real time, and if the time length is greater than the target time length within a period of time, the target client may try to increase the video code rate. Then at this point, a request to increase the video bitrate may be sent to the server.
Or, the user can manually select to increase the bitrate of the video during the process of watching the video. At this time, the user may operate on the terminal, trigger the instruction for increasing the code rate, and send the request for increasing the code rate to the server when the target client detects the instruction for increasing the code rate.
When a request for increasing the code rate is received, a video stream with a third code rate to be sent needs to be determined.
First, the total video stream with the third bitrate can be determined according to the identifier of the video carried in the request for increasing bitrate. And then, according to the timestamp of the carried video frame, determining the video frame with the timestamp same as the carried timestamp in the video stream of the total third code rate. And finally, determining all video streams after the determined video frame as video streams to be sent. Thus, the possibility of picture skipping or frame skipping is reduced.
Secondly, sending the video stream with the third code rate to the target client through the bidirectional communication link
In implementation, after the video stream with the third bitrate to be sent is obtained, the video stream with the third bitrate to be sent can be sent to the target client.
In order to facilitate the user to know that the current code rate is increased, a message carrying information that the code rate is increased can be sent to the target client.
Compared with the method for reducing the code rate in the related technology, the method for regulating the video code rate has the advantages that the client side in the related technology obtains the live broadcast stream through the HTTP, and the HTTP protocol is in one-way communication, so that the client side is difficult to send the notification message to the server side, when the client side detects that the code rate needs to be regulated, the client side can only reinitiate the playing request, the playing address is switched to the low-code-rate video address, and a new link request is established to play the low-code-rate audio/video stream. This inevitably leads to picture-skipping or frame-skipping problems.
In the method for adjusting video bitrate provided by the embodiment of the application, in the process of sending the video stream with the first bitrate to the target client through the bidirectional communication link, after receiving a bitrate reduction request sent by the target client, the network bandwidth condition of a network accessed by the target client is determined. And if the network bandwidth of the network accessed by the target client is determined to be insufficient, acquiring the video stream with the second code rate to be sent, and sending the video stream with the second code rate to the target client through the original bidirectional communication link. Therefore, according to the method for adjusting the video bitrate provided by the embodiment of the application, the video stream and the signaling are transmitted through the bidirectional communication link, so that when the client detects that the pause in the video stream is likely to occur, the request for reducing the bitrate can be transmitted to the server through the bidirectional communication link, the server can directly transmit the video stream to the client through the original bidirectional communication link without establishing a new link, the possibility of picture jump back and frame jump is reduced, and the watching experience of a user is effectively improved.
In addition, when the request for reducing the code rate is received, the server side judges the network bandwidth condition of the network accessed by the client side, so that the occurrence of the condition of reducing the code rate when the network bandwidth is sufficient can be reduced.
The following describes a method for adjusting video bitrate according to an embodiment of the present application with a specific example.
(1) And the target client initially plays the video with the first code rate.
(2) And the target client detects the duration of the remaining playable video in the video playing buffer area in real time, judges that the jamming is likely to occur when the duration is less than the target duration, and informs the server of the need of reducing the code rate through an RTMP notification message.
(3) After receiving the request for reducing the code rate sent by the target client, the server detects and confirms the network bandwidth condition of the network accessed by the target client, and the detection scheme is as follows:
a: the server side counts the average value of the data volume of the sending buffer areas corresponding to all the clients in real time;
b: and detecting the data volume of a sending buffer corresponding to the target client, and when the difference value between the data volume and the average value is larger than a target threshold value, determining that the network bandwidth is insufficient and the code rate playing needs to be reduced.
(4) And after the server side checks and confirms, the server side informs the client side of the detection result.
(5) After confirming that the code rate needs to be reduced, the server starts a video frame replacement function, acquires a video stream with a second code rate coded in advance, searches for a sending position, sends the video stream with the second code rate to be sent based on the original bidirectional communication link, and simultaneously informs the client that the current actual code rate is changed.
(6) After the code rate is reduced, the target client side tries to improve the playing image quality after detecting that the remaining playable videos in the video playing cache area are continuously stable for a period of time, and informs the server side of needing to improve the code rate.
(7) And after receiving the request for increasing the code rate, the server closes the dynamic replacement function of the video frame, and sends the video stream with the first code rate according to the original bidirectional communication link.
Based on the same technical concept, an embodiment of the present application further provides a device for adjusting a video bitrate, where the device may be a server in the foregoing embodiment, as shown in fig. 2, and the device includes:
a sendingmodule 201, configured to send a video stream with a first code rate to a target client through a bidirectional communication link;
a determiningmodule 202, configured to determine, after receiving a request for reducing a code rate sent by a target client, a network bandwidth condition of a network to which the target client accesses;
an obtainingmodule 203, configured to obtain a video stream with a second code rate to be sent if it is determined that a network bandwidth of a network to which a target client is accessed is insufficient, where the second code rate is lower than the first code rate;
the sendingmodule 201 is further configured to send the video stream with the second bitrate to the target client through the bidirectional communication link.
In one possible implementation, the determiningmodule 202 is configured to:
determining the data volume of a sending buffer corresponding to a target client;
and determining the network bandwidth condition of the network accessed by the target client based on the data volume of the sending buffer corresponding to the target client.
In one possible implementation, the determiningmodule 202 is configured to:
determining the average value of the data amount of the sending buffer corresponding to all the clients, wherein the played video is the same as the video played by the target client;
and if the difference value between the data volume of the sending buffer area corresponding to the target client and the average value is larger than the target threshold value, determining that the network bandwidth of the network accessed by the target client is insufficient.
In a possible implementation manner, the request for reducing the code rate carries an identifier of a played video and a playing progress;
an obtainingmodule 203, configured to:
and determining the video stream after the playing progress to be the video stream with the second code rate to be sent in the video stream corresponding to the identifier of the playing video based on the identifier of the playing video and the playing progress.
In a possible implementation manner, the sendingmodule 201 is further configured to:
and sending a message carrying the network condition to the target client.
In one possible implementation, the request for reducing the bitrate is sent when the target client detects that the duration of the remaining playable video in the video play cache region is less than the target duration.
In a possible implementation manner, the obtainingmodule 203 is further configured to:
after receiving a request for increasing the code rate sent by a target client, acquiring a video stream with a third code rate to be sent, wherein the third code rate is higher than the first code rate;
the sendingmodule 201 is further configured to:
and sending the video stream with the third code rate to the target client through the bidirectional communication link.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
It should be noted that: in the apparatus for adjusting a video bitrate provided in the foregoing embodiment, when the video bitrate is adjusted, only the division of the functional modules is illustrated, and in practical applications, the function allocation may be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the apparatus for adjusting video bitrate provided by the foregoing embodiment and the method embodiment for adjusting video bitrate belong to the same concept, and specific implementation processes thereof are detailed in the method embodiment and are not described herein again.
Fig. 3 is a schematic structural diagram of aserver 300 according to an embodiment of the present disclosure, where theserver 300 may generate a relatively large difference due to different configurations or performances, and may include one or more processors (CPUs) 301 and one ormore memories 302, where thememory 302 stores at least one instruction, and the at least one instruction is loaded and executed by theprocessor 301 to implement the method for adjusting a video bitrate.
In an exemplary embodiment, a computer-readable storage medium is further provided, in which at least one instruction is stored, and the at least one instruction is loaded and executed by a processor to implement the method for adjusting a video bitrate in the above-mentioned embodiment. For example, the computer-readable storage medium may be a ROM (Read-Only Memory), a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the protection scope of the present application.