Disclosure of Invention
The embodiment of the application aims to provide a method for transmitting videos, and the effect of improving the fluency of the videos can be achieved through the technical scheme of the embodiment of the application.
In a first aspect, an embodiment of the present application provides a method for transmitting a video, where the method determines a code rate of a slice to be transmitted in a video stream; determining target bits of slices to be sent according to the code rate of the slices to be sent and the time length of the slices to be sent, wherein the time length of each slice to be sent in a video stream is the same; distributing target bits of the slices to be sent to each frame in the slices to be sent according to a preset distribution rule, and coding the slices to be sent according to the number of bits distributed to each frame in the slices to be sent to obtain coded slices to be sent; and sending the coded slice to be sent to the terminal equipment.
In the process, a fixed number of bits are distributed to each video slice through the duration of each slice and the predetermined slice code rate, so that each video slice reaches the fixed code rate, the fixed bits are distributed to each frame according to a preset rule, the video quality is optimal, and the effect of improving the video smoothness can be achieved through the stable and fixed slice code rate.
Optionally, when the video stream is an on-demand video stream, determining the target bitrate of the to-be-sent slice in the video stream includes:
and determining the target code rate of the slices to be sent according to the average code rate of the video slices in the historical video stream in the system, wherein the target code rates of all the slices to be sent in the video stream are the same.
In the above process, when a video is requested, the average bit rate of the video slice in the system data can be used as the bit rate of the slice in the video stream, so as to achieve the effect of constant bit rate of the video stream.
Optionally, when the video stream is a live video stream, determining the target bitrate of the to-be-sent slice in the video stream includes:
and determining the target code rate of the slice to be sent according to the average code rate of the video slice which is coded before the slice to be sent in the video stream.
In the above process, the target bitrate of the current slice is determined according to the average bitrate of the coded slice in the video stream, so that the bitrate of the current slice and the bitrate of the previous slice are smaller in amplitude, and the video playing process is smoother.
Optionally, the allocating target bits of the slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and encoding the slice to be sent according to the number of bits allocated to each frame in the slice to be sent to obtain an encoded slice to be sent, including:
and distributing target bits of the slice to be sent to each frame in the slice to be sent according to the weight occupation ratio of each frame in the slice to be sent, and coding the slice to be sent according to the number of bits distributed to each frame in the slice to be sent to obtain the coded slice to be sent, wherein the weight occupation ratio represents the importance degree of each frame in the slice to be sent.
In the process, the fixed bit number of each slice is distributed according to the weight percentage of each frame in the slice, and the video slice is coded according to the distributed bit number, so that the video slice can obtain stable code rate, and the video playing is smoother.
Optionally, before allocating target bits of a slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and encoding the slice to be sent according to the number of bits allocated to each frame in the slice to be sent to obtain an encoded slice to be sent, the method further includes;
and predicting the frames in the to-be-transmitted slice by utilizing a forward prediction algorithm to obtain a prediction result, wherein the prediction result comprises the type and the number of the frames in the to-be-transmitted slice.
In the above process, the type and number of frames in the slice can be predicted by a forward prediction algorithm, and the frames in the slice can be allocated with bits only when the type and number of frames in the slice are clear.
Optionally, the type of the frame includes at least one of the following frames:
the video slice coding method comprises the following steps of intra-frame coding frames, forward predictive coding frames, bidirectional difference frames and reference bidirectional difference frames, wherein the weight ratio of various frames in a video slice is sequentially reduced in the following sequence:
intra-coded frames, forward predictive coded frames, reference bidirectional difference frames, and bidirectional difference frames.
In the above process, according to the type of the frame and the weight ratio of each frame, the reasonable allocation of the corresponding bits can be realized.
Optionally, the forward predictive coding frame includes at least one of the following frames:
the method comprises the steps of encoding a common forward prediction encoding frame and a key forward prediction encoding frame, wherein the key forward prediction encoding frame is allocated to a larger number of bits than the forward prediction encoding frame and is used for encoding a video slice in a complex scene.
In the process, the forward predictive coding frames can be divided into common forward predictive coding frames and key forward predictive coding frames, and the common forward predictive coding frames and the key forward predictive coding frames respectively code video slices under different scenes, so that the video can be smoother.
Optionally, the target bits of the slice to be sent are allocated to each frame in the slice to be sent according to a preset allocation rule, and the allocation is implemented by the following method:
wherein, Tp represents the allocated bit number of the current frame, Ts represents the target bit, Rc represents the allocated bit number before the current frame, Ws represents the sum of the weights of all frames in the slice to be transmitted, Wc represents the sum of the weights of the frames encoded before the current frame, and Wp represents the weight of the current frame.
In the above process, the bit number required to be obtained by the current frame through allocation can be calculated according to the weight ratio of the weight of the current frame in the uncoded frame.
In a second aspect, an embodiment of the present application provides an apparatus for transmitting video, including:
the first determining module is used for determining the code rate of a slice to be sent in a video stream;
the second determining module is used for determining a target bit of a slice to be sent according to the code rate of the slice to be sent and the time length of the slice to be sent, wherein the time length of each slice to be sent in the video stream is the same;
the distribution module is used for distributing target bits of the slices to be sent to each frame in the slices to be sent according to a preset distribution rule, and coding the slices to be sent according to the number of bits distributed to each frame in the slices to be sent to obtain coded slices to be sent;
and the sending module is used for sending the coded slice to be sent to the terminal equipment.
Optionally, the first determining module is specifically configured to:
and when the video stream is the on-demand video stream, determining the target code rate of the to-be-sent slice according to the average code rate of the video slices in the historical video stream in the system, wherein the target code rates of all the to-be-sent slices in the video stream are the same.
Optionally, the first determining module is specifically configured to:
and when the video stream is a live video stream, determining a target code rate to be cut according to the average code rate of the video slice coded before the slice to be cut in the video stream.
Optionally, the allocation module is specifically configured to:
and distributing target bits of the slice to be sent to each frame in the slice to be sent according to the weight occupation ratio of each frame in the slice to be sent, and coding the slice to be sent according to the number of bits distributed to each frame in the slice to be sent to obtain the coded slice to be sent, wherein the weight occupation ratio represents the importance degree of each frame in the slice to be sent.
Optionally, the apparatus further comprises:
and the prediction module is used for predicting the frames in the slices to be sent by utilizing a forward prediction algorithm before the distribution module distributes the target bits of the slices to be sent to each frame in the slices to be sent according to a preset distribution rule, and codes the slices to be sent according to the number of bits distributed to each frame in the slices to be sent to obtain the coded slices to be sent, so as to obtain a prediction result, wherein the prediction result comprises the types and the number of the frames in the slices to be sent.
Optionally, the type of the frame includes at least one of the following frames:
the video slice coding method comprises the following steps of intra-frame coding frames, forward predictive coding frames, bidirectional difference frames and reference bidirectional difference frames, wherein the weight ratio of various frames in a video slice is sequentially reduced in the following sequence:
intra-coded frames, forward predictive coded frames, reference bidirectional difference frames, and bidirectional difference frames.
Optionally, the forward predictive coding frame includes at least one of:
the method comprises the steps of encoding a common forward prediction encoding frame and a key forward prediction encoding frame, wherein the key forward prediction encoding frame is allocated to a larger number of bits than the forward prediction encoding frame and is used for encoding a video slice in a complex scene.
Optionally, the allocating module allocates the target bits of the slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and the allocating module is implemented by the following method:
wherein, Tp represents the allocated bit number of the current frame, Ts represents the target bit, Rc represents the allocated bit number before the current frame, Ws represents the total weight of all frames in the slice to be transmitted, Wc represents the weight sum of the frames coded before the current frame, and Wp represents the weight occupied by the current frame.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method as provided in the first aspect are executed.
In a fourth aspect, embodiments of the present application provide a readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, performs the steps in the method as provided in the first aspect.
Additional features and advantages of the present application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the present application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
The method comprises the steps of accurately controlling the code rate of each video slice by controlling the bit allocation of each video slice, predicting the frame type composition of the slices through forward prediction according to the reference relation of the frames of various types in interframe prediction in the aspect of bit allocation, determining the frames of various types, using a code rate allocation method based on the frame types, performing corresponding bit allocation on the frames in the slices according to the frames of different types and the number, sending the coded slices to a client, and playing the slices only after the client completely downloads the slices.
However, in the currently used x264 and other encoders designed based on the application scenario of continuous code streams, the used code rate control method does not consider the situation that the video is divided, and lacks the slice-level code rate control, so that the generated slice code rate fluctuation is large, the judgment of the adaptive algorithm is inaccurate, and the jamming or bandwidth waste is easily generated in the practical application.
The bit allocation algorithm proposed herein for this purpose is performed at two levels, slice level and frame level, respectively. The code rate of a slice to be coded is determined preferentially, then the bit number to be distributed to the slice is determined according to the code rate of the slice and the set slice duration, the code rate of the video slice reaches the required code rate setting by distributing fixed bit number, and then the fixed bit number is distributed to each frame in the video slice according to the importance degree of each frame type in the slice, so that the quality of the video is optimal and the phenomenon of blocking does not occur.
A method for transmitting video according to an embodiment of the present application is described below with reference to fig. 1.
Referring to fig. 1, fig. 1 is a flowchart of a method for transmitting a video according to an embodiment of the present application, which is applied to a server, and the method for transmitting a video shown in fig. 1 includes:
110: and determining the code rate of the to-be-sent slice in the video stream.
In the process, after the code rate of the slice in the video stream is determined to meet the requirement, the video playing process can not be blocked.
The slice represents a group of frames forming a video slice, and is a processing unit with the largest code rate control, and in order to ensure the accuracy of client-side adaptive decision, ideally, the code rate of each slice should be the same as the set code rate in an M3U8 (index file) file. The slices are independent from each other, are independently coded, are simultaneously downloaded as independent units, and are different from progressive downloading, and the client can start playing the slices after completely downloading one video slice.
The code rate of the slice to be transmitted may be an average code rate of the code rates of the historical video slices in the system, or an average code rate of the coded slices in the current video stream.
In addition, the video stream may be an on-demand video stream or a live video stream.
Optionally, when the video stream is an on-demand video stream, determining the target bitrate of the to-be-sent slice in the video stream includes:
and determining the target code rate of the slices to be sent according to the average code rate of the video slices in the historical video stream in the system, wherein the target code rates of all the slices to be sent in the video stream are the same.
In the above process, when a video is requested, the average bit rate of the video slice in the system data can be used as the bit rate of the slice in the video stream, so as to achieve the effect of constant bit rate of the video stream.
The target code rates of all video slices in the video stream are constant, and the historical video stream in the system can be historical video data stored in a current server or video data stored in other servers.
Optionally, when the video stream is a live video stream, determining the target bitrate of the to-be-sent slice in the video stream includes:
and determining the target code rate of the slice to be sent according to the average code rate of the video slice which is coded before the slice to be sent in the video stream.
In the above process, the target bitrate of the current slice is determined according to the average bitrate of the coded slice in the video stream, so that the bitrate of the current slice and the bitrate of the previous slice are smaller in amplitude, and the video playing process is smoother.
120: and determining the target bit of the slice to be sent according to the code rate of the slice to be sent and the time length of the slice to be sent.
In the process, the fixed bit number allocated to each slice can be calculated through the slices with the predetermined code rate and the preset duration, so that each slice is allocated with a certain bit number, the control of the code rate at the slice level can be achieved, and the video is smoother.
Wherein the preset duration of each video slice is the same, and the duration of the slice is generally 2 seconds to 10 seconds, for example: for convenience of management, the time duration of all slices is set to a fixed time duration of 2 seconds. Because of the existence of slice independence, the bit allocation of each slice is also mutually independent, and the actual bit number of the previous slice does not affect the bit allocation of the current slice, therefore, after the target bit rate and the slice duration are determined, the target bit number of each slice is also determined, and is calculated by the following formula:
ts ═ Dur × R (where Dur denotes slice duration, R denotes target bitrate, and Ts denotes target number of bits).
Meanwhile, the number of frames contained in the slice can be calculated according to the frame rate and the slice duration.
Ns is Dur fps (where fps is the frame rate, i.e., the number of frames played per second, and Ns is the number of frames).
After the bit allocation of the frame is completed, allocating the bits of the next frame, and continuing to perform bit allocation on the frame in the next slice until the Ns frames are all allocated, which is not described herein repeatedly.
130: and distributing target bits of the slice to be sent to each frame in the slice to be sent according to a preset distribution rule, and coding the slice to be sent according to the number of bits distributed to each frame in the slice to be sent to obtain the coded slice to be sent.
In the process, the bits distributed to each slice in the step are distributed to each frame according to a preset distribution rule, so that each frame is distributed with a certain bit number, and the video slice is coded according to the distributed bit number, so that the quality of the video is optimal.
The preset allocation rule may be to allocate the target bits according to a weight ratio of each frame in the slice, where the weight ratio indicates an importance degree of the frame in the slice. The time domain correlation between frames is fully utilized, more bits are allocated to the frames with larger interframe prediction contribution, and the quality of the video is greatly improved. In addition, the following factors need to be considered when allocating bits: whether slices are independent and coded, the adaptive frame type selection strategy causes uncertainty in the proportion of P (predictive-frame) frames and B (Bi-directionally interpolated predictive frame) frames in the slices, and the complexity of images in different scenes is greatly different.
Optionally, the allocating target bits of the slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and encoding the slice to be sent according to the number of bits allocated to each frame in the slice to be sent to obtain an encoded slice to be sent, including:
and distributing target bits of the slice to be sent to each frame in the slice to be sent according to the weight occupation ratio of each frame in the slice to be sent, and coding the slice to be sent according to the number of bits distributed to each frame in the slice to be sent to obtain the coded slice to be sent, wherein the weight occupation ratio represents the importance degree of each frame in the slice to be sent.
In the process, the fixed bit number of each slice is distributed according to the weight percentage of each frame in the slice, and the video slice is coded according to the distributed bit number, so that the video slice can obtain stable code rate, and the video playing is smoother.
Wherein the weight ratio of each frame type in the slice is different. Under ideal conditions, a Variable Bit Rate (VBR) allocation mode can be used in a slice to allocate more bit rates to portions with high complexity and allocate less bit rates to portions with low complexity, that is, more bits can be allocated to frames with higher weight and less bits can be allocated to frames with lower weight, so that the quality of a video slice can be optimized.
Optionally, before allocating target bits of a slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and encoding the slice to be sent according to the number of bits allocated to each frame in the slice to be sent to obtain an encoded slice to be sent, the method shown in fig. 1 may further include;
and predicting the frames in the to-be-transmitted slice by utilizing a forward prediction algorithm to obtain a prediction result, wherein the prediction result comprises the type and the number of the frames in the to-be-transmitted slice.
In the above process, the type and number of frames in the slice can be predicted by a forward prediction algorithm, and the frames in the slice can be allocated with bits only when the type and number of frames in the slice are clear.
The forward prediction algorithm can predict the current frame according to the previous frame, and can also predict the current frame according to the next frame and the previous frame together.
Optionally, the type of the frame includes at least one of the following frames:
the video slice coding method comprises the following steps of intra-frame coding frames, forward predictive coding frames, bidirectional difference frames and reference bidirectional difference frames, wherein the weight ratio of various frames in a video slice is sequentially reduced in the following sequence:
intra-coded frames, forward predictive coded frames, reference bidirectional difference frames, and bidirectional difference frames.
In the above process, according to the type of the frame and the weight ratio of each frame, the reasonable allocation of the corresponding bits can be realized.
Among them, the x264 encoder mainly divides the frame into four types including: the intra-coded frame is also called I (intra picture) frame, which is usually the first frame (IDR frame) of each GOP (a video compression technique used by MPEG), and is moderately compressed, and serves as a reference point for random access and can be used as a picture. Forward predictive coded frames, also called P (predictive-frame) frames, compress coded pictures of the transmitted data volume by fully exploiting the temporal redundancy information of previously coded frames in the sequence of pictures, also called predictive frames; the difference between the frame and the previous key frame (or P frame) is shown, and the difference defined by the frame is superposed by the picture buffered before to generate the final picture when decoding. The Bi-directional differential frame is also called B (Bi-directional interpolated prediction frame), that is, the difference between the current frame and the previous and subsequent frames is recorded in the B frame, in other words, to decode the B frame, not only the previous buffered picture but also the decoded picture are obtained, and the final picture is obtained by the superposition of the previous and subsequent pictures and the current frame data. The reference bidirectional difference frame (B-ref) is a B frame of the reference frame, which also records the difference between the current frame and the previous and subsequent frames, and the bidirectional difference frame can be obtained by further prediction based on the reference bidirectional difference frame.
The reference relationship between the respective frames is exemplified below in conjunction with fig. 2.
Referring to fig. 2, fig. 2 is a schematic diagram of frame types and reference relationships thereof according to an embodiment of the present application:
wherein, I0 is the first frame, most images in the video can be compressed, decoding can be completed directly according to the data of the frame when decoding, P1 can compress the data according to the redundant information of I0, the difference defined by the frame needs to be superimposed on the picture buffered by I0 when decoding, generating the final picture, P5 can compress the data according to the redundant information of P1, the difference defined by the frame needs to be superimposed on the picture buffered before decoding, generating the final picture, B3 can compress the data according to the difference defined by the picture buffered by I0 and the frame and the superimposition of the difference information of B-ref2 and the frame, the final picture needs to be generated according to the data buffered by I0 and the superimposition of the difference between the two frames and the frame when decoding, B-ref2 can obtain the data of the frame according to the data buffered before and the superimposition of the differences between I0 and P1 and the data of the frame, similarly, B4 may also obtain the data of the frame directly according to the data that has been buffered before and the superposition of the difference between B-ref2 and the frame, B7 may obtain the data of the frame according to the data that has been buffered before and the superposition of the difference between P1 and B-ref6 and the data of the frame, B-ref6 may obtain the data of the frame according to the data that has been buffered before and the superposition of the difference between P1 and P5 and the data of the frame, B8 may obtain the data of the frame according to the data that has been buffered before and the superposition of the difference between B-ref6 and P5 and the data of the frame, and the like, which is not described herein again.
Optionally, the forward predictive coding frame includes at least one of the following frames:
the method comprises the steps of encoding a common forward prediction encoding frame and a key forward prediction encoding frame, wherein the key forward prediction encoding frame is allocated to a larger number of bits than the forward prediction encoding frame and is used for encoding a video slice in a complex scene.
In the process, the forward predictive coding frames can be divided into common forward predictive coding frames and key forward predictive coding frames, and the common forward predictive coding frames and the key forward predictive coding frames respectively code video slices under different scenes, so that the video can be smoother.
Wherein, the key forward predictive coding frame (P-specific) is allocated with a larger number of bits than the forward predictive coding frame, which is used for coding the video slice in the complex scene.
The values of the different frame types provided in the embodiment of the present application are described in detail below with reference to fig. 3.
Referring to fig. 3, fig. 3 is a table corresponding to weights of various types of frames according to an embodiment of the present application:
wherein the frame packets of different types: intra-coded frames (I-frames), key forward predictive coded frames (P-specific frames), forward predictive coded frames (P-frames), reference bidirectional difference frames (B-ref frames), and bidirectional difference frames (B-frames), corresponding to weights 130, 80, 40, 5, and 3, respectively.
In the process, each frame in each slice can be allocated with bits according to the corresponding weight ratio, so that the quality of the video is optimal, and the phenomenon of blocking is reduced.
Optionally, the target bits of the slice to be sent are allocated to each frame in the slice to be sent according to a preset allocation rule, and the allocation is implemented by the following method:
wherein, Tp represents the allocated bit number of the current frame, Ts represents the target bit, Rc represents the allocated bit number before the current frame, Ws represents the sum of the weights of all frames in the slice to be transmitted, Wc represents the sum of the weights of the frames encoded before the current frame, and Wp represents the weight of the current frame.
In the above process, the bit number required to be obtained by the current frame through allocation can be calculated according to the weight ratio of the weight of the current frame in the uncoded frame.
140: and sending the coded slice to be sent to the terminal equipment.
In the process, the set slice with the fixed code rate is sent to the terminal, and the terminal can sequentially download and decode the corresponding video slices and finally realize the playing of the video.
A method for transmitting video according to an embodiment of the present application is described in detail below with reference to fig. 4.
Referring to fig. 4, fig. 4 is a detailed flowchart of a method for transmitting a video according to an embodiment of the present application, applied to a server, where the method for transmitting a video shown in fig. 4 includes:
410: slice bit allocation.
The allocation of bits is preferentially done for video slices, where each video slice is allocated a fixed number of bits.
By allocating a fixed number of bits to a video slice, the bitrate of the video slice can be controlled.
420: frame level bit allocation.
And distributing the target bits to each frame according to the weight ratio of each frame, so that each frame obtains a corresponding number of bits according to the importance degree of each frame data.
430: and controlling the code rate at a frame level.
The bit allocation of each frame realizes the code rate control of each frame, and the quality of the video is optimal.
440: and updating the residual weight value.
Before the bit allocation is carried out on the next frame, the total weight corresponding to the rest frames is updated to be used as the reference total weight of the next frame, and the next frame carries out the corresponding bit allocation according to the weight ratio corresponding to the current total weight.
450: it is determined whether it is the last frame.
If not, the bits are allocated to the next frame, and if the last frame, the bits are allocated to each frame in the next slice.
460: it is determined whether it is the last slice.
If the slice is not the last slice, the bit allocation is carried out on each frame of the next slice, if the slice is the last slice, the bit allocation is finished, and the code rate control of each video slice and each frame in the slice is realized.
The method of transmitting video is described above with reference to fig. 1 to 4, and the apparatus for transmitting video is described below with reference to fig. 5 to 6.
Referring to fig. 5, a schematic block diagram of an apparatus 500 for transmitting video provided in the embodiment of the present application is shown, where the apparatus 500 may be a module, a program segment, or code on an electronic device. The apparatus 500 corresponds to the above-mentioned embodiment of the method of fig. 1, and can perform various steps related to the embodiment of the method of fig. 1, and specific functions of the apparatus 500 can be referred to the following description, and detailed descriptions are appropriately omitted herein to avoid redundancy.
Optionally, the apparatus 500 includes:
a first determining module 510, configured to determine a bitrate of a slice to be sent in a video stream;
a second determining module 520, configured to determine a target bit of a slice to be sent according to a code rate of the slice to be sent and a duration of the slice to be sent, where durations of the slices to be sent in the video stream are the same;
the allocating module 530 is configured to allocate target bits of a slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and encode the slice to be sent according to a number of bits allocated to each frame in the slice to be sent, so as to obtain an encoded slice to be sent;
a sending module 540, configured to send the encoded slice to be sent to the terminal device.
Optionally, the first determining module is specifically configured to:
and when the video stream is the on-demand video stream, determining the target code rate of the to-be-sent slice according to the average code rate of the video slices in the historical video stream in the system, wherein the target code rates of all the to-be-sent slices in the video stream are the same.
Optionally, the first determining module is specifically used for
And when the video stream is a live video stream, determining a target code rate to be cut according to the average code rate of the video slice coded before the slice to be cut in the video stream.
Optionally, the allocation module is specifically configured to:
and distributing target bits of the slice to be sent to each frame in the slice to be sent according to the weight occupation ratio of each frame in the slice to be sent, and coding the slice to be sent according to the number of bits distributed to each frame in the slice to be sent to obtain the coded slice to be sent, wherein the weight occupation ratio represents the importance degree of each frame in the slice to be sent.
Optionally, the apparatus further comprises:
and the prediction module is used for predicting the frames in the slices to be sent by utilizing a forward prediction algorithm before the distribution module distributes the target bits of the slices to be sent to each frame in the slices to be sent according to a preset distribution rule, and codes the slices to be sent according to the number of bits distributed to each frame in the slices to be sent to obtain the coded slices to be sent, so as to obtain a prediction result, wherein the prediction result comprises the types and the number of the frames in the slices to be sent.
Optionally, the type of the frame includes at least one of the following frames:
the video slice coding method comprises the following steps of intra-frame coding frames, forward predictive coding frames, bidirectional difference frames and reference bidirectional difference frames, wherein the weight ratio of various frames in a video slice is sequentially reduced in the following sequence:
intra-coded frames, forward predictive coded frames, reference bidirectional difference frames, and bidirectional difference frames.
Optionally, the forward predictive coding frame includes at least one of:
the method comprises the steps of encoding a common forward prediction encoding frame and a key forward prediction encoding frame, wherein the key forward prediction encoding frame is allocated to a larger number of bits than the forward prediction encoding frame and is used for encoding a video slice in a complex scene.
Optionally, the allocating module allocates the target bits of the slice to be sent to each frame in the slice to be sent according to a preset allocation rule, and the allocating module is implemented by the following method:
wherein, Tp represents the allocated bit number of the current frame, Ts represents the target bit, Rc represents the allocated bit number before the current frame, Ws represents the total weight of all frames in the slice to be transmitted, Wc represents the weight sum of the frames coded before the current frame, and Wp represents the weight occupied by the current frame.
Referring to fig. 6, a schematic block diagram of a structure of an apparatus 600 for transmitting video provided in an embodiment of the present application is shown, where the apparatus may include a processor 620 and a memory 610. Optionally, the apparatus may further include: a communication interface 630, and a communication bus 640. The apparatus corresponds to the above-mentioned embodiment of the method of fig. 1, and can perform various steps related to the embodiment of the method of fig. 1, and specific functions of the apparatus can be referred to the following description.
In particular, memory 610 is used to store computer readable instructions.
Processor 620, for processing the readable instructions stored by the memory, is capable of performing the steps of embodiments 110 through 140 of the method of fig. 1.
A communication interface 630 is used for communicating signaling or data with other node devices. For example: the method and the device for communication with the server or the terminal, or with other device nodes are used, and the embodiments of the application are not limited thereto.
And a communication bus 640 for realizing direct connection communication of the above components.
In this embodiment, the communication interface 630 of the device in this application is used for performing signaling or data communication with other node devices. The memory 610 may be a high-speed RAM memory or a non-volatile memory (e.g., at least one disk memory). The memory 610 may optionally be at least one memory device located remotely from the processor. The memory 610 stores computer readable instructions, which when executed by the processor 620, cause the electronic device to perform the method processes described above with reference to fig. 1. A processor 620 may be used on the apparatus 500 and to perform the functions herein. The Processor 620 may be, for example, a general-purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component, and the embodiments of the present Application are not limited thereto.
Embodiments of the present application further provide a readable storage medium, and when being executed by a processor, the computer program performs a method process performed by an electronic device in the method embodiment shown in fig. 1.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method, and will not be described in too much detail herein.
In summary, the present application provides a method, an apparatus, an electronic device, and a readable storage medium for transmitting a video, where the method determines a code rate of a slice to be transmitted in a video stream; determining target bits of slices to be sent according to the code rate of the slices to be sent and the time length of the slices to be sent, wherein the time length of each slice to be sent in a video stream is the same; distributing target bits of the slices to be sent to each frame in the slices to be sent according to a preset distribution rule, and coding the slices to be sent according to the number of bits distributed to each frame in the slices to be sent to obtain coded slices to be sent; and sending the coded slice to be sent to the terminal equipment. The method can achieve the effect of improving the video fluency.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.