Detailed Description
Embodiments of the present application will be described in further detail below with reference to the drawings and examples. It should be understood that the particular embodiments described herein are illustrative only and are not limiting of embodiments of the application. It should be further noted that, for convenience of description, only some, but not all of the structures related to the embodiments of the present application are shown in the drawings.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged, as appropriate, such that embodiments of the present application may be implemented in sequences other than those illustrated or described herein, and that the objects identified by "first," "second," etc. are generally of a type, and are not limited to the number of objects, such as the first object may be one or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
The video coding method provided by the embodiment of the application can be executed by computing equipment such as a server, a smart phone, a tablet computer, a notebook computer and the like. The method can be applied to scenes needing to encode the video stream, such as video encoding processing of live video stream, video encoding processing of recorded video, and the like.
Fig. 1 is a flowchart of a video encoding method according to an embodiment of the present application, as shown in fig. 1, specifically including the following steps:
step S101, a video frame sequence to be encoded is obtained, and the motion type of a video frame in the video frame sequence is determined.
Wherein the sequence of video frames is a sequence of a plurality of consecutive video frames. And when video coding is carried out, acquiring the video frame sequence, and determining a corresponding video coding mode based on the motion condition of the video frames in the video frame sequence.
Wherein the motion type of the video frame characterizes the relative motion condition of the video frame. Alternatively, it may be classified into a stationary type, a slow motion type, and a fast motion type. Wherein the still type characterizes the video frame as relatively still, the slow motion type characterizes the video frame as relatively slow motion, and the fast motion type characterizes the video frame as relatively fast motion.
Step S102, carrying out sub-pixel search on the video frame under the preset duration based on a first preset algorithm under the condition that the motion type of the video frame is a static type.
In one embodiment, when determining a motion type of a video frame of a video sequence, if the motion type of the video frame in the video sequence is a still type, a sub-pixel search is performed on the video frame under a preset duration based on a first preset algorithm. Alternatively, the motion type of the video frames in the video sequence may be a still type, and the plurality of consecutive video frames in the video sequence for a predetermined duration may be still types. If a certain video frame is determined to be of a still type in the video sequence, the video frame in 2 seconds is started to be of the still type.
Wherein the first predetermined algorithm is less complex than the standard encoding algorithm. Alternatively, the first preset algorithm for performing the video frame sub-pixel search may be a bilinear interpolation algorithm, and the standard encoding algorithm may be a 6-tap interpolation algorithm. In the video coding process, the video sampled by various modes does not contain sub-pixels, and the sub-pixels can be obtained by a certain interpolation calculation of the whole pixels. Therefore, between the whole-pixel motion estimation and the sub-pixel motion estimation, interpolation calculation of sub-pixels is required in the search range of the reference frame image. In the calculation process, a first preset algorithm is adopted for calculating and processing the video frames of the static type under the continuous preset duration in the video frame sequence.
Step S103, skipping sub-pixel searching and sub-pixel reference information generation for the video frame after the preset duration, and carrying out video frame coding based on the gradually increased minimum quantization parameter value.
In one embodiment, in the case that the motion type of the video frame is determined to be a still type, the sub-pixel search and the generation of sub-pixel reference information are skipped for the video frame after the preset duration. The sub-pixel reference information is information which needs to be calculated in the video coding processing process and needs to be referred to when coding other video frames aiming at the current frame. At this time, under the condition of meeting the static type, the sub-pixel search is skipped for the video frame after the preset duration, and the generation of sub-pixel reference information is performed to optimize the video coding. For example, when a video frame sequence including 45 frames of images is determined that the corresponding video frames are of a still type (e.g., from the 0 th frame image to the 40 th frame image) under a continuous preset duration, the 0 th frame image to the 40 th frame image adopt a first preset algorithm to perform a sub-pixel search, and for the video frames of the still type after the preset duration, such as the 41 st frame image, the 42 th frame image and the 43 rd frame image, the sub-pixel search and the generation of sub-pixel reference information are skipped, and video frame coding is performed based on the gradually increased minimum quantization parameter values.
The quantization parameter is a parameter reflecting the compression condition of space details in the video coding process. The smaller the quantization parameter value, the finer the quantization, the higher the image quality, and the longer the resulting code stream. If the quantization parameter value is small, most of details in the video image are preserved; the quantization parameter value is increased, some details in the video image are lost, the code rate is reduced, and the image distortion strengthening quality is reduced. Illustratively, when the quantization parameter value takes a minimum value of 0, according to the default settings of the encoder, it indicates that quantization is the finest; conversely, when the quantization parameter value takes the maximum value 51, it indicates that quantization is the coarsest. In one embodiment, video frames of still type after a preset period are encoded based on progressively increasing minimum quantization parameter values while skipping sub-pixel searching and generation of sub-pixel reference information. Alternatively, the minimum quantization parameter value may be exemplified in an increasing manner by: and when each frame is coded, sequentially increasing the minimum quantization parameter value by a preset value, and then carrying out video coding on the corresponding video frame. The preset size value may be 1, for example. In one embodiment, the upper limit value for the increase in the minimum quantization parameter value may be set accordingly, and the increase may not be performed after the increase.
In one embodiment, for a video frame in a sequence of video frames to be encoded, if it is determined that the motion type of the video frame in the sequence of video frames is a fast motion type, the minimum quantization parameter value of the original size is restored and video encoding of the video frame is performed based thereon.
According to the method, a video frame sequence to be encoded is obtained, the motion type of the video frames in the video frame sequence is determined, under the condition that the motion type meets the static encoding condition, sub-pixel searching is conducted on the video frames under the preset duration based on a first preset algorithm, wherein the complexity of the first preset algorithm is lower than that of a standard encoding algorithm, the sub-pixel searching and generation of sub-pixel reference information are skipped on the video frames after the preset duration, and video frame encoding is conducted based on gradually increased quantization parameter values. According to the scheme, under the condition that the video frame is relatively static, a low-complexity coding algorithm is adopted, and meanwhile, part of coding flow is skipped, so that the coding efficiency is remarkably improved under the condition that the video coding quality is guaranteed.
Based on the technical scheme, the method further comprises the following steps: selecting a skip mode frame for the video frames after the preset duration; and adopting a preset skip mode to carry out video coding of the skip mode frame. That is, for a still type video frame in a video sequence, for a still type video frame after a preset time period, skipping sub-pixel searching and generating sub-pixel reference information, and for a selected skip mode frame, performing video encoding of the skip mode frame by adopting a preset skip mode. The mode of selecting the skip mode frame may be to randomly select an odd frame or an even frame among the still type video frames or select the odd frame or the even frame as the skip mode frame. The preset skip mode may be a skip mode set by the encoder itself in a design process, and the skip mode is defined in a video coding standard. The preset Skip mode may be a Skip mode defined in the HEVC coding standard, for example. By using the skip mode, a great amount of encoding time is saved, and a great amount of bit rate is saved, so that the video encoding efficiency is further improved.
Fig. 2 is a flowchart of another video encoding method according to an embodiment of the present application, and as shown in fig. 2, a method for determining a video frame type is provided, where the method includes:
step 201, a video frame sequence to be encoded is obtained, and the motion type of the video frame is determined based on the row encoding cost and the column encoding cost of the encoding block in the video frame.
In one embodiment, when determining the motion type of a video frame, the motion type of the video frame is determined based on the row encoding cost and the column encoding cost of the encoded blocks in the video frame. The coding blocks are independent coding units for dividing video frame images in the video coding process, and one video frame image can be divided into a plurality of rows and a plurality of columns of coding blocks. The motion type of the encoded block in the video frame is determined by acquiring a row encoding cost and a column encoding cost determination. Optionally, the row coding cost and the column coding cost of the coding block are calculated and stored correspondingly in the preprocessing process of video coding, and can be directly obtained here.
In one embodiment, different determination approaches are employed in determining the type of motion for different types of video frames. Optionally, as shown in fig. 3, fig. 3 is a flowchart of a method for determining a motion type of a P-frame image according to an embodiment of the present application, which specifically includes:
in step S2011, in the case that the video frame is a P-frame image, the line coding costs of each line of the P-frame image and the column coding costs of the middle column are obtained.
Step 2012, comparing the row coding cost and the column coding cost of each row with the corresponding first price threshold value, and determining whether the P frame image is of a static type according to the comparison result.
In one embodiment, for a P-frame image, a row coding cost of each row of the P-frame image and a column coding cost of an intermediate column are obtained, where in the case where there are two columns in the intermediate column, one of the columns may be selected as the intermediate column at random or according to a set selection manner.
Exemplary, as shown in the following table:
inter-11
|
inter-12
|
…
|
…
|
inter-1n
|
inter-21
|
inter-22
|
…
|
…
|
inter-2n
|
…
|
…
|
…
|
…
|
…
|
inter-m1
|
inter-m2
|
…
|
…
|
inter-mn |
the P frame image is divided into m rows and n columns, the exemplary labels of the coding blocks are shown in the table above, the coding cost of the coding blocks of the first row and the first column is marked as inter-00, the coding cost of the second column and the first row is marked as inter-01, the coding cost of the first column and the second row is marked as inter-10, and the like.
When calculating the line coding cost, the sum of the coding costs of the coding blocks of the line is calculated as the line coding cost of the line (the value range of x is 0 m in an exemplary way denoted as an inter-rx), and the coding cost of the middle column is the corresponding coding block of the middle column and then is used as the column coding cost (the value range of x is 0 m in an exemplary way denoted as an inter-c).
Optionally, when determining the motion type of the video frame, it includes determining whether it is a stationary type, a slow motion type, and in the case that it is neither a stationary type nor a slow motion type, determining that it is a fast motion type. And when determining whether the P-frame image is of a static type, comparing the P-frame image with a first price threshold value which is correspondingly set according to the row coding cost and the column coding cost of each row, and determining whether the P-frame image is of the static type according to the comparison result. The first price threshold may be a fixed value or a value calculated based on different numbers of rows and columns. Alternatively, for a row coding cost, the aligned threshold may be denoted as n×th1_still, and for a column coding cost, the aligned threshold may be denoted as m×th1_still. Alternatively, the judgment method may be that the inter-rx < n×th1_still, and the inter-c < m×th1_still determines that the P frame picture is of STILL type. By the method for determining the motion type of the video frame based on the coding cost, the motion type of the video frame can be determined rapidly, complex calculation and comparison processes are not needed, and the determination speed of the motion type can be improved remarkably.
Optionally, for the case that the video frame is an I-frame image, the manner of determining the motion type of the video frame is shown in fig. 4, and fig. 4 is a flowchart of a method for determining the motion type of the I-frame image according to an embodiment of the present application, where the method includes:
in step S2013, in the case that the video frame is an I-frame image, the line coding costs of each line of the I-frame image and the column coding costs of the middle column are obtained.
Step S2014, acquiring the row coding cost of each row of the previous frame image of the I frame image, and the column coding cost of the middle column.
Step S2015, determining whether the I-frame image is of a still type based on the line coding cost and the column coding cost of each line of the I-frame image, and the line coding cost and the column coding cost of each line of the previous frame image.
In one embodiment, when the video frame is an I frame image and the previous frame is a P frame image and is of a still type, when acquiring the line coding cost of each line of the I frame image and the column coding cost of the middle column, the corresponding acquiring the line coding cost of each line of the previous frame image and the column coding cost of the middle column of the I frame image determines whether the I frame image is of the still type by comparing the line coding cost and the column coding cost of each line of the I frame image and the line coding cost and the column coding cost of each line of the previous frame image.
Alternatively, the manner of determining whether the I-frame image is of the STILL type may be to determine whether the absolute value of the difference between each line coding cost of the I-frame image and the corresponding line coding cost of the previous frame image is smaller than a first absolute threshold, which may be denoted as n×th2_still, and whether the absolute value of the difference between the column coding cost of the I-frame image and the column coding cost of the previous frame image is smaller than a second absolute threshold, which may be denoted as m×th2_still, respectively. And determining that the I frame image is of a static type when the absolute value of the difference between each row coding cost of the I frame image and the corresponding row coding cost of the previous frame image is smaller than a first absolute threshold and the absolute value of the difference between the column coding cost of the I frame image and the column coding cost of the previous frame image is smaller than a second absolute threshold.
Alternatively, in determining whether the video frame is of the slow motion type, it may be: and determining that the video frame is of a slow motion type under the condition that any line of line coding cost in the video frame is larger than a second cost threshold and smaller than a third cost threshold and other line coding cost is smaller than a first cost threshold. I.e. when there are some or several lines whose line coding cost is greater than the second cost threshold and less than the third cost threshold, it is determined that it is of slow motion type. Wherein the second cost threshold is greater than or equal to the first cost threshold and the third cost threshold is greater than the second cost threshold. Alternatively, a line is determined to be a fast motion type when there is a line coding cost for that line that is greater than a third rate threshold.
Step S202, carrying out sub-pixel search on the video frame under the preset duration based on a first preset algorithm under the condition that the motion type of the video frame is a static type.
Step 203, skipping sub-pixel searching and sub-pixel reference information generation for the video frame after the preset duration, and performing video frame encoding based on the gradually increased minimum quantization parameter value.
According to the method, a video frame sequence to be encoded is obtained, the motion type of the video frames in the video frame sequence is determined, under the condition that the motion type meets the static encoding condition, sub-pixel searching is conducted on the video frames under the preset duration based on a first preset algorithm, wherein the complexity of the first preset algorithm is lower than that of a standard encoding algorithm, the sub-pixel searching and generation of sub-pixel reference information are skipped on the video frames after the preset duration, and video frame encoding is conducted based on gradually increased quantization parameter values. According to the scheme, under the condition that the video frame is relatively static, a low-complexity coding algorithm is adopted, and meanwhile, part of coding flow is skipped, so that the coding efficiency is remarkably improved under the condition that the video coding quality is guaranteed.
Fig. 5 is a flowchart of another video encoding method according to an embodiment of the present application, as shown in fig. 5, including:
step 301, a video frame sequence to be encoded is obtained, and the motion type of a video frame in the video frame sequence is determined.
Step S302, performing sub-pixel search on the video frame under the preset duration based on a first preset algorithm under the condition that the motion type of the video frame is a still type.
Step S303, skipping sub-pixel searching and sub-pixel reference information generation for the video frame after the preset duration, and performing video frame coding based on the gradually increased minimum quantization parameter value.
Step S304, under the condition that the motion type of the video frame is a slow motion frame type, carrying out sub-pixel search on the video frame of the slow motion frame type based on a first preset algorithm.
Step S305, determining an algorithm adopted by the video frame of the next slow motion frame type based on the set feedback frame, and performing a sub-pixel search based on the determined algorithm.
In one embodiment, for a video frame of a slow motion frame type, a sub-pixel search is performed on the video frame of the slow motion frame type based on a first preset algorithm, while an algorithm adopted by a video frame of a next slow motion frame type is determined by using a set feedback frame, such as adopting the first preset algorithm or a standard coding algorithm, and the sub-pixel search is performed based on the determined algorithm.
Alternatively, the process of determining the algorithm to be adopted by the video frame of the next slow motion frame type based on the set feedback frame may be: acquiring the actual coding cost of the recorded video frame of the current slow motion frame type, and determining that the video frame of the next slow motion frame type uses a standard coding algorithm under the condition that the actual coding cost is larger than a preset cost threshold. The coding quality is measured by comparing the actual coding cost with a preset cost threshold, if the actual coding cost is larger than the preset cost threshold, the video frame of the next slow motion frame type adopts a standard coding algorithm to carry out sub-pixel searching, otherwise, the first preset algorithm is continuously used for carrying out sub-pixel searching. The preset cost threshold value can be adaptively set according to actual requirements. By setting a feedback frame form to compare the actual coding cost with a preset cost threshold, adaptive algorithm switching can be realized, and proper algorithms are selected for different actual coding conditions to perform sub-pixel searching, so that coding quality is ensured and coding efficiency is improved.
Optionally, the video frame of the fast motion type is encoded by adopting an original set manner of an encoder, for example, a standard encoding algorithm and a default minimum quantization parameter value are adopted for video encoding.
According to the method, a video frame sequence to be encoded is obtained, the motion type of the video frames in the video frame sequence is determined, under the condition that the motion type meets the static encoding condition, sub-pixel searching is conducted on the video frames under the preset duration based on a first preset algorithm, wherein the complexity of the first preset algorithm is lower than that of a standard encoding algorithm, the sub-pixel searching and generation of sub-pixel reference information are skipped on the video frames after the preset duration, and video frame encoding is conducted based on gradually increased quantization parameter values. According to the scheme, under the condition that the video frame is relatively static, a low-complexity coding algorithm is adopted, and meanwhile, part of coding flow is skipped, so that the coding efficiency is remarkably improved under the condition that the video coding quality is guaranteed.
Fig. 6 is a block diagram of a video encoding apparatus according to an embodiment of the present application, and as shown in fig. 6, the apparatus is configured to execute the video encoding method according to the foregoing embodiment, and has functional modules and beneficial effects corresponding to the execution method. As shown in fig. 6, the apparatus specifically includes: a type determination module 101, a pixel search module 102, an encoding configuration module 103, and an encoding processing module 104, wherein,
the type determining module 101 is configured to acquire a video frame sequence to be encoded and determine the motion type of a video frame in the video frame sequence;
the pixel searching module 102 is configured to perform sub-pixel searching on the video frame under the preset duration based on a first preset algorithm under the condition that the motion type of the video frame is a static type, wherein the complexity of the first preset algorithm is lower than that of a standard encoding algorithm;
the encoding configuration module 103 is configured to skip sub-pixel searching and sub-pixel reference information generation for the video frame after the preset duration;
the encoding processing module 104 is configured to encode the video frame based on the gradually increasing minimum quantization parameter value.
According to the method, a video frame sequence to be encoded is obtained, the motion type of the video frames in the video frame sequence is determined, under the condition that the motion type meets the static encoding condition, sub-pixel searching is conducted on the video frames under the preset duration based on a first preset algorithm, wherein the complexity of the first preset algorithm is lower than that of a standard encoding algorithm, the sub-pixel searching and generation of sub-pixel reference information are skipped on the video frames after the preset duration, and video frame encoding is conducted based on gradually increased quantization parameter values. According to the scheme, under the condition that the video frame is relatively static, a low-complexity coding algorithm is adopted, and meanwhile, part of coding flow is skipped, so that the coding efficiency is remarkably improved under the condition that the video coding quality is guaranteed.
In a possible embodiment, the type determining module 101 is specifically configured to:
and determining the motion type of the video frame based on the row coding cost and the column coding cost of the coding block in the video frame.
In a possible embodiment, the type determining module 101 is specifically configured to:
acquiring row coding cost of each row of the P frame image and column coding cost of a middle column under the condition that the video frame is the P frame image;
and comparing the row coding cost and the column coding cost of each row with a first price threshold value which is correspondingly set, and determining whether the P frame image is of a static type according to the comparison result.
In a possible embodiment, the type determining module 101 is specifically configured to:
acquiring row coding cost of each row of the I frame image and column coding cost of a middle column under the condition that the video frame is the I frame image;
acquiring the row coding cost of each row of a previous frame image of the I frame image and the column coding cost of a middle column;
and determining whether the I frame image is of a static type based on the row coding cost and the column coding cost of each row of the I frame image and the row coding cost and the column coding cost of each row of the previous frame image.
In a possible embodiment, the type determining module 101 is specifically configured to:
and determining that the video frame is of a slow motion type under the condition that any line coding cost is larger than a second cost threshold and smaller than a third cost threshold and other line coding costs are smaller than a first cost threshold in the video frame.
In one possible embodiment, the pixel search module 102 is further configured to:
under the condition that the motion type of the video frame is a slow motion frame type, carrying out sub-pixel search on the video frame of the slow motion frame type based on the first preset algorithm;
and determining an algorithm adopted by a video frame of the next slow motion frame type based on the set feedback frame, and carrying out sub-pixel searching based on the determined algorithm.
In one possible embodiment, the pixel search module 102 is further configured to:
acquiring the actual coding cost of the recorded video frame of the current slow motion frame type;
and under the condition that the actual coding cost is larger than a preset cost threshold value, determining the video frame of the next slow motion frame type to use a standard coding algorithm.
In one possible embodiment, the encoding processing module 104 is configured to:
and when each frame is coded, sequentially increasing the minimum quantization parameter value by a preset value, and then carrying out video coding on the corresponding video frame.
In one possible embodiment, the encoding processing module 104 is further configured to:
after the minimum quantization parameter value is increased by a preset value in sequence and video coding of the corresponding video frame is carried out, the minimum quantization parameter value with the original size is restored under the condition that the motion type of the video frame in the video frame sequence is determined to be the rapid motion type, so that video coding of the video frame is carried out.
In a possible embodiment, the encoding configuration module 103 is further configured to:
selecting a skip mode frame for the video frames after the preset duration;
the encoding processing module 104 is configured to:
and adopting a preset skip mode to carry out video coding of the skip mode frame.
Fig. 7 is a schematic structural diagram of a video encoding apparatus according to an embodiment of the present application, and as shown in fig. 7, the apparatus includes a processor 201, a memory 202, an input device 203, and an output device 204; the number of processors 201 in the device may be one or more, one processor 201 being taken as an example in fig. 7; the processor 201, memory 202, input devices 203, and output devices 204 in the apparatus may be connected by a bus or other means, for example in fig. 7. The memory 202 is a computer readable storage medium, and may be used to store software programs, computer executable programs, and modules, such as program instructions/modules corresponding to the video encoding method in the embodiments of the present application. The processor 201 executes various functional applications of the device and data processing, i.e., implements the video encoding method described above, by running software programs, instructions, and modules stored in the memory 202. The input device 703 may be used to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the apparatus. The output device 204 may include a display device such as a display screen.
Embodiments of the present application also provide a non-volatile storage medium containing computer-executable instructions, which when executed by a computer processor, are configured to perform a video encoding method as described in one of the above embodiments, comprising:
acquiring a video frame sequence to be encoded, and determining the motion type of a video frame in the video frame sequence;
under the condition that the motion type of the video frame is a static type, carrying out sub-pixel search on the video frame under the preset duration based on a first preset algorithm, wherein the complexity of the first preset algorithm is lower than that of a standard coding algorithm;
and skipping sub-pixel searching and sub-pixel reference information generation for the video frames after the preset duration, and carrying out video frame coding based on the gradually increased minimum quantization parameter values.
It should be noted that, in the embodiment of the video encoding apparatus, each unit and module included are only divided according to the functional logic, but not limited to the above-mentioned division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the embodiments of the present application.
In some possible embodiments, aspects of the method provided by the present application may also be implemented in the form of a program product, which includes a program code for causing a computer device to perform the steps of the method according to the various exemplary embodiments of the application described in the present specification, when the program product is run on the computer device, for example, the computer device may perform the video encoding method described in the embodiments of the present application. The program product may be implemented using any combination of one or more readable media.