Video transcoding method, device, storage medium and electronic device
Process the transcoding feature information of the video through the prediction model, select appropriate transcoding parameters for CRF transcoding, solve the problems of bit rate waste and low bandwidth utilization in the existing technology, and achieve efficient and accurate bit rate of video encoding. manage.
Patent Information
- Application Number
- CN202410978843.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-22
AI Technical Summary
Existing video encoding technology is difficult to avoid wasting bit rates while ensuring image quality. Especially when the scene complexity changes, it is impossible to efficiently and accurately obtain the average bit rate of the video after transcoding with a specified bit rate factor, resulting in network transmission and bandwidth The utilization rate is not high.
By predicting the average bit rate under different transcoding parameters in advance, select appropriate transcoding parameters for final CRF transcoding, use peak signal-to-noise ratio, structural similarity index and code stream byte number to determine the target video sub-segment, and apply the prediction model Process transcoding feature information to select the most appropriate transcoding parameters to ensure video quality and bandwidth requirements.
It achieves efficient and accurate selection of appropriate transcoding parameters while ensuring video quality, avoiding bit rate waste, meeting bandwidth requirements, and improving the efficiency of video coding engineering applications.
Smart Images

Figure CN118524222B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image data processing, and in particular to a video transcoding method, device, storage medium and electronic equipment. Background Art
[0002] From the perspective of bit rate control, common video compression coding can be divided into CBR (Constant Bitrate), CQP (Constant Quantizer Parameter), ABR (Average Bitrate), CRF (Constant Rate Factor), etc. Different coding control strategies are suitable for different application scenarios.
[0003] When encoding offline video on demand, if ABR or CBR is used to encode a video at a constant bit rate, this encoding method is relatively friendly to network transmission, but it cannot guarantee the continuity of the video quality experience, nor can it avoid bit rate waste. For example, for complex scene clips, if the specified target bit rate is insufficient, the image quality will be significantly reduced; for simple scene clips, if the specified target bit rate is too high, there will be bit rate waste. A video is often composed of many scenes of different complexity, and a single constant bit rate is difficult to meet the needs of all scenes at the same time.
[0004] The goal of constant rate factor coding (CRF) is to ensure the picture quality experience while avoiding bit rate waste. By setting a rate factor value for the target quality, when the scene is simple, only a lower bit rate is used to achieve the target quality. When the scene is complex, more bit rate is allocated to ensure the picture quality. When the rate factor used for encoding is small and the scene complexity is high, the average bit rate of the output file may exceed expectations, putting pressure on network transmission and bandwidth costs. When the rate factor used for encoding is large and the scene complexity is average or simple, the image quality of the output file is insufficient and the bandwidth utilization is not high. How to efficiently and accurately obtain the average bit rate of the video after transcoding at a specified rate factor is a problem that CRF coding hopes to solve in engineering applications. Summary of the invention
[0005] In view of this, the present invention provides a video transcoding method, device, storage medium and electronic device. Through the method, the average bit rate under different transcoding parameters can be predicted in advance, and the transcoding parameters corresponding to the appropriate average bit rate can be selected from each average bit rate to perform the final CRF transcoding on the video, thereby ensuring the video quality while also ensuring that the bandwidth requirements are met.
[0006] A video transcoding method, comprising:
[0007] Obtaining a first video segment, and determining a maximum bit rate supported by the first video segment;
[0008] Performing CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment, wherein the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor;
[0009] Obtaining a peak signal-to-noise ratio, a structural similarity index, and a bitstream byte count of each video frame in the second video segment, wherein the peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF transcoding;
[0010] Determine a target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, wherein the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments with the same number of frames in the second video segment;
[0011] Based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, obtaining transcoding feature information corresponding to the target video sub-segment;
[0012] Extracting bitstream layer feature information corresponding to the target video sub-segment, wherein the bitstream layer feature information at least includes distribution features of quantization parameters, motion vector features, frame size features, and macroblock type features;
[0013] Applying the pre-trained prediction model, processing the transcoding feature information and the bitstream layer feature information corresponding to the target video sub-segment, and obtaining a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to a plurality of other transcoding parameters;
[0014] Among at least one average bit rate to be selected, a transcoding parameter corresponding to a maximum average bit rate to be selected is selected to perform final CRF transcoding on the first video segment, and the average bit rate to be selected is a first average bit rate less than the maximum bit rate.
[0015] Optionally, the determining the target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment includes:
[0016] Generate a frame size list corresponding to the second video segment, wherein the frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order;
[0017] Determine the window width of the preset sliding window;
[0018] Sliding the sliding window in the frame size list, and calculating the sum of the number of bitstream bytes of each video frame within the window width each time the sliding window is slid;
[0019] The video frame region where the sliding window having the largest sum of bitstream bytes is located is selected from the frame size list as the target video sub-segment.
[0020] Optionally, obtaining transcoding feature information corresponding to the target video sub-segment based on a peak signal-to-noise ratio and a structural similarity index of each video frame in the target video sub-segment includes:
[0021] Based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, the average peak signal-to-noise ratio and the average structural similarity index of the target video sub-segment are calculated, and the average peak signal-to-noise ratio and the average structural similarity index are used as transcoding feature information corresponding to the target video sub-segment.
[0022] Optionally, the process of training the prediction model includes:
[0023] According to the number of frames of the target video sub-segment, a video segment set is collected, wherein the video segment set includes at least one third video segment, and the third video segment is a video segment with the same number of frames as the target video sub-segment;
[0024] After performing CRF pre-transcoding on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained;
[0025] Perform CRF transcoding on the third video segment according to the at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter;
[0026] The transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are used as training data, and the second average bit rate is used as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
[0027] Optionally, the process of obtaining the peak signal-to-noise ratio and the structural similarity index of each video frame in the second video segment includes:
[0028] Based on the video resolution of the second video segment, scaling the first video segment to obtain a fourth video segment;
[0029] The image pixel difference and image similarity between each video frame in the fourth video segment and the video frame in the corresponding second video segment are calculated to obtain a peak signal-to-noise ratio and a structural similarity index of each video frame in the second video segment.
[0030] A video transcoding device, comprising:
[0031] A first acquisition unit, configured to obtain a first video segment and determine a maximum bit rate supported by the first video segment;
[0032] A first transcoding unit, configured to perform CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment, wherein the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor;
[0033] A second acquisition unit is used to obtain a peak signal-to-noise ratio, a structural similarity index, and a bitstream byte count of each video frame in the second video segment, wherein the peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF transcoding;
[0034] a determining unit, configured to determine a target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, wherein the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments with the same number of frames in the second video segment;
[0035] A third acquisition unit, configured to obtain transcoding feature information corresponding to the target video sub-segment based on a peak signal-to-noise ratio and a structural similarity index of each video frame in the target video sub-segment;
[0036] A fourth acquisition unit is used to extract bitstream layer feature information corresponding to the target video sub-segment, wherein the bitstream layer feature information at least includes a distribution feature of a quantization parameter, a motion vector feature, a frame size feature, and a macroblock type feature;
[0037] A prediction unit, used to apply a pre-trained prediction model to process transcoding feature information and bitstream layer feature information corresponding to the target video sub-segment, and obtain a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to multiple other transcoding parameters;
[0038] The second transcoding unit is used to select a transcoding parameter corresponding to a maximum average bit rate to be selected from at least one average bit rate to be selected, and perform final CRF transcoding on the first video segment, wherein the average bit rate to be selected is a first average bit rate less than the maximum bit rate.
[0039] Optionally, the determining unit determines the target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, specifically for:
[0040] Generate a frame size list corresponding to the second video segment, wherein the frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order;
[0041] Determine the window width of the preset sliding window;
[0042] Sliding the sliding window in the frame size list, and calculating the sum of the number of bitstream bytes of each video frame within the window width each time the sliding window is slid;
[0043] The video frame region where the sliding window having the largest sum of bitstream bytes is located is selected from the frame size list as the target video sub-segment.
[0044] Optionally, the device further comprises: a training unit;
[0045] The training unit is used to:
[0046] According to the number of frames of the target video sub-segment, a video segment set is collected, wherein the video segment set includes at least one third video segment, and the third video segment is a video segment with the same number of frames as the target video sub-segment;
[0047] After performing CRF pre-transcoding on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained;
[0048] Perform CRF transcoding on the third video segment according to the at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter;
[0049] The transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are used as training data, and the second average bit rate is used as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
[0050] A storage medium includes stored instructions, wherein when the instructions are executed, a device where the storage medium is located is controlled to execute any one of the above-mentioned video transcoding methods.
[0051] An electronic device comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform any one of the above-mentioned video transcoding methods.
[0052] Compared with the prior art, the present invention has the following advantages:
[0053] The present invention provides a video transcoding method, device, storage medium and electronic device, comprising: obtaining a first video segment and determining a maximum bit rate supported by the first video segment; performing CRF pre-transcoding on the first video segment according to an initial transcoding parameter to obtain a second video segment; obtaining a peak signal-to-noise ratio, a structural similarity index and a bit stream byte number of each video frame in the second video segment; determining a target video sub-segment in the second video segment based on the bit stream byte number of each video frame; obtaining transcoding feature information corresponding to the target video sub-segment based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment; extracting bit stream layer feature information corresponding to the target video sub-segment; applying a prediction model to process the transcoding feature information and bit stream layer feature information corresponding to the target video sub-segment to obtain multiple first average bit rates; and selecting a transcoding parameter corresponding to the largest average bit rate to be selected from at least one average bit rate to perform final CRF transcoding on the first video segment, wherein the average bit rate to be selected is a first average bit rate less than the maximum bit rate. By using the method provided by the present invention, the average bit rate under different transcoding parameters can be predicted in advance, and the transcoding parameters corresponding to the appropriate average bit rate can be selected from each average bit rate to perform the final CRF transcoding on the video, thereby ensuring the video quality while also meeting the bandwidth requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0055] Figure 1 A method flow chart of a video transcoding method provided by an embodiment of the present invention;
[0056] Figure 2 A flowchart of another method of a video transcoding method provided by an embodiment of the present invention;
[0057] Figure 3 A schematic diagram of the movement of a sliding window in a video transcoding method provided by an embodiment of the present invention;
[0058] Figure 4 A flowchart of another method of a video transcoding method provided by an embodiment of the present invention;
[0059] Figure 5 A device structure diagram of a video transcoding device provided by an embodiment of the present invention;
[0060] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0061] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0062] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0063] The present invention can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or devices, etc.
[0064] The embodiment of the present invention provides a video transcoding method, which can be applied to various system platforms, and its execution subject can be a processor of a computer terminal or various mobile devices. The method flow chart of the method is as follows: Figure 1 As shown, specifically including:
[0065] S101: Obtain a first video segment, and determine a maximum bit rate supported by the first video segment.
[0066] S102: Perform CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment.
[0067] The initial transcoding parameters include at least an initial transcoding resolution and an initial bit rate factor, and may also include but are not limited to encoding formats such as H264, H265, AV1, AVS, etc.
[0068] S103: Obtaining a peak signal-to-noise ratio, a structural similarity index, and a bitstream byte count of each video frame in the second video segment.
[0069] Among them, the Peak Signal to Noise Ratio (PSNR) is used to characterize the image quality of the video frame after CRF (Constant Rate Factor) transcoding, and the Structural Similarity Index (SSIM) is used to characterize the similarity of the video frame before and after CRF.
[0070] It should be noted that when calculating the peak signal-to-noise ratio and structural similarity index of video frames, the resolutions of the images of the two video frames need to be consistent. Therefore, the embodiment of the present invention can scale the video clip before transcoding to the resolution of the video clip after transcoding, and then compare and calculate it with the transcoded video clip.
[0071] Optionally, the process of obtaining the peak signal-to-noise ratio and the structural similarity index of each video frame in the second video segment provided by the embodiment of the present invention may include:
[0072] The first video segment is scaled based on the video resolution of the second video segment to obtain a fourth video segment.
[0073] The image pixel difference and image similarity between each video frame in the fourth video segment and the corresponding video frame in the second video segment are calculated to obtain a peak signal-to-noise ratio and a structural similarity index of each video frame in the second video segment.
[0074] It is understandable that the embodiment of the present invention can also scale the transcoded video segment to the resolution of the original video segment and then compare and calculate with the original video segment.
[0075] Optionally, the process of obtaining the peak signal-to-noise ratio and the structural similarity index of each video frame in the second video segment provided by the embodiment of the present invention may include:
[0076] Based on the video resolution of the first video segment, the second video segment is scaled to obtain a fifth video segment.
[0077] The image pixel difference and image similarity between each video frame in the fifth video segment and the corresponding video frame in the first video segment are calculated to obtain a peak signal-to-noise ratio and a structural similarity index of each video frame in the second video segment.
[0078] Optionally, the embodiment of the present invention can directly obtain the peak signal-to-noise ratio and the structural similarity index of each video frame during the pre-transcoding process of the first video segment.
[0079] S104: Determine a target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment.
[0080] The sum of the bitstream bytes of the video frames in the target video sub-segment is greater than the sum of the bitstream bytes of other video sub-segments of the same size in the second video segment.
[0081] Specifically, a sliding window may be set, and during the sliding process of the window, the sum of the number of bytes of the code streams of each video frame in the window is calculated.
[0082] Optionally, several adjacent video frames may be selected in sequence according to a preset number of frames as a video sub-segment to calculate the sum of the number of bytes of the bitstream.
[0083] It should be noted that the larger the sum of the bitstream bytes of a single video sub-segment is, the more complex the representation of the video sub-segment is, and the greater the difficulty in the transcoding process is.
[0084] S105: Obtain transcoding feature information corresponding to the target video sub-segment based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment.
[0085] The transcoding feature information is the average value of the peak signal-to-noise ratio and the average value of the structural similarity index of each video frame in the target video sub-segment. That is, based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, the average peak signal-to-noise ratio and the average structural similarity index of the target video sub-segment are calculated, and the average peak signal-to-noise ratio and the average structural similarity index are used as the transcoding feature information corresponding to the target video sub-segment.
[0086] S106: Extracting bitstream layer feature information corresponding to the target video sub-segment.
[0087] The bitstream layer feature information includes at least one of a quantizer parameter (QP) distribution feature, a motion vector feature, a frame size feature, and a macroblock type feature.
[0088] Furthermore, the bitstream layer feature information may specifically include 45 features, with specific reference to the features in Table 1 and Table 2 below:
[0089]
[0090]
[0091] S107: Apply the pre-trained prediction model to process the transcoding feature information and bitstream layer feature information corresponding to the target video sub-segment, and obtain a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to multiple other transcoding parameters.
[0092] It should be noted that the prediction model can specifically be a regression model, and the available models include LibGBM, RandomForest, SVM (support vector machine), etc.
[0093] It should also be noted that other transcoding parameters correspond to different bit rate factors, and the prediction model mainly predicts the average bit rate of the transcoded video clips under different bit rate factors.
[0094] Specifically, the transcoding feature information and the bitstream layer feature information are combined and input into a prediction model to predict the average bit rate.
[0095] S108: Selecting a transcoding parameter corresponding to a maximum average bit rate to be selected from at least one average bit rate to be selected, and performing final CRF transcoding on the first video segment.
[0096] The average bit rate to be selected is a first average bit rate that is less than the maximum bit rate.
[0097] Based on the above method, the process of selecting the maximum average bit rate to be selected has the following scenario embodiments:
[0098] For example, for a video with 1080P output resolution, when the CRF values (bitrate factor) are 24, 25, 26, 27, and 28, the Bitrate (average bitrate) obtained by this method is 3200Kbps, 3000Kbps, 2800Kbps, 2400Kbps, and 2000Kbps. Considering the image quality and bandwidth cost, the business requires the average bitrate to be no higher than 2500Kbps (that is, the maximum bitrate supported by the video is 2500Kbps). At this time, we can choose to use the bitrate factor = 27 as the final encoding factor for transcoding.
[0099] By applying the method provided by the embodiment of the present invention, the average bit rate under different transcoding parameters can be predicted in advance, and the transcoding parameters corresponding to the appropriate average bit rate can be selected from each average bit rate to finally transcode the video, thereby ensuring that the video quality can also meet the bandwidth requirements.
[0100] In the method provided in the embodiment of the present invention, reference is made to Figure 2 , based on the number of bitstream bytes of each video frame in the second video segment, determining a target video sub-segment in the second video segment, comprising:
[0101] S201: Generate a frame size list corresponding to the second video segment.
[0102] The frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order.
[0103] S202: Determine a preset window width of a sliding window.
[0104] S203: Slide the sliding window in the frame size list, and calculate the sum of the number of code stream bytes of each video frame within the window width each time the sliding window is slid.
[0105] refer to Figure 3 , Figure 3 The figure is a schematic diagram of the sliding process of the sliding window. The sliding window slides in time sequence. After each sliding, a video frame enters and leaves the range covered by the sliding window. The window width of the sliding window is the size of the combination of multiple video frames.
[0106] S204: Select the video frame region where the sliding window with the largest sum of bitstream bytes is located in the frame size list as the target video sub-segment.
[0107] Based on the method provided in the above embodiment, the process of video transcoding may have the following implementation scenarios:
[0108] (1) Perform a CRF constant bitrate factor H264 pre-transcoding of the target video according to the preset transcoding resolution, preset bitrate factor and other preset parameters to obtain the output video file. During the pre-transcoding process, the peak signal-to-noise ratio and structural similarity index are calculated. Among them, the peak signal-to-noise ratio and structural similarity index are based on the preset transcoding resolution rather than scaling to the source resolution. These features cannot be obtained separately from the transcoded video file and are suitable for acquisition during the transcoding process.
[0109] (2) Count the number of bytes of the code stream of each frame of the pre-transcoded output video file to form a list of frame sizes in chronological order.
[0110] (3) Traverse the list with a sliding window of T frame width and calculate the sum of the bitstream byte sizes of each frame in the sliding window. Record the maximum sum of the bitstream byte sizes and the position of the sliding window at this time, and define the sliding window position as the target sliding window.
[0111] Among them, according to the principle of CRF encoding, the bit rate distribution after pre-transcoding reflects the complexity of the picture to a certain extent. The use of sliding windows to select the most complex segment from the target video as the representative segment has the following considerations: First, there is uncertainty in the complexity distribution of each scene in the video. When extracting features from the entire video, the features of simple scenes and complex scenes will be mixed and disturbed. Secondly, the average bit rate of the most complex segment is more conducive to estimating the occupied file volume and consumed transmission bandwidth. In addition, if the expected average bit rate is selected from the average bit rates predicted by each CRF from the perspective of picture quality, the video produced using this bit rate factor as the transcoding parameter can ensure that the picture quality is always above the expected picture quality, because the average bit rate (quality expectation) is based on the most complex segment.
[0112] (4) Extract the peak signal-to-noise ratio and the average value of the structural similarity index within the target sliding window as feature information during the transcoding process.
[0113] (5) The pre-transcoded video file generated in step (1) is analyzed in the target sliding window to extract the bitstream byte layer features in the window. This scheme selects a total of 45 bitstream layer feature information, mainly including the distribution characteristics of quantization parameters, motion vector characteristics, frame size characteristics and macroblock type characteristics.
[0114] (6) The feature information generated in the transcoding process in step D and the bitstream layer feature information generated in step E are combined and sent to the trained machine learning model. The model predicts the average bit rate of the video in the target sliding window after constant bit rate factor encoding under the specified bit rate factor and specified encoding parameters. The specified encoding parameters include but are not limited to encoding resolution and encoding format such as H264, H265, AV1, AVS, etc. The encoding parameters are consistent with the encoding parameters used to produce the dataset labels in the training model stage.
[0115] (7) Obtain the average bitrate of the target video in the sliding window after encoding at each bitrate factor. The average bitrate of the target video after encoding must be less than the average bitrate under the same bitrate factor. Select the appropriate bitrate factor for final transcoding based on the average bitrate and the business situation.
[0116] In the present invention, the selected bitstream layer feature information can be divided into the following categories: frame size features, quantization parameter distribution features, motion vector features, macroblock type features and features during transcoding. The features are all calculated within a frame, and then the average value within the sliding window is calculated. For example, the calculation process of the maximum value of the quantization parameter: calculate the maximum value of the quantization parameter of each frame, and calculate the average value of the maximum value of the quantization parameter of each frame as the feature value.
[0117] The greater the correlation between the feature and the label data, the higher the prediction accuracy. The distribution of the quantization parameter value reflects the difficulty of picture encoding to a certain extent. The simpler the picture, the smaller the average quantization parameter when encoded at the same bit rate factor, and vice versa. The encoding difficulty will eventually be reflected in the volume of the generated file in CRF encoding, so the quantization parameter distribution is a relatively effective feature. Similarly, the motion vector can also reflect the difficulty of encoding. In addition to introducing the traditional motion vector size, the scheme also introduces the error between the motion vector prediction value and the true value as a feature. This feature reflects the irregularity and unpredictability of the motion in the picture to a certain extent. The larger the error, the higher the encoding complexity. The macroblock partitioning method reflects the complexity of the texture in the picture. The introduction of the peak signal-to-noise ratio and structural similarity index features in the transcoding process has a significant impact on the improvement of the model prediction accuracy, because it reflects the encoding difficulty of the source for the encoder. The higher the encoding difficulty, the lower the peak signal-to-noise ratio\structural similarity index value at the same bit rate factor, and vice versa.
[0118] In the present invention, the extraction of the above-mentioned code stream byte layer features is completed in the compression domain, without pixel-level operations, the required computational cost is low, and it is easy to implement in engineering. Experimental data show that the above-mentioned features can obtain good reasoning accuracy. The extraction of peak signal-to-noise ratio and structural similarity index features in the transcoding process only requires a small computational overhead because the pre-transcoding process is reused. The encoder completes the calculation of the peak signal-to-noise ratio and structural similarity index of the current frame to be encoded and the reconstructed frame.
[0119] In the method provided in the embodiment of the present invention, reference is made to Figure 4 , the process of training a prediction model includes:
[0120] S401: collecting a video segment set according to the number of frames of a target video sub-segment, where the video segment set includes at least one third video segment.
[0121] The third video segment is a video segment having the same frame number as the target video sub-segment.
[0122] It should be noted that a video segment having the same frame number as the target video sub-segment may be directly obtained through a web crawler or a database, or a video segment may be captured from a long video according to the frame number of the target video sub-segment.
[0123] S402: After performing CRF pre-transcoding on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained.
[0124] It should be noted that the process of pre-transcoding the third video clip in S402 is consistent with the process of pre-transcoding in S102 above, and will not be described in detail here.
[0125] S403: Perform CRF transcoding on the third video segment according to at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter.
[0126] S404: using the transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment as training data and the second average bit rate as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
[0127] It can be understood that after the third video clip is pre-transcoded, the transcoding process corresponding to other transcoding parameters is performed again on the third video clip multiple times according to the CRF transcoding method to obtain the second average bit rate corresponding to each other transcoding parameter. The feature information obtained by the original pre-transcoding and the bitstream layer feature information are input into the prediction model as training data. The prediction model outputs the predicted average bit rate corresponding to each other transcoding parameter after processing, and the predicted average bit rate is compared with the standard second average bit rate. If the difference between the two is large, the model parameters of the prediction model are adjusted and the prediction is performed again until the error between the obtained predicted average bit rate and the standard second average bit rate is within the preset range, indicating that the prediction model has converged and the training of the prediction model is completed.
[0128] It should be noted that the training phase of the prediction model includes several steps, including data set preparation and model training. At this time, the video is transcoded using different bitrate factors in order to obtain label data, i.e., answers, under different bitrate factors. Each data-answer combination will be trained to obtain a model file. In the actual reasoning phase (engineering production phase), only one pre-transcoding is required to extract the feature information after pre-transcoding and feed it into each model file (model), so that the average bitrate under different bitrate factors can be inferred.
[0129] In the present invention, the specific implementation process of training the prediction model may include the following implementation scenarios:
[0130] A. Select T consecutive frames of video from the original source material to form a video clip, and collect a certain number of video clips to form a data set. The common value of T is 250 frames, corresponding to a 10-second duration of a 25fps source. Generally, the video clip is formed by copying the key frame position from the original source material in a non-transcoding manner.
[0131] B. Perform a CRF constant bit rate factor H264 pre-transcoding on the video clips in the data set according to the preset transcoding resolution, preset bit rate factor and other preset parameters to obtain the output video file.
[0132] C. Extract the peak signal-to-noise ratio and structural similarity index in the pre-transcoding process as feature information, and extract the bitstream layer feature information of the pre-transcoding output video file. The two feature information items total 47 items.
[0133] D. Transcode the video clips with a bitrate factor CRF of N and business-specified encoding parameters such as encoding format and resolution. N is determined by the business scenario. For example, if N is 20 to 32, the video source clips will be transcoded 13 times. The business-specified encoding parameters must be consistent with the encoding parameters when the model is finally used for average bitrate prediction, such as encoding formats such as H264, H265, AV1, AVS, etc. The specified resolution must be consistent with the resolution when the model is finally used for average bitrate prediction, such as 1080P.
[0134] E. Calculate the average bit rate of the transcoded video file output in step D as the label of the data set. For example, if N is 20-32, 13 labels will be formed, and the labels and feature information together form 13 data sets.
[0135] The machine learning model used in this solution adopts a regression model. The available models include LibGBM, RandomForest, SVM (support vector machine), etc. For different bitrate factors N, the respective model files are trained for prediction. For example, if the average bitrate after transcoding needs to be predicted when the CRF value is 20-32, 13 model files will be trained.
[0136] Based on the method provided in the above embodiment, the present invention provides an application implementation scenario of a video transcoding method. The specific embodiment is as follows. In this example, a certain video needs to be encoded with a constant bit rate factor at a resolution of 1080P, and the bit rate factor CRF range is 24 to 32:
[0137] (1) Encode the video source with a constant bit rate factor to generate a pre-transcoded video. Preset parameters: encoding standard H264, encoding resolution 540P, frame rate 25, CRF value 28, use 2 reference frames, enable B frame encoding, IDR (Instantaneous Decoding Refresh) key frame interval 75 frames, enable peak signal-to-noise ratio and structural similarity index calculation. Other parameters use the default configuration of X264, and record the peak signal-to-noise ratio and structural similarity index of the Y component of each frame. The same encoding parameters as those used in the dataset preprocessing stage should be used here.
[0138] (2) Use tools such as ffprobe to output the size of each frame of the pre-transcoded video and record it.
[0139] (3) Traverse the frame size list with 250 frames as the window and calculate the sum of the bitstream byte sizes of each frame in the sliding window. Record the maximum value of the sum of the bitstream byte sizes and the position of the sliding window at this time, and define the sliding window position as the target sliding window.
[0140] (4) Calculate the average value of the peak signal-to-noise ratio and structural similarity index of the Y component in the sliding window as the features in the transcoding process. Calculate the bitstream byte number layer features of the pre-transcoded video in the sliding window.
[0141] (5) Combine the features of the pre-transcoding process and the features of the bitstream byte count layer and send them to the corresponding machine learning models of CRF 24~32 in turn, and output the predicted bitrate under each CRF. According to the business situation, the bitrate factor that meets the expected bitrate is selected as the formal encoding bitrate factor.
[0142] (6) Use the official encoding bit rate factor to transcode the video source with a constant bit rate factor. The encoding parameters are determined according to the business situation, such as encoding standard H265, encoding resolution 1080P, frame rate 25, using 2 reference frames, B frame encoding, IDR interval 75 frames, etc. The same encoding parameters as those used in the dataset labeling stage should be used here.
[0143] In the method provided in the embodiment of the present invention, the present invention proposes to use a sliding window to select the most complex segment from the target video as a representative segment, extract its features, and predict its average bit rate after specified CRF encoding. The prediction of the bit rate after transcoding the most complex segment can ensure that the average bit rate or file volume of the entire CRF encoding is controlled. Compared with the existing scheme that only uses the feature information of the pre-transcoded video file, the present invention introduces the peak signal-to-noise ratio and structural similarity indicators in the pre-transcoding process as auxiliary feature information, which can greatly improve the feature correlation and improve the prediction accuracy. The present invention extracts 45 bitstream byte layer features of the transcoded video file, and has the characteristics of high extraction performance and full feature coverage. Among them, the motion vector prediction error as a feature is not involved in the existing scheme.
[0144] The specific implementation processes and derivative methods of the above-mentioned embodiments are all within the protection scope of the present invention.
[0145] and Figure 1 Corresponding to the method, the embodiment of the present invention also provides a video transcoding device for Figure 1 The specific implementation of the method in the embodiment of the present invention is that the video transcoding device provided by the embodiment of the present invention can be applied to a computer terminal or various mobile devices, and its structural diagram is as follows Figure 5 As shown, specifically including:
[0146] The first acquisition unit 501 is configured to acquire a first video segment and determine a maximum bit rate supported by the first video segment.
[0147] The first transcoding unit 502 is configured to perform CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment, where the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor.
[0148] The second acquisition unit 503 is used to obtain the peak signal-to-noise ratio, structural similarity index and bitstream byte number of each video frame in the second video segment, the peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF.
[0149] The determination unit 504 is used to determine the target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, and the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments of the same size in the second video segment.
[0150] The third acquisition unit 505 is used to obtain transcoding feature information corresponding to the target video sub-segment based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment.
[0151] The fourth acquisition unit 506 is used to extract the bitstream layer feature information corresponding to the target video sub-segment, where the bitstream layer feature information at least includes the distribution feature of the quantization parameter, the motion vector feature, the frame size feature, and the macroblock type feature.
[0152] The prediction unit 507 is used to apply the pre-trained prediction model to process the transcoding feature information and bitstream layer feature information corresponding to the target video sub-segment, and obtain the first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to multiple other transcoding parameters.
[0153] The second transcoding unit 508 is used to select a transcoding parameter corresponding to a maximum average bit rate to be selected from at least one average bit rate to be selected, and perform final CRF transcoding on the first video, wherein the average bit rate to be selected is a first average bit rate less than the maximum bit rate.
[0154] In the device provided by the embodiment of the present invention, the determining unit determines the target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, and is specifically configured to:
[0155] A frame size list corresponding to the second video segment is generated, wherein the frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order.
[0156] Determines the window width of the preset sliding window.
[0157] Slide the sliding window in the frame size list, and calculate the sum of the bitstream bytes of each video frame within the window width each time the sliding window is slid.
[0158] In the frame size list, select the video frame region where the sliding window with the largest sum of bitstream bytes is located as the target video sub-segment.
[0159] The device provided in the embodiment of the present invention further includes: a training unit.
[0160] Training unit for:
[0161] According to the number of frames of the target video sub-segment, a video segment set is collected, the video segment set includes at least one third video segment, and the third video segment is a video segment with the same number of frames as the target video sub-segment.
[0162] After CRF pre-transcoding is performed on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained.
[0163] Perform CRF transcoding on the third video segment according to at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter.
[0164] The transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are used as training data, and the second average bit rate is used as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
[0165] For the specific working process of each unit in the video transcoding device disclosed in the above embodiment of the present invention, reference may be made to the corresponding content in the video transcoding device disclosed in the above embodiment of the present invention, and will not be described in detail here.
[0166] An embodiment of the present invention further provides a storage medium, the storage medium including stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned video transcoding method.
[0167] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Figure 6 As shown, it specifically includes a memory 601 and one or more instructions 602, wherein the one or more instructions 602 are stored in the memory 601 and are configured to be executed by one or more processors 603 to perform the following operations:
[0168] A first video segment is obtained, and a maximum bit rate supported by the first video segment is determined.
[0169] The first video segment is CRF pre-transcoded according to preset initial transcoding parameters to obtain a second video segment, where the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor.
[0170] The peak signal-to-noise ratio, structural similarity index and bitstream byte count of each video frame in the second video clip are obtained. The peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF.
[0171] Based on the number of bitstream bytes of each video frame in the second video segment, a target video sub-segment in the second video segment is determined, and the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments of the same size in the second video segment.
[0172] Based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, transcoding feature information corresponding to the target video sub-segment is obtained.
[0173] Extract the bitstream layer feature information corresponding to the target video sub-segment, where the bitstream layer feature information at least includes the distribution feature of the quantization parameter, the motion vector feature, the frame size feature, and the macroblock type feature.
[0174] The pre-trained prediction model is applied to process transcoding feature information and bitstream layer feature information corresponding to the target video sub-segment, and a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to multiple other transcoding parameters is obtained.
[0175] Among at least one average bit rate to be selected, a transcoding parameter corresponding to a maximum average bit rate to be selected is selected to perform final CRF transcoding on the first video, and the average bit rate to be selected is a first average bit rate that is less than the maximum bit rate.
[0176] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, in which the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0177] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.
[0178] In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0179] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A video transcoding method, characterized in that: include: Obtaining a first video segment, and determining a maximum bit rate supported by the first video segment; Performing CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment, wherein the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor; Obtaining a peak signal-to-noise ratio, a structural similarity index, and a bitstream byte count of each video frame in the second video segment, wherein the peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF transcoding; Determine a target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, wherein the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments with the same number of frames in the second video segment; Based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, obtaining transcoding feature information corresponding to the target video sub-segment; Extracting bitstream layer feature information corresponding to the target video sub-segment, wherein the bitstream layer feature information at least includes distribution features of quantization parameters, motion vector features, frame size features, and macroblock type features; Applying the pre-trained prediction model, processing the transcoding feature information and the bitstream layer feature information corresponding to the target video sub-segment, and obtaining a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to a plurality of other transcoding parameters; Among at least one average bit rate to be selected, a transcoding parameter corresponding to a maximum average bit rate to be selected is selected to perform final CRF transcoding on the first video segment, and the average bit rate to be selected is a first average bit rate less than the maximum bit rate.
2. The method according to claim 1, characterized in that: The determining, based on the number of code stream bytes of each video frame in the second video segment, a target video sub-segment in the second video segment comprises: Generate a frame size list corresponding to the second video segment, wherein the frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order; Determine the window width of the preset sliding window; Sliding the sliding window in the frame size list, and calculating the sum of the number of bitstream bytes of each video frame within the window width each time the sliding window is slid; The video frame region where the sliding window having the largest sum of bitstream bytes is located is selected from the frame size list as the target video sub-segment.
3. The method according to claim 1 or 2, characterized in that: The obtaining, based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, transcoding feature information corresponding to the target video sub-segment includes: Based on the peak signal-to-noise ratio and the structural similarity index of each video frame in the target video sub-segment, the average peak signal-to-noise ratio and the average structural similarity index of the target video sub-segment are calculated, and the average peak signal-to-noise ratio and the average structural similarity index are used as transcoding feature information corresponding to the target video sub-segment.
4. The method according to claim 1, characterized in that The process of training the prediction model includes: According to the number of frames of the target video sub-segment, a video segment set is collected, wherein the video segment set includes at least one third video segment, and the third video segment is a video segment with the same number of frames as the target video sub-segment; After performing CRF pre-transcoding on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained; Perform CRF transcoding on the third video segment according to at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter; The transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are used as training data, and the second average bit rate is used as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
5. The method according to claim 1, characterized in that The process of obtaining the peak signal-to-noise ratio and the structural similarity index of each video frame in the second video segment includes: Based on the video resolution of the second video segment, scaling the first video segment to obtain a fourth video segment; The image pixel difference and image similarity between each video frame in the fourth video segment and the video frame in the corresponding second video segment are calculated to obtain a peak signal-to-noise ratio and a structural similarity index of each video frame in the second video segment.
6. A video transcoding device, characterized in that: include: A first acquisition unit, configured to obtain a first video segment and determine a maximum bit rate supported by the first video segment; A first transcoding unit, configured to perform CRF pre-transcoding on the first video segment according to preset initial transcoding parameters to obtain a second video segment, wherein the initial transcoding parameters at least include an initial transcoding resolution and an initial bit rate factor; A second acquisition unit is used to obtain a peak signal-to-noise ratio, a structural similarity index, and a bitstream byte count of each video frame in the second video segment, wherein the peak signal-to-noise ratio is used to characterize the image quality of the video frame after CRF transcoding, and the structural similarity index is used to characterize the similarity of the video frame before and after CRF transcoding; a determining unit, configured to determine a target video sub-segment in the second video segment based on the number of bitstream bytes of each video frame in the second video segment, wherein the sum of the number of bitstream bytes of each video frame in the target video sub-segment is greater than the sum of the number of bitstream bytes of other video sub-segments with the same number of frames in the second video segment; A third acquisition unit, configured to obtain transcoding feature information corresponding to the target video sub-segment based on a peak signal-to-noise ratio and a structural similarity index of each video frame in the target video sub-segment; A fourth acquisition unit is used to extract bitstream layer feature information corresponding to the target video sub-segment, wherein the bitstream layer feature information at least includes a distribution feature of a quantization parameter, a motion vector feature, a frame size feature, and a macroblock type feature; A prediction unit, used to apply a pre-trained prediction model to process transcoding feature information and bitstream layer feature information corresponding to the target video sub-segment, and obtain a first average bit rate of the first video segment predicted by the prediction model after CRF transcoding according to multiple other transcoding parameters; The second transcoding unit is used to select a transcoding parameter corresponding to a maximum average bit rate to be selected from at least one average bit rate to be selected, and perform final CRF transcoding on the first video segment, wherein the average bit rate to be selected is a first average bit rate less than the maximum bit rate.
7. The device according to claim 6, characterized in that The determining unit determines the target video sub-segment in the second video segment based on the number of code stream bytes of each video frame in the second video segment, specifically for: Generate a frame size list corresponding to the second video segment, wherein the frame size list includes the number of bitstream bytes of each video frame in the second video segment arranged in chronological order; Determine the window width of the preset sliding window; Sliding the sliding window in the frame size list, and calculating the sum of the number of bitstream bytes of each video frame within the window width each time the sliding window is slid; The video frame region where the sliding window having the largest sum of bitstream bytes is located is selected from the frame size list as the target video sub-segment.
8. The device according to claim 6, characterized in that Also includes: Training unit; The training unit is used to: According to the number of frames of the target video sub-segment, a video segment set is collected, wherein the video segment set includes at least one third video segment, and the third video segment is a video segment with the same number of frames as the target video sub-segment; After performing CRF pre-transcoding on the third video segment according to the initial transcoding parameters, transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are obtained; Perform CRF transcoding on the third video segment according to at least one other transcoding parameter to obtain a second average bit rate corresponding to the at least one other transcoding parameter; The transcoding feature information and bitstream layer feature information of the pre-transcoded third video segment are used as training data, and the second average bit rate is used as a training label to iteratively train the prediction model until the prediction model converges, thereby completing the training of the prediction model.
9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the video transcoding method according to any one of claims 1 to 5.
10. An electronic device, characterized in that: The device comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the video transcoding method as described in any one of claims 1 to 5.
