WO2026011968A1 - 视频编码方法、装置、设备以及可读存储介质 - Google Patents

视频编码方法、装置、设备以及可读存储介质

Info

Publication number
WO2026011968A1
WO2026011968A1 PCT/CN2025/095634 CN2025095634W WO2026011968A1 WO 2026011968 A1 WO2026011968 A1 WO 2026011968A1 CN 2025095634 W CN2025095634 W CN 2025095634W WO 2026011968 A1 WO2026011968 A1 WO 2026011968A1
Authority
WO
WIPO (PCT)
Prior art keywords
video
video frame
bitrate
value
encoding
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2025/095634
Other languages
English (en)
French (fr)
Inventor
李志成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology (Shenzhen) Co Ltd
Original Assignee
Tencent Technology (Shenzhen) Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology (Shenzhen) Co Ltd filed Critical Tencent Technology (Shenzhen) Co Ltd
Publication of WO2026011968A1 publication Critical patent/WO2026011968A1/zh
Pending legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/103—Selection of coding mode or of prediction mode
    • H04N19/114—Adapting the group of pictures [GOP] structure, e.g. number of B-frames between two anchor frames
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/136—Incoming video signal characteristics or properties
    • H04N19/14—Coding unit complexity, e.g. amount of activity or edge presence estimation
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/146—Data rate or code amount at the encoder output
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/146—Data rate or code amount at the encoder output
    • H04N19/149—Data rate or code amount at the encoder output by estimating the code amount by means of a model, e.g. mathematical model or statistical model
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/172—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a picture, frame or field
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/182—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being a pixel
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/186—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being a colour or a chrominance component
    • H—ELECTRICITY
    • H04—ELECTRIC COMMUNICATION TECHNIQUE
    • H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/136—Incoming video signal characteristics or properties
    • H04N19/137—Motion inside a coding unit, e.g. average field, frame or block difference

Definitions

  • This application relates to the field of computer technology, specifically to video coding.
  • streaming media services such as online live streaming, video downloading and playback, distance education, and telemedicine has been driven, enriching people's lives.
  • video encoding is required during video stream data transmission.
  • the video source bitrate needs to be determined first, so that the encoding bitrate of the video encoder can be determined based on the video source bitrate for video encoding.
  • the relevant technology calculates the video source bitrate at fixed intervals and adjusts the encoding bitrate of the video encoder synchronously based on the determined video source bitrate.
  • related technologies statistically analyze video source bitrate over a fixed period of time.
  • the statistically obtained video source bitrate is relatively fixed.
  • the video encoder After adjusting the encoding bitrate of the video encoder synchronously according to the determined video source bitrate, the video encoder will encode according to the fixed encoding bitrate during this period. Due to the diversity of video content, this will affect the video encoding quality and lead to a reduction in the image quality of the encoded video frames.
  • This application provides a video encoding method, apparatus, device, and readable storage medium, which can flexibly adjust the encoding bitrate of the video encoder according to the frame level to ensure the quality of the video frames after encoding.
  • This application provides a video encoding method, including:
  • the target video source is obtained as a sequence of frames to be encoded, and the first video frame in the sequence is encoded by the video encoder according to the encoding bitrate.
  • the image texture ratio is determined based on the first image texture value and the second image texture value.
  • the encoding bitrate of the video encoder is adjusted according to the image texture ratio to obtain the target encoding bitrate, and the first video frame is encoded according to the target encoding bitrate.
  • embodiments of this application provide a video encoding apparatus, including:
  • the acquisition unit is used to acquire the current encoding bitrate of the video encoder.
  • the encoding unit is used to acquire the sequence of frames to be encoded from the target video source, and to encode the first video frame in the sequence of frames to be encoded by the video encoder according to the encoding bitrate.
  • the first determining unit is used to determine the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded, and to determine the second image texture value of the second video frame adjacent to the first video frame, wherein the first video frame is any video frame after the first video frame;
  • the second determining unit is used to determine an image texture ratio based on the first image texture value and the second image texture value when the texture complexity identified by the first image texture value is greater than the texture complexity identified by the second image texture value.
  • An adjustment unit is used to adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain a target encoding bitrate, and to encode the first video frame according to the target encoding bitrate.
  • this application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described video encoding method.
  • embodiments of this application provide a storage medium for storing a computer program for executing the methods described above.
  • embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described above.
  • This application embodiment can obtain the current encoding bitrate of the video encoder; obtain the sequence of frames to be encoded from the target video source, and start encoding the first video frame in the sequence of frames to be encoded according to the encoding bitrate using the video encoder; determine the first image texture value of the first video frame currently to be encoded in the sequence of frames to be encoded, and determine the second image texture value of the second video frame adjacent to the first video frame, wherein the first video frame is any video frame after the first video frame; when the first image texture value is greater than the second image texture value, determine the image texture ratio based on the first image texture value and the second image texture value; adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encode the first video frame according to the target encoding bitrate.
  • this application can obtain the current encoding bitrate of the video encoder in real time, and then encode the video frames in the current frame sequence of the target video source according to the encoding bitrate. Furthermore, during the encoding process, the texture complexity between the first video frame to be encoded and the adjacent second video frame is compared in real time. Texture complexity represents the richness of the video frame's content to evaluate the required encoding bitrate. If the texture of the first video frame is more complex than the previous frame, the image texture ratio between the first and second video frames is determined based on the first and second image texture values. Finally, the encoding bitrate of the video encoder is adjusted to the target bitrate according to the image texture ratio.
  • the target encoding bitrate is set so that the video encoder encodes the first video frame according to the adjusted target encoding bitrate.
  • this application can compare the texture complexity between the preceding and following video frames during the encoding process of the target video source's frame sequence.
  • the encoding bitrate of the video encoder is adjusted according to the texture ratio between the preceding and following video frames. In this way, the encoding bitrate of the video encoder can be flexibly and finely adjusted at the frame level to ensure the encoding quality of the following video frames and guarantee the video frame image quality of the video encoding.
  • Figure 1 is a schematic diagram of a video encoding system provided in an embodiment of this application.
  • FIG. 2 is a flowchart illustrating the steps of the video encoding method provided in an embodiment of this application.
  • Figure 3 is an example of an image texture value calculation scenario in the video encoding method provided in the embodiments of this application;
  • Figure 4 is a schematic flowchart of another step of the video encoding method provided in the embodiment of this application.
  • Figure 5 is an example diagram of a video encoding scenario provided in an embodiment of this application.
  • Figure 6 is an example diagram of bitrate variation in a code control scenario for video encoding provided in the embodiments of this application;
  • Figure 7 is an example diagram of the video encoding process provided in an embodiment of this application.
  • Figure 8 is an example diagram of the calculation scenario of image texture value of video frame provided in the embodiment of this application.
  • Figure 9 is a schematic diagram of the video encoding device provided in an embodiment of this application.
  • Figure 10 is a schematic diagram of the structure of the terminal provided in an embodiment of this application.
  • FIG 11 is a schematic diagram of the server structure provided in an embodiment of this application.
  • this application embodiment when this application embodiment needs to obtain target video source and related data, it will obtain separate permission or separate consent for the target video source and related data through pop-up windows or redirection to a confirmation page. After clearly obtaining separate permission or separate consent for the target video source and related data, it will then obtain the necessary target video source and related data for enabling this application embodiment to operate normally.
  • IDR frames In video coding algorithms (H.264/H.265/H.266/AV1, etc.), images (i.e., video frames) are organized as sequences. The first image in a sequence is an Instantaneous Decoding Refresh (IDR) frame. IDR images are all internal picture (I) frames, which can also be understood as keyframes.
  • I-frame Internal image, keyframe. IDR frames clear the Decoded Picture Buffer (DPB) reference frame list, while I-frames do not.
  • DPB Decoded Picture Buffer
  • An IDR image is always an I-image, but an I-image is not necessarily an IDR image.
  • a sequence can contain many I-images, and image frames following an I-image frame can reference image frames between two I-image frames for motion reference.
  • Encoder bitrate control specifically refers to the allocation of bits to the frame to be encoded and the adjustment of quantization parameters (QP) by utilizing the existing information of the encoder, the actual number of bits generated after encoding, and the state of the buffer, so as to ensure that the optimal video quality is achieved through reasonable bit allocation under a limited target bitrate.
  • QP quantization parameters
  • Bitrate/bitstream This refers to the amount of data a video file uses per unit of time. Also called bitrate or bitstream rate, it can be simply understood as the sampling rate. It's the most important part of image quality control in video encoding, and is generally measured in kilobits per second (kbps) or megabits per second (mbps). At the same resolution, the higher the bitstream of a video file, the lower the compression ratio and the higher the image quality. A higher bitstream indicates a higher sampling rate per unit of time, higher data stream precision, and a file that is closer to the original file after encoding. This results in better image quality, clearer picture, and higher requirements for the decoding capabilities of the playback device.
  • QoS Quality of Service, mainly responsible for managing services and providing service differentiation from the network perspective.
  • Network entities handle different services according to different quality requirements.
  • Common monitoring indicators include stuttering rate, stuttering time, and first frame.
  • QoE Quality of Experience.
  • the evaluation subject is the end user, and the evaluation objects are the business and the network supporting the business.
  • the evaluation indicators are not limited to the average user video viewing time, video quality and clarity, screen latency and stuttering, etc. These indicators will affect the viewing experience (QoE) on the viewer's end, and thus also affect the advertising conversion effect.
  • GOP stands for group of pictures, specifically referring to the interval between two I-frames, such as interval duration and interval length.
  • the Instant Decode Refresh (IDR) frame is the first I-frame in a GOP, marking the start of a new sequence encoding for the video stream. Its purpose is to immediately refresh the decoder, thus preventing prediction errors from propagating.
  • IDR Instant Decode Refresh
  • the computer device can be a server or a target terminal, etc.
  • the server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
  • the target terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, smart home appliance, vehicle terminal, smart voice interaction device, aircraft, etc., but is not limited to these.
  • This application provides a video encoding method that uses the interval between keyframes in a video frame sequence to calculate the video source bitrate, which is then used to update the encoding bitrate of the video encoder. Based on this, the encoding bitrate of the video encoder is adjusted at the frame level by comparing the texture complexity between consecutive frames, and the video frames are encoded according to the adjusted bitrate.
  • the specific implementation is illustrated in the following examples:
  • this application proposes a video encoding method.
  • the method compares the texture complexity between consecutive video frames.
  • the texture of a later video frame is more complex than that of a previous video frame
  • the encoding bitrate of the video encoder is adjusted according to the ratio of texture complexity between the two frames. This allows for flexible and precise adjustment of the video encoder's bitrate at the frame level, ensuring the encoding quality of later video frames and guaranteeing the image quality of the encoded video frames. Please refer to the following specific embodiments for details.
  • the devices in this system may include a server and/or a terminal.
  • the terminal may request the server to execute the video encoding method of this application.
  • the system includes a server or terminal.
  • the terminal or server can obtain the current encoding bitrate of the video encoder; obtain the sequence of frames to be encoded from the target video source, and start encoding the first video frame in the sequence of frames to be encoded according to the encoding bitrate using the video encoder; determine the first image texture value of the first video frame currently to be encoded in the sequence of frames to be encoded, and determine the second image texture value of the second video frame adjacent to the first video frame, wherein the first video frame is any video frame after the first video frame; when the first image texture value is greater than the second image texture value, determine the image texture ratio based on the first image texture value and the second image texture value; adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encode the first video frame according to the target encoding bitrate.
  • Figure 1 is a schematic diagram of a video encoding system provided in an embodiment of this application
  • the system includes a server and a terminal.
  • the terminal is equipped with a client, which can send or obtain real-time video streaming data to or from the server backend, such as compressing and storing object attribute data in various business areas, querying object attribute data, etc.
  • the terminal can directly send or receive real-time video stream data to the server; in addition, a video client can be installed on the terminal, which can be used to send or receive real-time video stream data to the server.
  • the server can obtain the current encoding bitrate of the video encoder; obtain the sequence of frames to be encoded from the target video source, and start encoding the first video frame in the sequence of frames to be encoded according to the encoding bitrate using the video encoder; determine the first image texture value of the first video frame currently to be encoded in the sequence of frames to be encoded, and determine the second image texture value of the second video frame adjacent to the first video frame, wherein the first video frame is any video frame after the first video frame; when the first image texture value is greater than the second image texture value, determine the image texture ratio based on the first image texture value and the second image texture value; adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encode the first video frame according to the target encoding bitrate.
  • the video encoding system is applicable to both live video streaming and video-on-demand scenarios.
  • the terminal can include both a broadcaster and a viewer.
  • the broadcaster sends video source data to the server in real time.
  • the server encodes the video frames from the source and sends the encoded video frame stream to the viewer for decoding and playback.
  • video-on-demand the terminal can be understood as either the viewer or the on-demand client.
  • the server loads video data directly from pre-stored storage or other servers, using the pre-stored or loaded video as the video source.
  • the server encodes the video frames from the source's video frame stream sequence and sends the encoded video frame stream to the terminal for decoding and playback.
  • the broadcaster For example, taking live video streaming as an example, suppose the broadcaster is streaming a game.
  • the game footage is the target video source, and the broadcaster transmits the game footage to the server in real time as a stream.
  • This stream data is transmitted to the server in sequence.
  • the server determines the video source encoding based on the interval between keyframes in the sequence. Specifically, it determines the encoding in real time based on the granularity of the group of pictures (GOP) between two keyframes (I-frames).
  • the GOP can represent a group of video frames (the group of frames to be encoded). Specifically, the frame length (i.e., the interval) between two keyframes (I-frames) and the frame rate of the video source can be determined first.
  • the number of video frame groups per unit time i.e., the video source bitrate
  • the video encoding kernel i.e., the video encoder
  • the video encoder is dynamically loaded and updated according to the current video source bitrate so that the video encoder can obtain the current basic encoding bitrate.
  • the server begins encoding the video frames in the frame sequence according to the encoding bitrate of the video encoder.
  • the complexity of the video frames between adjacent frames is determined.
  • the complexity can be represented by image texture.
  • the image texture value of the current frame and the image texture value of the previous frame are determined.
  • the image texture ratio between the current video frame and the previous video frame can be determined.
  • the encoding bitrate in the video encoder is adjusted according to the image texture ratio.
  • the target encoding bitrate obtained by the adjustment is greater than the encoding bitrate when the previous frame was encoded.
  • the current video frame is encoded according to the target encoding bitrate to ensure the image encoding quality of the current more complex video frame and to guarantee the video frame image quality.
  • the encoded video frame data is transmitted to the viewer for decoding and playback. The viewer can then display the rich and complex game scenes in a better picture quality, ensuring reliability.
  • video on demand requires real-time video streaming data.
  • the server directly loads video from pre-stored data or from other servers, using the pre-stored or loaded video as the video source.
  • the server determines the video source encoding based on the interval between keyframes in the sequence. Specifically, it determines the encoding in real time based on the granularity of the group of pictures (GOP) between two keyframes (I-frames).
  • the frame interval can represent a group of video frames (the group of frames to be encoded). Specifically, the frame length between two keyframes (I-frames) and the frame rate of the playback client can be determined first.
  • the number of video frame groups per unit time i.e., the video source bitrate
  • the video encoding kernel i.e., the video encoder
  • the video encoder is dynamically loaded and updated according to the current video source bitrate so that the video encoder can obtain the current basic encoding bitrate.
  • the server begins encoding the video frames in the frame sequence according to the encoding bitrate of the video encoder.
  • the complexity of the video frames between adjacent frames is determined.
  • the complexity can be represented by image texture.
  • the image texture value of the current frame and the image texture value of the previous frame are determined.
  • the image texture ratio between the current video frame and the previous video frame can be determined.
  • the encoding bitrate in the video encoder is adjusted according to the image texture ratio.
  • the target encoding bitrate obtained by the adjustment is greater than the encoding bitrate when the previous frame was encoded.
  • the current video frame is encoded according to the target encoding bitrate to ensure the image encoding quality of the current more complex video frame and to guarantee the video frame image quality.
  • the encoded video frame data is transmitted to the terminal (video client) for decoding and playback. In this way, the terminal can display rich and complex game scenes with better picture quality and reliability.
  • this application can compare the texture complexity between consecutive video frames during the encoding process of the target video source's frame sequence.
  • the encoding bitrate of the video encoder is adjusted according to the texture ratio of the consecutive video frames. In this way, the encoding bitrate of the video encoder can be flexibly and finely adjusted at the frame level to ensure the encoding quality of the subsequent video frames and guarantee the video frame image quality of the video encoding.
  • FIG. 2 is a flowchart illustrating the steps of the video encoding method provided in this embodiment
  • this embodiment takes the video encoding device being integrated into a server as an example.
  • the processor on the server executes the program instructions corresponding to the video encoding method, the specific process is as follows:
  • Video encoding can be understood as compressing video source data and transmitting the compressed data to the playback device for decoding and playback, so that the corresponding video image is displayed on the playback page. It's important to note that video stream data is organized and transmitted in the form of a frame sequence. Video encoding involves encoding the video frames in the frame sequence using a video encoder. The video encoder has a bitrate; that is, when encoding the video frames in the frame sequence, the encoder encodes them according to the bitrate. This means that the video frames in the frame sequence are compressed sequentially according to the bitrate, so that the bitrate of each compressed frame is lower than the bitrate before compression, resulting in a video file corresponding to the sequence. This can be understood as video segments, allowing for transmission to the playback device with less communication bandwidth.
  • a video encoder is an application used to compress and convert video signals into digital formats. Its main function is to reduce the size of video files through compression technology, thus requiring less bandwidth and storage space during network transmission or storage.
  • a video encoder can convert raw video signals into various digital formats, such as H.264, MPEG-4, AVC, and VP9.
  • the functions of a video encoder include compressing video data, changing video formats, and adjusting image quality. It takes multiple input signals (such as HDMI, SDI, IP video, etc.) and encodes these signals into compressed digital formats, such as H.264 or H.265, which require less bandwidth for transmission and storage. Further, the data is transmitted over the network to a backend monitoring center, where it is decoded by corresponding decoding software or hardware running on the terminal.
  • the content of different video frames may differ, which can be understood as varying levels of content richness or complexity.
  • Video frames with richer content typically require more memory than those with simpler content. Therefore, during encoding at a uniform bitrate, simpler video frames tend to have better image quality after encoding, while more content-rich frames tend to have lower image quality.
  • the bitrate of the video encoder can be adjusted to reduce the lower image quality of more content-rich frames after encoding.
  • the encoding bitrate can be defined as the number of bits of information transmitted per second, and can be expressed in kilobits per second (kbps) or megabits per second (mbps). Specifically, the bitrate is the number of bits of data or data throughput transmitted per unit of time, reflecting the transmission speed and quality of video data. During video encoding, the encoding bitrate can be controlled to optimize video quality and file size.
  • the bitrate can be adjusted based on the source video bitrate.
  • Related technologies periodically acquire the source video bitrate for fixed durations (e.g., 1 second, 3 seconds, etc.) and adjust the encoder bitrate accordingly.
  • adjusting the bitrate based on a fixed-duration bitrate results in a fixed bitrate with coarse granularity. Since real-time video sequences contain multiple frames with varying complexity, using a coarse bitrate can cause more complex frames to become blurry and of poor quality after encoding.
  • the video bitrate refers to the number of bits transmitted per second in the source video, expressed in kilobits per second (kbps) or megabits per second (mbps).
  • kbps kilobits per second
  • mbps megabits per second
  • a higher bitrate indicates a larger amount of data transmitted per unit of time, resulting in higher video precision and quality, and a clearer picture.
  • Bitrate is one of the important factors determining video file size and image quality; at the same resolution, a higher bitrate results in a larger video file size and better image quality.
  • the acquisition granularity of the video source bitrate is reduced to acquire the video source bitrate of the target video source, so as to synchronously adjust the encoding bitrate of the video encoder, thereby achieving a more precise adjustment of the encoding bitrate of the video encoder, which serves as the base bitrate for video encoding and has reliability.
  • the target video source can be a real-time transmitted video source, which can be understood as the video signal source or video source end, providing real-time streaming data.
  • a real-time transmitted video source which can be understood as the video signal source or video source end, providing real-time streaming data.
  • it could be the streaming data of video frames uploaded and transmitted from the broadcaster's end to the server in a live video broadcast (i.e., the signal source); it could also be the streaming data of video frames read and loaded in real-time from other platforms or databases by the server in a video-on-demand scenario; or it could be the audio and video streaming data in an audio-visual call scenario, and so on.
  • the video source bitrate can be determined based on the interval between key video frames in the target video source, so that the encoding bitrate of the video encoder can be updated synchronously according to the video source bitrate.
  • step 101 may include: obtaining the current video source bitrate of the target video source; and updating the encoding bitrate of the video encoder synchronously according to the video source bitrate.
  • the encoding bitrate of the video encoder is adjustable.
  • the real-time encoding bitrate of the video encoder can be adjusted based on the interval between two adjacent key video frames of the target video source.
  • the video frame stream data of the target video source can be organized and transmitted to the server in the form of a video frame sequence.
  • This video frame sequence can include different types of video frames, such as key video frames (Intra-coded Frames, I-frames), predicted frames (P-frames), and bi-directional predicted frames (B-frames).
  • the video source bitrate between two key frames can be statistically determined based on the interval between them (group of pictures, GOP).
  • the frame rate of the target video source is determined, and the interval between two adjacent key video frames in the transmission sequence of the target video source is detected in real time, such as the interval length or interval duration.
  • the video source bitrate is calculated based on the interval between the two adjacent key video frames and the frame rate, for example, by determining the video source bitrate based on the ratio between the frame rate and the interval.
  • the encoding bitrate in the video encoder is updated synchronously based on the video source bitrate, ensuring that the current encoding bitrate is compatible with the sequence of frames to be encoded between the current two keyframes in the video frame sequence—essentially, a subsequence or segment sequence.
  • the real-time video source bitrate is determined by using the interval between keyframes. This bitrate serves as the base bitrate for the video encoder, better meeting the encoding bitrate requirements of each video frame sequence, offering both flexibility and reliability.
  • the encoding bitrate can be real-time.
  • the current encoding bitrate of the video encoder can be the initial encoding bitrate that is synchronously updated based on the video source bitrate, or it can be the historical encoding bitrate used when encoding the previous video frame during the video encoding process, depending on the actual situation.
  • the "previous video frame” can refer to "a video frame in the sequence of frames to be encoded” in this embodiment. The “sequence of frames to be encoded” will be described in detail later and will not be discussed here.
  • the real-time encoding bitrate of the video encoder can be obtained, which can be used as the base bitrate for video encoding to better match the encoding bitrate requirements of each video frame sequence, and also has reliability.
  • the sequence of frames to be encoded corresponding to the target video source can be obtained.
  • the video encoder can then start encoding the video frames in the sequence of frames to be encoded according to the current encoding bitrate. Since the encoding process of the video encoder can be frame-by-frame, the first video frame in the sequence of frames to be encoded can be encoded according to the encoding bitrate to compress the video frames, increase the data transmission rate per unit time under a specific bandwidth, and ensure the smoothness of video playback at the playback end.
  • the frame sequence to be encoded can be a sub-sequence or a sequence segment transmitted in real time by the target video source. Specifically, all video frames provided by the target video source are transmitted as a video frame sequence.
  • the frame sequence to be encoded can be a sub-sequence of the entire video frame sequence. For example, it can be a sequence consisting of two currently adjacent key video frames and non-key video frames located between these two key video frames (such as the aforementioned forward prediction frames and/or bidirectional prediction frames), or it can be a sequence consisting of multiple key video frames and non-key video frames. There is no limitation here.
  • the first video frame can refer to the first video frame in the current sequence of frames to be encoded. It should be noted that this first video frame refers to the first frame in the sub-sequence currently being transmitted by the target video source; that is, the first frame is different at different times during the video encoding process, depending on the real-time sequence of frames to be encoded. Therefore, the first video frame can be the first frame of the entire video frame sequence corresponding to the target video source, or it can be a frame in the middle of the video frame sequence; there is no limitation here.
  • the type of the first video frame can be a key video frame.
  • the server when performing video encoding, can simultaneously receive and acquire video frame stream data from the target video source and encode the real-time acquired video frame stream data. Assuming the video frame stream data is transmitted in sequence, the server can sequentially receive and acquire each sequence of frames to be encoded from the target video source and encode the video frames in each sequence sequentially. Therefore, the encoding process of the target video source's video stream data is performed in real-time.
  • the video encoder uses the current encoding bitrate as the base bitrate, that is, it starts encoding the first video frame in the sequence of frames to be encoded according to the current real-time encoding bitrate.
  • the target video source can be understood as the live video source of the broadcaster.
  • the server obtains the live frame sequence from the broadcaster in real time.
  • the video encoder uses the current real-time encoding bitrate as the basis and starts to encode the first live frame in the frame sequence to be encoded according to the encoding bitrate to obtain encoded stream data for subsequent transmission to the viewer.
  • the target video source can be understood as the target video stream data loaded in real time from a video database or other server.
  • This real-time loaded target video stream data is transmitted to the server in sequence.
  • the server obtains the sequence of frames to be encoded from the target video stream data in real time.
  • the video encoder uses the current real-time encoding bitrate as a basis and starts encoding the first target video frame in the sequence of frames to be encoded according to the encoding bitrate to obtain the encoded stream data for subsequent transmission to the playback end.
  • the sequence of frames to be encoded corresponding to the target video source can be obtained.
  • the current encoding bitrate of the video encoder is used as the base bitrate.
  • the video encoder starts encoding the video frames in the sequence of frames to be encoded according to the current encoding bitrate, thereby compressing the video frames, increasing the data transmission rate per unit time under a specific bandwidth, and ensuring the smoothness of video playback on the playback end.
  • the complexity of the video frame corresponding to the current encoding progress and the complexity of the previous video frame can be determined.
  • the complexity comparison between the current video frame and the previous video frame can be used to determine whether the video frame corresponding to the current encoding progress is more complex than the previous video frame, thereby deciding whether to adjust the encoding bitrate of the video encoder, which has reliability.
  • this application embodiment in representing the complexity of video frames in this application embodiment, it can be described through the constituent elements and/or grayscale changes of the video frame. For example, it can be described using algorithms such as Euclidean distance, statistical histograms, Local Binary Pattern (LBP) detection algorithms, and Convolutional Neural Networks (CNN) feature extraction and classification.
  • LBP Local Binary Pattern
  • CNN Convolutional Neural Networks
  • this application embodiment will use a local binary pattern detection algorithm to represent the complexity of consecutive video frames.
  • the local binary pattern can refer to image texture to represent the complexity of the video frame.
  • the first video frame can be the video frame ready to be encoded corresponding to the current encoding progress in the frame sequence to be encoded
  • the second video frame can be the video frame preceding the first video frame currently ready to be encoded in the frame sequence to be encoded.
  • the second video frame is usually the video frame currently being encoded or has already been encoded, while the first video frame refers to the next video frame to be encoded. Therefore, the first video frame can be any video frame after the first video frame in the frame sequence to be encoded.
  • the first video frame can be the i-th video frame
  • the second video frame can be the (i-1)-th video frame, where i is greater than 1 and less than or equal to N.
  • the image texture value can be a parameter representing the texture features of a video frame, used to quantitatively or qualitatively describe the texture characteristics of the video frame.
  • the image texture value can be determined based on the analysis of texture features using important surface grayscale information in the video frame.
  • the texture feature is a value calculated from the video frame, used to quantify the characteristics of grayscale level changes within a region. Specifically, it is generated by calculating the grayscale co-occurrence matrix of the sub-image formed by each small window and the texture feature value. Therefore, the image texture value can not only reflect the visual complexity of an image but also serve as an important indicator for quantifying the complexity of image information.
  • the complexity of image information in the first video frame can be represented by the first image texture value
  • the complexity of image information in the second video frame can be represented by the second image texture value.
  • the image texture value can be a single numerical value or a matrix form, such as an image texture value represented as an image matrix containing three two-dimensional matrices (R, G, B), with values between 0 and 255, representing the depth of color.
  • the corresponding first image texture value can be determined based on the grayscale value of each first pixel in the first video frame. For example, "determining the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded" in step 103 may include:
  • the grayscale value can be the color depth of a pixel in a black and white image, that is, the color depth of each first pixel in the first video frame.
  • the grayscale value ranges from 0 to 255, with 255 for white and 0 for black.
  • the grayscale value represents the change in brightness from dark to light, corresponding to the color in the video frame from black to white. It can reflect the statistical characteristics and contrast of the video frame. It should be noted that the color value of each pixel in a grayscale image can be understood as grayscale, which refers to the color depth of a point in a black and white image.
  • the grayscale value corresponding to each first pixel in the first video frame can be obtained.
  • the grayscale value of each first pixel can be obtained by weighted averaging of the color values of the three color channels (red, green, and blue) to represent the contribution of the color values of the three color channels to the brightness; or, the color value of each first pixel in the three color channels can be determined, and the maximum/minimum value of the color values of the first pixel in the three color channels can be used as the grayscale value of the first pixel; the above grayscale value determination process is only an example and is not intended as a specific limitation.
  • the first image texture value of the first video frame is determined based on the grayscale value of each first pixel.
  • the second image texture value of the second video frame can be determined in the same way as above. Based on this, the relationship between the first and second image texture values can be used to determine whether the first video frame is more complex than the previous video frame (i.e., the second video frame), so as to adjust the bitrate for video encoding.
  • the first image texture value can be generated not only based on all area information of the first video frame, but also based on the grayscale values of the target area information, target object information and/or target object information in the first video frame; similarly, the second image texture value can be determined based on the grayscale values of the target area information, target object information and/or target object information in the second video frame.
  • the image texture values can be calculated based on the grayscale values of pixels within the target image region in the video frame.
  • the target image region can be the image region corresponding to a specific object or the image region of a fixed area.
  • a target mask image is obtained.
  • the target mask image is an image that displays the pixels of the target image region in the first video frame.
  • the first video frame is masked according to the target mask image to obtain the processed target first video frame.
  • the target first video frame only displays the content within the target image region.
  • the gray value of each first pixel in the target first video frame is obtained so as to calculate the first image texture value of the target first video frame based on the gray value of each first pixel.
  • image texture value calculation based on this can specifically describe the key texture features of the target image region in the video frame, improving the computational efficiency of texture complexity.
  • image frames such as forward prediction video frames or bidirectional prediction video frames that have removed redundant image information
  • this calculation of image texture value according to the mask method is particularly meaningful. It enables the rapid location of the content difference region between the first and second video frames, and uses the explicit difference information of this content difference region as the main basis for image texture value calculation, reducing the computational load in the image texture value calculation process and ensuring reliability.
  • the local texture value of each video frame sub-region can be determined first based on the grayscale value of the first pixel within each video frame sub-region in the first video frame, and then the first image texture value of the first video frame can be determined by combining the local texture values of each video frame sub-region.
  • step (103.2) may include:
  • the first pixel in the first video frame is divided to obtain multiple target local regions
  • the target local texture window can be understood as a neighborhood region of a specific size, such as a region of 3 pixels by 3 pixels. Specifically, the target local texture window can be understood as the coverage area of the operator in the local binary mode algorithm.
  • the gray value of the first pixel located at the center of the window is used as the gray value judgment threshold of the current target local texture window.
  • the gray values of adjacent pixels are compared with the threshold. If the gray value of the surrounding pixels is greater than the gray value of the first pixel at the center, the position of the pixel is marked or assigned a value of 1; otherwise, it is assigned a value of 0.
  • the target local region can be a sub-region of an image in the first video frame, i.e., a sub-region of the video frame. It can be understood that the first video frame can be divided into multiple target local regions by dividing the first pixels according to the size of the target local texture window.
  • the size of each target local region is the same as the size of the target local texture window. For example, taking the target local region of the first video frame as an example, if the target local texture window is a 3-pixel by 3-pixel range window, then each target local region consists of 3 first pixels in both length and width, meaning one target local region includes 9 first pixels.
  • the target local texture window is a 4-pixel by 4-pixel range window, one target local region contains 16 first pixels; and if it is a 5-pixel by 5-pixel range window, the target local region contains 25 first pixels.
  • the first image texture value of the first video frame it can be calculated based on the first local texture values of multiple regions within the first video frame. Specifically, a target local texture window can be obtained first, and the first video frame can be divided according to the size of the target local texture window, thus dividing the first video frame into multiple target local regions of uniform size. Further, after determining each target local region in the first video frame, for each target local region, the first local texture value corresponding to that target local region can be determined based on the grayscale value of the first pixel contained within that target local region. This first local texture value can be understood as the texture feature value of the first pixel at the center position of the target local region.
  • the first image texture value of the first video frame is obtained by summarizing the first local texture values corresponding to each target local region.
  • the calculation process can be a weighted calculation or a concatenation method; no limitation is made here. Therefore, the local texture value of each video frame sub-region can be determined based on the grayscale value of the first pixel in each video frame sub-region in the first video frame, and the first image texture value of the first video frame can be determined by combining the local texture values of each video frame sub-region, so as to be used for the comparison of complexity between the first video frame and the second video frame in the future, thereby improving the accuracy of video frame complexity comparison and having reliability.
  • step (103.2.4) may include: determining the central first pixel and the edge first pixels surrounding the central first pixel within each target local region; comparing the grayscale value of each edge first pixel with the grayscale value of the central first pixel for each target local region to obtain multiple comparison results for each target local region; and performing binarization processing on the multiple comparison results for each target local region to obtain the first local texture value corresponding to each target local region.
  • the central first pixel can be the pixel located at the center of the corresponding target local region in the first video frame, while the edge first pixels are the other pixels within the corresponding target local region that are located around the central first pixel.
  • the target local region is the image region corresponding to a target local texture window of size 3 pixels by 3 pixels
  • the target local region contains 9 first pixels.
  • the pixel located at the center is the central first pixel
  • the other 8 pixels located around the central first pixel are all edge first pixels.
  • the central first pixel and the edge first pixel are considered in relation to a single target local region.
  • Each target local region in the first video frame has its own central first pixel and edge first pixels.
  • the first pixel located at the center of the target local region can be determined as the central first pixel, and other first pixels located around the central first pixel can be determined as edge first pixels; then, the gray value of the central first pixel is used as the gray value reference value or gray value threshold, and the gray value of each edge first pixel is compared with the gray value reference value of the center to obtain the gray value comparison result of each edge first pixel relative to the central first pixel; finally, based on the multiple gray value comparison results, a binarization transformation is performed to obtain the first local texture value of the target local region.
  • each target local region is an image region corresponding to a target local texture window of size 3 pixels by 3 pixels
  • each target local region contains 9 first pixels: 1 central first pixel and 8 edge first pixels.
  • the grayscale value of the central first pixel is 83
  • the grayscale values of the surrounding 8 edge first pixels are 44, 118, 192, 204, 250, 174, 61, and 32 respectively.
  • the grayscale value is compared with the grayscale value of the central first pixel, resulting in 8 grayscale comparison results. Each grayscale comparison result is then binarized.
  • the grayscale value of the edge first pixel is greater than that of the central first pixel, it is assigned a value of 1 after binarization. If the grayscale value of the edge first pixel is less than or equal to that of the central first pixel... If the grayscale value is 0, then the value is assigned to 0. Therefore, for the above 8 grayscale comparison results, after binarization conversion, the values are assigned to 0, 1, 1, 1, 1, 1, 0, 0 (clockwise order), which is represented by the 8-bit binary number 01111100.
  • the image texture value is represented by 8 bits. For the first image texture value of each target local area, there can be 256 different results.
  • the first image texture value of the target local area in binary form is converted to decimal form and represented as 124. Both the binary number "01111100" and the decimal number "124" can represent the first image texture value corresponding to the target local area.
  • the central pixel combination area can be regarded as a whole, i.e., as the "central pixel".
  • the central first pixel combination area contains multiple first pixels located in the center of the target local region, and other first pixels in the target local region located outside the central first pixel combination area are regarded as edge first pixels.
  • the gray value of the central first pixel combination region can be determined based on the gray values of multiple pixels within the central first pixel combination region, or defined as the "target gray value of the central first pixel combination region".
  • a weighted average of the gray values of multiple first pixels within the central first pixel combination region is then performed to obtain the target gray value corresponding to the central first pixel combination region.
  • the gray value of each edge pixel is compared with the target gray value corresponding to the central pixel combination region to obtain multiple gray-level comparison results. Finally, by binarizing these multiple gray-level comparison results, the first local texture value corresponding to the target local region is obtained.
  • each target local region is an image region corresponding to a target local texture window of size 4 pixels by 4 pixels, then the region contains 16 first pixels.
  • the four first pixels in the "2 pixels by 2 pixels" area located at the center of the target local region can be taken as the central first pixel combination area.
  • the target gray value of the central first pixel combination area is determined. For example, by taking a weighted average of the gray values of these four first pixels, or by taking the maximum or minimum value among the gray values of these four first pixels, as the target gray value of the central first pixel combination area.
  • the 12 edge first pixels in the target local region located around the central first pixel combination area are compared with the target gray value of the central first pixel combination area to obtain 12 gray comparison results.
  • the first local texture value corresponding to the target local region is obtained.
  • target local area can be divided according to the target local texture window of other specifications and sizes.
  • the implementation process can be referred to the above examples, and will not be described in detail here.
  • the size parameters of the local texture window used to divide the local region of the video frame can be adjusted before calculating the image texture value, so as to obtain the target local texture window after adjustment.
  • step (103.2.1) may include: obtaining candidate local texture windows and determining the candidate window range value of the candidate local texture window; obtaining the target available resource amount of image computing power resources, and querying the window range list according to the target available resource amount to obtain the target window range value, wherein the window range list includes the correlation between different available resource amounts and window range values; when the candidate window range value is less than the target window range value, adjusting the candidate local texture window according to the target window range value to obtain the target local texture window; when the candidate window range value is greater than or equal to the target window range value, determining the candidate local texture window as the target local texture window.
  • the candidate local texture window can be a neighborhood region of a pre-set size range, which can be understood as the default operator coverage range of the local binarization mode algorithm.
  • the size of the candidate local texture window is a neighborhood range of 3 pixels by 3 pixels.
  • the image computing resources can be one or more of the computing resources used for image processing in the server, such as the central processing unit (CPU), graphics processing unit (GPU), memory, cache, etc. These computing resources affect the efficiency of calculating image texture values.
  • the target available resource quantity can be the available quantity of any one or more of the above computing resources, for example, the available quantity of GPU computing resources.
  • the window range list can be a list of available resource quantities and window range values for one or more image computing resources. Specifically, it includes the association between the available resource quantities and window range values of one or more types of image computing resources. It should be noted that the server will monitor the remaining available resource quantity of local image computing resources in real time and synchronously update the available resource scalar of the corresponding type of image computing resources in the window range list according to the remaining available resource quantity.
  • the default candidate local texture window corresponding to the local binarization mode algorithm is obtained, and the candidate window range value is determined, which represents the size of the candidate local texture window.
  • the target available resource amount of the image computing power resources on the server is obtained, and the window range list is queried according to the target available resource amount to determine the target window range value that matches the target available resource amount of the current image computing power resources.
  • the target window range value is compared with the candidate window range value. If the target window range value is greater than the candidate window range value, the size of the candidate local texture window is adjusted according to the target window range value to obtain the adjusted target local texture window.
  • the candidate local texture window is directly used as the target local texture window. Therefore, a texture window with a larger coverage area can be selected as the target local texture window. This will reduce the number of windows (i.e., "target local regions") when dividing the video frame into multiple target local regions according to the target local texture window. This will reduce the amount of computation required to calculate the image texture value, improve the efficiency of image texture value calculation, and effectively avoid delays in adjusting the encoding bitrate of the video encoder due to the image texture value calculation process, thus affecting the video encoding progress and efficiency. This method is reliable.
  • the resolution of any "video frame" in this embodiment can also be reduced to decrease the computational load of image texture values, thereby improving the computational efficiency of image texture values for video frames. It should be noted that reducing the image resolution of the video frame can reduce the computational load, and on this basis, further combining this with an enlarged target local texture window can further reduce the computational load of image texture values for video frames, thereby further improving the computational efficiency of image texture values. This effectively avoids delays in subsequent video encoding efficiency due to the image texture value calculation process, ensuring reliability.
  • the resolution of the first video frame can be reduced by downsampling, so that subsequent image texture value calculations can be performed based on the downsampled first video frame, thereby improving the computational efficiency of image texture values.
  • the following steps may be included: obtaining the image resolution information corresponding to the first video frame currently to be encoded in the frame sequence to be encoded; performing downsampling processing on the first video frame based on the image resolution information to obtain the downsampled first video frame; then before step (103.1), the following steps may also be included: obtaining the grayscale value of each first pixel in the downsampled first video frame.
  • the image resolution information can be expressed as the amount of information contained in a video frame, represented by the number of pixels.
  • image resolution information can represent the number of pixels contained in a video frame per unit length (e.g., per inch), that is, the number of pixels contained in the video frame in both the length and width dimensions. It can be understood that image resolution information determines the level of detail in a video frame; the higher the resolution, the clearer the image.
  • pixel downsampling can reduce the computational load on the image texture value of the first video frame.
  • the image resolution information of the first video frame can be obtained. This image resolution information represents the distribution and number of first pixels contained in the first video frame. Then, the pixel value corresponding to each first pixel in the first video frame is obtained. Based on the distribution of each first pixel in the first video frame as reflected by the image resolution information, downsampling is performed according to the size relationship of each first pixel value.
  • the first pixel with the largest pixel value in each first pixel area is used.
  • the downsampled first video frame is obtained.
  • the grayscale value of each first pixel in the downsampled first video frame is obtained so that the first image texture value of the first video frame can be determined subsequently based on the grayscale value of each first pixel in the downsampled first video frame.
  • the encoding bitrate used by the video encoder when encoding the previous video frame will continue to be used to encode the current video frame.
  • the image quality of the currently encoded video frame will be similar to that of the previous video frame. Therefore, if the difference between the first video frame and the second video frame in the frame sequence to be encoded is too small, even if the texture complexity of the first video frame is greater than that of the second video frame, the encoding bitrate of the video encoder will not be adjusted. Instead, the encoding bitrate used by the video encoder when encoding the second video frame will be used to encode the first video frame. This reduces the frequency of bitrate adjustments during video encoding, thereby minimizing the bandwidth consumption of the encoded video frame stream data transmission.
  • the similarity between the first video frame to be encoded and the second video frame that has already been encoded can be determined first. If the similarity is less than a certain threshold, the first image texture value of the first video frame is determined to determine the texture complexity of the first video frame. For example, before step 103, the following may also be included:
  • step 103 may include: when the similarity is less than a preset similarity threshold, determining the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded.
  • the preset similarity threshold can be used to determine the similarity between a first video frame to be encoded and a previously encoded second video frame, thereby determining the degree of difference between the first and second video frames.
  • a higher similarity threshold indicates a smaller difference between the first and second video frames, and vice versa.
  • This preset similarity threshold is used to determine the difference between the first and second video frames, deciding whether to determine the image texture values of both frames, and thus further adjusting the encoding bitrate of the video encoder.
  • HSV Hue Saturation Value
  • histogram statistics histogram statistics
  • hash similarity statistics can be used. Any of these algorithms can be employed to determine the similarity between the first video frame (currently being encoded) and the second video frame (already encoded) in the sequence of frames to be encoded. Furthermore, after determining the similarity between the first and second video frames, this similarity is compared with a preset similarity threshold.
  • the similarity between the first video frame and the second video frame is less than the preset similarity threshold, it indicates that the difference between the first video frame and the second video frame is too large.
  • the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded is determined, and the second image texture value of the second video frame adjacent to the first video frame is determined, so that the encoding bitrate of the video encoder can be adjusted when the first image texture value is greater than the second image texture value.
  • the video encoder encodes the first video frame currently to be encoded in the frame sequence to be encoded according to the current encoding bitrate (i.e. the encoding bitrate when encoding the second video frame).
  • a histogram statistical algorithm is used to calculate the color similarity between the first video frame and the second video frame.
  • the similarity includes color similarity
  • step (103.a) may include:
  • the first pixel value refers to the pixel value of the corresponding first pixel point in the first video frame
  • the second pixel point refers to the pixel value of the corresponding second pixel point in the second video frame
  • the first histogram is used to count the number of first pixels corresponding to each pixel value dimension of the first video frame.
  • the width of the first histogram can include 256 pixel value dimensions, that is, pixel values from 0 to 255.
  • Each bar in the first histogram corresponds to a target pixel value, and the height of the bar represents the count of first pixels corresponding to that target pixel value in the first video.
  • This first histogram can reflect the color characteristics of the first video frame.
  • the second histogram is used to count the number of second pixels corresponding to each pixel value dimension of the second video frame.
  • the width of the second histogram can include 256 pixel value dimensions, that is, pixel values from 0 to 255. This second histogram can reflect the color characteristics of the second video frame.
  • Color similarity can represent the degree of similarity in color between the first video frame and the second video frame, and also reflects the color difference between the first video frame and the second video frame.
  • the first pixel value of each first pixel in the first video frame is obtained, and the number of first pixels corresponding to each first pixel value dimension is counted.
  • Each first pixel value dimension is used as the width (i.e., the horizontal axis value) of the histogram, and the number of first pixels corresponding to each first pixel value dimension is used as the height of the corresponding bar in the histogram, generating a first histogram for the first video frame to represent its color characteristics.
  • a second histogram corresponding to the second video frame is obtained.
  • the generation process of this second histogram can refer to that of the first histogram; if it has already been generated in a historical timeframe, the second histogram corresponding to the second video frame can be directly obtained. Further, based on the differences between the first and second histograms in each pixel value dimension, the color similarity between the first and second video frames is calculated. In this way, color similarity is used to evaluate the degree of difference in color features between the first video frame and the second video frame, so as to make subsequent decisions on whether to adjust the encoding bitrate of the video encoder based on the texture difference between the first video frame and the second video frame.
  • step (103.a.3) may include: determining a first statistic of the first video frame in each pixel value dimension based on the first histogram, and determining a second statistic of the second video frame in each pixel value dimension based on the second histogram; determining the difference in the number of pixels in each pixel value dimension between the first video frame and the second video frame based on the first and second statistics in each pixel value dimension; and determining the color similarity between the first video frame and the second video frame based on the difference in the number of pixels in each pixel value dimension.
  • the first statistic can be the number of first pixels corresponding to the first pixel value dimension in the first histogram, while the second statistic is the number of second pixels corresponding to the second pixel value dimension in the second histogram.
  • the pixel count difference refers to the difference in the number of pixels in the same pixel value dimension between the first histogram and the second histogram. For example, if the first histogram has 60 pixels with a value of 100 and the second histogram has 70 pixels with a value of 100, then the pixel count difference in the dimension with a pixel value of 100 is 30.
  • the process is as follows: First, the maximum value between the first and second statistics in that pixel value dimension is obtained as the target value. Then, for each pixel value dimension, a target ratio between the difference in the number of pixels and the target value is determined. This target ratio represents the proportion of difference between the first and second video frames in the current pixel value dimension, i.e., the degree of difference. The highest similarity is 1. By subtracting the target ratio from 1, the color sub-similarity between the first and second video frames in the current pixel value dimension is obtained. Finally, the color sub-similarity values in each pixel value dimension are summed and averaged to obtain the overall color similarity.
  • the complexity of the video frame corresponding to the current encoding progress and the complexity of the previous video frame can be determined during the video frame encoding process. This allows for the adjustment of the video encoder's bitrate according to frame-level decisions when it is determined that the texture complexity of the current video frame increases relative to the previous video frame, thus meeting the image quality requirements of the current video frame and ensuring reliability.
  • the image texture ratio is determined based on the first image texture value and the second image texture value.
  • the texture complexity indicated by the first and second image texture values is compared.
  • This comparison of texture complexity between the first and second video frames helps determine whether to adjust the encoding bitrate of the video encoder. Given that a larger image texture value corresponds to greater texture complexity of the video frame, on the one hand, when the first image texture value is greater than the second image texture value, the encoding bitrate of the video encoder is adjusted; on the other hand, when the first image texture value is less than or equal to the second image texture value, the encoding bitrate of the video encoder is not adjusted. This ensures that the encoding bitrate of the video encoder can meet the image quality requirements of the encoded video frame for the first video frame being encoded, thus ensuring reliability.
  • the image texture ratio can be a ratio representing the texture complexity of the first video frame relative to the second video frame. It can be understood that when the texture complexity of the first video frame is greater than that of the second video frame, the image texture ratio is greater than 1, indicating that the first video frame is more complex than the second video frame.
  • the ratio between the first and second image texture values can be determined as the image texture ratio between the first and second video frames. This ratio allows for subsequent adjustments to the video encoder's bitrate, specifically adjusting the bitrate used when encoding the second video frame. This ensures that the adjusted bitrate meets the image quality requirements of the encoded first video frame, while reducing the bandwidth consumption of the video frame stream and improving reliability.
  • an image texture ratio can be calculated based on the significant difference in texture complexity between the first and second video frames. This ratio can then be used to adjust the video encoder's bitrate subsequently.
  • step 104 "determining the image texture ratio based on the first and second image texture values," can include: obtaining the image texture difference between the first and second image texture values; and calculating the image texture ratio between the first and second image texture values when the image texture difference is greater than a preset texture difference threshold.
  • the image texture difference can represent the degree of texture difference between the first video frame and the second video frame. Specifically, the texture difference is determined based on the texture values of the first and second images. If the image texture difference is larger, it means that the texture difference between the first and second video frames is larger. Conversely, if the image texture difference is smaller, it means that the texture difference between the first and second video frames is smaller.
  • the first image texture value is compared with the second image texture value.
  • the first image texture value is greater than the second image texture value, it means that the image texture of the first video frame to be encoded is more complex than the image texture of the previously encoded second video frame. If the difference in image texture complexity between the first video frame and the second video frame is small, the encoding bitrate used by the video encoder when encoding the second video frame can be used to encode the first video frame. This has little impact on the image quality of the first video frame and can reduce the amount of transmission bandwidth resources consumed.
  • the image texture difference between the first and second image texture values can be determined and compared with a preset texture difference threshold.
  • This preset texture difference threshold is used to determine the degree of difference between the first video frame to be encoded and the previously encoded second video frame.
  • the image texture difference is greater than the preset texture difference threshold, it indicates that the difference between the first and second video frames is large, and the previous encoding bitrate of the video frame encoder cannot meet the image quality requirements of the first video frame.
  • the image texture ratio between the first and second image texture values it is necessary to determine the image texture ratio between the first and second image texture values so that the previous encoding bitrate of the video encoder can be increased according to the image texture ratio.
  • the image texture difference is less than or equal to the preset texture difference threshold, it indicates that the difference between the first and second video frames is small, and the previous encoding bitrate of the video encoder does not need to be increased.
  • the encoding bitrate used when encoding the second video frame can continue to be used for encoding the first video frame. This reduces the frequency of adjusting the encoding bitrate of the video encoder and also reduces the amount of transmission bandwidth resources required.
  • the comparison result of texture complexity between the first video frame and the second video frame can be determined.
  • the decision is made to adjust the encoding bitrate of the video encoder according to the image texture ratio between the first video frame and the second video frame, so as to realize the adjustment of the encoding bitrate of the video encoder according to the frame level, and achieve more fine-grained and precise adjustment of the encoding bitrate of the video encoder.
  • the previous encoding bitrate of the video encoder can be adjusted according to the image texture ratio. Since the encoding bitrate of the video encoder may be adjusted in real time during the encoding of the preceding video frames in the frame sequence to be encoded, the current encoding bitrate of the video encoder can be understood as the encoding bitrate used when encoding the second video frame. Therefore, adjusting the previous encoding bitrate of the video encoder according to the image texture ratio makes the adjustment range of the video encoder's encoding bitrate match the ratio of the texture complexity difference between the preceding and following video frames.
  • the target encoding bitrate can be the encoding bitrate that has been re-determined after the video encoder has been adjusted. This target encoding bitrate can be obtained by adjusting the previous encoding bitrate according to the image texture ratio. It is used to encode the first video frame in order to cope with the encoding of the first video frame with rich image content and complex information, and to ensure the image quality of the first video frame after encoding.
  • the bitrate of the video encoder is adjusted based on the image-texture ratio, and the adjusted bitrate is compared with the limited bitrate of the video encoder to determine the final target bitrate of the video encoder.
  • step 105 "adjusting the bitrate of the video encoder based on the image-texture ratio to obtain the target bitrate,” may include: obtaining an upper limit value for the bitrate of the video encoder; weighting the bitrate based on the image-texture ratio to obtain candidate bitrates; when the upper limit value is greater than the candidate bitrates, adjusting the bitrate of the video encoder according to the candidate bitrates to obtain the target bitrate; when the upper limit value is less than the candidate bitrates, adjusting the bitrate of the video encoder according to the upper limit value to obtain the target bitrate.
  • the upper limit of the encoding bitrate can be the bitrate limit of the video encoder, which can be understood as the maximum encoding bitrate of the video encoder.
  • This upper limit of the encoding bitrate can be set according to the available bandwidth resources or the expected target bandwidth resources, so that the maximum encoding bitrate cannot exceed the upper limit of the encoding bitrate during the bitrate adjustment (i.e., bitrate control) process. In this way, the video frame quality is maximized, and the encoded video frame stream is transmitted smoothly under the limited bandwidth resources, avoiding the phenomenon of video playback stuttering, and has reliability.
  • the current encoding bitrate of the video encoder is obtained, for example, the encoding bitrate used when encoding the second video frame, and the upper limit of the encoding bitrate for the video encoder is also obtained.
  • the encoding bitrate is weighted according to the image texture ratio, and the adjustment range is based on the proportion of texture complexity differences between consecutive video frames, increasing the encoding bitrate of the video encoder. This achieves frame-level adjustment of the video encoder's encoding bitrate, obtaining candidate encoding bitrates.
  • the upper limit of the video encoder's encoding bitrate is used as a bitrate adjustment limit threshold.
  • the adjusted candidate encoding bitrate is greater than or equal to the upper limit of the video encoder's encoding bitrate, then the upper limit of the video encoder's encoding bitrate is used as the target encoding bitrate. Conversely, if the adjusted candidate encoding bitrate is less than the upper limit of the video encoder's encoding bitrate, then the video encoder's encoding bitrate is adjusted according to the candidate encoding bitrate, i.e., the candidate encoding bitrate is used as the target encoding bitrate for the video encoder.
  • the video encoding process encodes video frames sequentially in the sequence of frames to be encoded. Other video frames following the first video frame in the sequence also need to be encoded according to the encoding process of the first video frame.
  • the process may further include: obtaining the third image texture value of a third video frame located after and adjacent to the first video frame in the sequence of frames to be encoded; when the third image texture value is detected to be greater than the first image texture value, determining the target image texture ratio between the third video frame and the first video frame; adjusting the target encoding bitrate of the video encoder according to the target image texture ratio to obtain the adjusted target encoding bitrate, and encoding the third video frame according to the adjusted target encoding bitrate; when the third image texture value is detected to be less than or equal to the first image texture value, encoding the third video frame according to the target encoding bitrate.
  • the third video frame can be a video frame in the frame sequence to be encoded that is temporally following the first video frame, i.e., the video frame after the first video frame.
  • the third image texture value can represent the image texture complexity of the third video frame. Assuming there are N temporally arranged video frames in the frame sequence to be encoded, the first video frame can be the i-th video frame, the second video frame can be the (i+1)-th video frame, where i is greater than 1 and less than N.
  • the next step is to encode the next frame (i.e., the third video frame).
  • the third image texture value of the third video frame can be determined and compared with the first image texture value.
  • the decision is made to adjust the encoding bitrate of the video encoder.
  • the ratio between the texture value of the third image and the texture value of the first image is calculated as the target image texture ratio between the third video frame and the first video frame.
  • the target encoding bitrate of the video encoder is adjusted according to the target image texture ratio. This target encoding bitrate is the bitrate of the video encoder when encoding the first video frame, and a target candidate encoding bitrate is obtained.
  • the target candidate encoding bitrate can also be compared with the upper limit of the encoding bitrate. If the target candidate encoding bitrate is greater than the upper limit of the encoding bitrate, the upper limit of the encoding bitrate is determined as the bitrate for encoding the third video frame, and the adjustment of the current encoding bitrate of the video encoder is rejected. If the target candidate encoding bitrate is less than the upper limit of the encoding bitrate, the target candidate encoding bitrate is used as the adjusted target encoding bitrate of the video encoder. Further, the third video frame is encoded by the video encoder according to the adjusted target encoding bitrate.
  • the target encoding bitrate previously used by the video encoder is used to encode the third video frame to ensure the quality of the video image after encoding, thus ensuring reliability.
  • the encoding bitrate of the video encoder can be adjusted according to the image texture ratio between consecutive video frames. This ensures that the adjustment range of the video encoder's encoding bitrate matches the ratio of the texture complexity differences between consecutive video frames. This allows for more delicate and precise adjustment of the video encoder's encoding bitrate at the frame level.
  • the current first video frame is then encoded according to the newly adjusted bitrate, maximizing bandwidth savings while ensuring the image quality of the encoded first video frame, thus providing reliability.
  • the embodiments of this application can obtain the current encoding bitrate of the video encoder; obtain the sequence of frames to be encoded of the target video source, and start encoding the first video frame in the sequence of frames to be encoded according to the encoding bitrate by the video encoder; determine the first image texture value of the first video frame currently to be encoded in the sequence of frames to be encoded, and determine the second image texture value of the second video frame adjacent to the first video frame, wherein the first video frame is any video frame after the first video frame; when the first image texture value is greater than the second image texture value, determine the image texture ratio according to the first image texture value and the second image texture value; adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encode the first video frame according to the target encoding bitrate.
  • this application can obtain the current encoding bitrate of the video encoder in real time, and then encode the video frames in the current frame sequence of the target video source according to the encoding bitrate. Furthermore, during the encoding process, the texture complexity between the first video frame to be encoded and the adjacent second video frame is compared in real time. Texture complexity represents the richness of the video frame's content to evaluate the required encoding bitrate. If the texture of the first video frame is more complex than the previous frame, the image texture ratio between the first and second video frames is determined based on the first and second image texture values. Finally, the encoding bitrate of the video encoder is adjusted to the target bitrate according to the image texture ratio.
  • the target encoding bitrate is set so that the video encoder encodes the first video frame according to the adjusted target encoding bitrate.
  • this application can compare the texture complexity between the preceding and following video frames during the encoding process of the target video source's frame sequence.
  • the encoding bitrate of the video encoder is adjusted according to the texture ratio between the preceding and following video frames. In this way, the encoding bitrate of the video encoder can be flexibly and finely adjusted at the frame level to ensure the encoding quality of the following video frames and guarantee the video frame image quality of the video encoding.
  • FIG 4 is a schematic flowchart of another step of the video encoding method provided in this application embodiment. For ease of understanding, this application embodiment is described in conjunction with Figure 4.
  • the description will focus on a video encoding device, which can be integrated into a computer device such as a terminal or server.
  • a video encoding device which can be integrated into a computer device such as a terminal or server.
  • the processor on the computer device executes the program corresponding to the video encoding method
  • the specific flow of the video encoding method is as follows:
  • the encoding bitrate of the video encoder is adjustable.
  • the bitrate can be adjusted based on the source video bitrate, resulting in better image quality for more complex video frames after encoding. Specifically, this can be achieved by reducing the granularity of the source video bitrate acquisition to acquire the source video bitrate of the target video source and simultaneously adjusting the encoding bitrate of the video encoder. This allows for finer adjustments to the encoding bitrate of the video encoder, serving as a reliable base bitrate for video encoding.
  • the bitrate of the target video source can be determined based on the interval between two adjacent key video frames, thereby adjusting the encoding bitrate of the video encoder.
  • the video frame stream data of the target video source can be organized and transmitted to the server in the form of a video frame sequence.
  • This sequence can include different types of video frames, such as key video frames (Intra-coded Frames, I-frames), predicted frames (P-frames), and bi-directional predicted frames (B-frames).
  • the bitrate between two key frames can be statistically determined based on the interval between them (group of pictures, GOP).
  • the frame rate of the target video source is determined, and the interval between two adjacent key video frames in the transmission sequence of the target video source is detected in real time, such as the interval length or interval duration.
  • the video source bitrate is calculated based on the interval between the two adjacent key video frames and the frame rate, for example, by determining the video source bitrate based on the ratio between the frame rate and the interval.
  • the encoding bitrate in the video encoder is synchronously updated according to the video source bitrate, so that the current encoding bitrate can adapt to the sequence of frames to be encoded between the current two key frames in the video frame sequence, which can be understood as a sub-sequence or segment sequence.
  • the video source bitrate in the real-time stage is determined by using the interval between key frames as the base bitrate for encoding by the video encoder, which better matches the encoding bitrate requirements of each video frame sequence, providing flexibility and reliability.
  • the sequence of frames to be encoded corresponding to the target video source can be obtained.
  • the video encoder can then start encoding the video frames in the sequence of frames to be encoded according to the current encoding bitrate. Since the encoding process of the video encoder can be frame-by-frame, the first video frame in the sequence of frames to be encoded can be encoded according to the encoding bitrate to compress the video frames, increase the data transmission rate per unit time under a specific bandwidth, and ensure the smoothness of video playback at the playback end.
  • the server when it performs video encoding, it can simultaneously receive and acquire video frame stream data from the target video source and encode the acquired video frame stream data in real time. Assuming the video frame stream data is transmitted in sequence, the server can sequentially receive and acquire each sequence of frames to be encoded from the target video source and encode the video frames in each sequence sequentially. Therefore, the encoding process of the target video source's video stream data is performed in real time.
  • the video encoder uses the current encoding bitrate as the base bitrate, that is, it starts encoding the first video frame in the sequence of frames to be encoded according to the current real-time encoding bitrate.
  • the encoding bitrate used by the video encoder when encoding the previous video frame will continue to be used to encode the current video frame.
  • the image quality of the currently encoded video frame will be similar to that of the previous video frame. Therefore, if the difference between the first video frame and the second video frame in the frame sequence to be encoded is too small, even if the texture complexity of the first video frame is greater than that of the second video frame, the encoding bitrate of the video encoder will not be adjusted. Instead, the encoding bitrate used by the video encoder when encoding the second video frame will be used to encode the first video frame. This reduces the frequency of bitrate adjustments during video encoding, thereby minimizing the bandwidth consumption of the encoded video frame stream data transmission.
  • the similarity can refer to the color similarity between the first video frame and the second video frame.
  • the first pixel value of each first pixel in the first video frame is obtained, and the number of first pixels corresponding to each first pixel value dimension is counted.
  • Each first pixel value dimension is used as the width (i.e., the horizontal axis value) of the histogram, and the number of first pixels corresponding to each first pixel value dimension is used as the height of the corresponding bar in the histogram, generating a first histogram for the first video frame to represent its color characteristics.
  • a second histogram corresponding to the second video frame is obtained.
  • the generation process of this second histogram can refer to that of the first histogram; if it has already been generated in a historical time period, the second histogram corresponding to the second video frame can be directly obtained. Furthermore, the first statistical count of pixels in each pixel value dimension of the first histogram is determined, and the second statistical count of pixels in each pixel value dimension of the second histogram is determined. Based on the first and second statistical counts in each pixel value dimension, the difference in the number of pixels between the first video frame and the second video frame in each pixel value dimension is determined. Based on the difference in the number of pixels in each pixel value dimension, the color similarity between the first video frame and the second video frame is determined.
  • color similarity is used to evaluate the degree of difference in color features between the first video frame and the second video frame, so as to make subsequent decisions on whether to adjust the encoding bitrate of the video encoder based on the texture difference between the first video frame and the second video frame.
  • the similarity between the first video frame and the second video frame is compared with a preset similarity threshold.
  • This preset similarity threshold is used to determine the degree of similarity between the first video frame to be encoded and the previously encoded second video frame, thereby determining the degree of difference between the first and second video frames.
  • a higher similarity indicates a smaller difference between the first and second video frames, and vice versa.
  • the difference between the first and second video frames is determined using this preset similarity threshold to decide whether it is necessary to determine the image texture values of the first and second video frames.
  • the similarity between the first video frame and the second video frame is less than the preset similarity threshold, it indicates that the difference between the first video frame and the second video frame is too large.
  • the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded is determined, and the second image texture value of the second video frame adjacent to the first video frame is determined, so that the encoding bitrate of the video encoder can be adjusted when the first image texture value is greater than the second image texture value.
  • the video encoder encodes the first video frame currently to be encoded in the frame sequence to be encoded according to the current encoding bitrate (i.e. the encoding bitrate when encoding the second video frame).
  • the first image texture value and the second image texture value are compared to determine the texture complexity between the first video frame and the second video frame. This step takes the example that the larger the image texture value, the greater the texture complexity.
  • the image texture difference is greater than a preset texture difference threshold, it indicates a significant difference between the first and second video frames.
  • the previous encoding bitrate of the video frame encoder is insufficient to meet the image quality requirements of the first video frame. In this case, it is necessary to determine the image texture ratio between the first and second image texture values so that the previous encoding bitrate of the video encoder can be increased accordingly.
  • the image texture difference is less than or equal to the preset texture difference threshold, it indicates a smaller difference between the first and second video frames. In this case, the previous encoding bitrate of the video encoder does not need to be increased, and the encoding bitrate used for encoding the second video frame can continue to be used for encoding the first video frame. This reduces the frequency of bitrate adjustments by the video encoder and decreases the consumption of transmission bandwidth resources.
  • the previous encoding bitrate of the video encoder can be adjusted according to the image texture ratio. Since the encoding bitrate of the video encoder may be adjusted in real time during the encoding of the preceding video frames in the frame sequence to be encoded, the current encoding bitrate of the video encoder can be understood as the encoding bitrate used when encoding the second video frame. Therefore, adjusting the previous encoding bitrate of the video encoder according to the image texture ratio makes the adjustment range of the video encoder's encoding bitrate match the ratio of the texture complexity difference between the preceding and following video frames.
  • the current encoding bitrate of the video encoder is obtained, for example, the encoding bitrate used when encoding the second video frame, and the upper limit of the encoding bitrate for the video encoder is also obtained.
  • the encoding bitrate is weighted according to the image texture ratio, and the adjustment range is based on the proportion of texture complexity differences between consecutive video frames, increasing the encoding bitrate of the video encoder. This achieves frame-level adjustment of the video encoder's encoding bitrate, obtaining candidate encoding bitrates.
  • the upper limit of the video encoder's encoding bitrate is used as a bitrate adjustment limit threshold.
  • the adjusted candidate encoding bitrate is greater than or equal to the upper limit of the video encoder's encoding bitrate, then the upper limit of the video encoder's encoding bitrate is used as the target encoding bitrate. Conversely, if the adjusted candidate encoding bitrate is less than the upper limit of the video encoder's encoding bitrate, then the video encoder's encoding bitrate is adjusted according to the candidate encoding bitrate, i.e., the candidate encoding bitrate is used as the target encoding bitrate for the video encoder.
  • the upper limit of the encoding bitrate can be the bitrate limit of the video encoder, which can be understood as the maximum encoding bitrate of the video encoder.
  • This upper limit of the encoding bitrate can be set according to the available bandwidth resources or the expected target bandwidth resources, so that the maximum encoding bitrate cannot exceed the upper limit of the encoding bitrate during the bitrate adjustment (i.e., bitrate control) process. In this way, the video frame quality is maximized, and the encoded video frame stream is transmitted smoothly under the limited bandwidth resources, avoiding the phenomenon of video playback stuttering, and has reliability.
  • the encoding bitrate of the video encoder can be adjusted according to the image texture ratio between consecutive video frames. This ensures that the adjustment range of the video encoder's encoding bitrate matches the ratio of the texture complexity differences between consecutive video frames. This allows for more delicate and precise adjustment of the video encoder's encoding bitrate at the frame level.
  • the current first video frame is then encoded according to the newly adjusted bitrate, maximizing bandwidth savings while ensuring the image quality of the encoded first video frame, thus providing reliability.
  • this video encoding method is suitable for scenarios such as live video streaming and real-time audio and video, including game streaming, game footage, multiplayer cooperative gameplay, and online movie viewing.
  • This video encoding primarily compresses video frames in a live stream to increase the data throughput per unit time, which can be understood as the data transmission volume. The goal is to achieve an optimal balance between video quality and the reduction of buffering issues for users while meeting target bandwidth requirements, thereby improving video quality.
  • the following section introduces this video encoding method using an example scenario:
  • Video encoding can be implemented based on video codec control (i.e., bitrate control).
  • Video codec control analyzes the complexity of the video and the number of remaining bits to adjust the quantization parameters of the image layer and coding unit layer during encoding. This allows the encoder to achieve an optimal balance between video quality and the duration of buffering for the user, while meeting the target bandwidth (e.g., a range similar to the video source bitrate). Therefore, in live streaming or real-time audio/video scenarios, the encoder's bitrate can be adjusted based on the source video bitrate to ensure video quality.
  • This video encoding scenario example is based on frame-level bitrate calculation to adjust and control the encoder's encoding bitrate. This allows the encoder to achieve the optimal balance between video quality and the duration of buffering for the user while meeting the target bandwidth (e.g., a range of values similar to the video source bitrate), thus ensuring video quality.
  • the target bandwidth e.g., a range of values similar to the video source bitrate
  • FIG. 5 is an example diagram of a video encoding scenario provided in an embodiment of this application.
  • the specific video encoding scenario is as follows: A video source is input, and the video source is transmitted as a sequence of video frames (images). The sequence includes multiple video frames.
  • pre-analysis can be performed to determine the spatiotemporal complexity of the video frame.
  • the encoder's bitrate is controlled. Specifically, the quantization parameter (QP) of the image layer in the encoder and the quantization parameter (QP) of the encoding unit in the encoder are adjusted. This compresses and buffers the actual bitrate of the encoder, allowing the video frames to be encoded at the target bitrate.
  • the video quality is optimized as much as possible within the target bandwidth.
  • Figure 6 is an example diagram of bitrate variation in a bitrate control scenario for video encoding provided in this application embodiment.
  • bitrate control is not performed between stages A and B.
  • the actual bitrate fluctuates, sometimes high and sometimes low, and is unstable.
  • the actual bitrate may exceed the target bandwidth limit.
  • bitrate control can be performed.
  • the output bitrate is generally below the target bandwidth limit, and the output bitrate tends to be stable without significant fluctuations, effectively ensuring the quality of the encoded video and providing reliability.
  • This video encoding scenario example is not limited to live video streaming and video-on-demand scenarios. It supports encoding video media stream data in various data formats, such as Real-Time Messaging Protocol (RTMP), Flash Video (FLV), HTTP Live Streaming (HLS), Dynamic Adaptive Streaming over HTTP (DASH), Web Real-Time Communications (WebRTC), Transport Stream (TS), and Moving Picture Experts Group 4 (MP4).
  • RTMP Real-Time Messaging Protocol
  • FLV Flash Video
  • HLS Dynamic Adaptive Streaming over HTTP
  • WebRTC Web Real-Time Communications
  • TS Transport Stream
  • MP4 Moving Picture Experts Group 4
  • the broadcaster's client can transmit video stream data to the video encoding server in real time.
  • the video encoding server encodes the live video stream.
  • the live stream can be an image stream formed by organizing multiple consecutive video frames as a frame sequence.
  • the video encoding server encodes each video frame in the frame sequence. This encoding process can be understood as compression, which
  • the video encoding process can be divided into two parts: bitrate control and adjustment and video frame encoding. This video encoding scenario example will focus on the bitrate control and adjustment process.
  • FIG. 7 is an example diagram of the video encoding process provided in an embodiment of this application. Referring to Figure 7, the bitrate control adjustment during the video encoding process is described in detail below:
  • IDR frames are organized in sequences.
  • the first video frame in a sequence is called an Instantaneous Decoder Refresh (IDR) video frame.
  • IDR frames are all keyframe (I-frame) images.
  • a sequence of frames to be encoded can contain many I-frame images. Images after I-frame images can use images between I-frame images as motion references.
  • the video encoder's bitrate can be initially adjusted based on the video source bitrate.
  • This bitrate serves as the base bitrate for the current frame sequence to be encoded, allowing for further bitrate adjustments.
  • the video source bitrate can be determined in real-time based on the granularity of the group of pictures (GOP) between two keyframes (I-frames).
  • the GOP represents a group of video frames (the group of frames to be encoded). Specifically, the frame length between two keyframes (I-frames) and the frame rate of the playback client are first determined.
  • the number of video frame groups per unit time i.e., the video source bitrate
  • the video encoding kernel i.e., the video encoder
  • the video encoder is dynamically loaded and updated according to the current video source bitrate, enabling the video encoder to obtain the current base bitrate.
  • Detection methods can include Hue Saturation Value (HSV), histogram statistics, hash similarity statistics, etc. Taking the detection of abrupt changes between any two adjacent video frames using frame-level histograms as an example, the specific steps are as follows:
  • a histogram for each video frame is calculated and generated, as follows: the pixel value of each pixel in the video frame is calculated, and according to the scalar of 256 pixel values from 0 to 255, the number of pixels corresponding to each pixel value is counted. Thus, a histogram of color for the video frame is generated based on the number of pixels corresponding to each pixel value.
  • the color similarity between the video frames is calculated, as shown below:
  • Sh represents the color similarity between two video frames. The closer the similarity is to 1, the more similar the two video frames are. The closer the similarity is to 0, the greater the difference between the two video frames.
  • n represents the width of the histogram, with a maximum width of 256.
  • a i represents the value of one video frame at pixel i in the histogram (i.e., the statistical value of the pixel point).
  • b i represents the value of one video frame at pixel i in the histogram.
  • FIG 8 is an example diagram of the calculation scenario for image texture values of video frames provided in the embodiments of this application.
  • the original LBP operator is defined as follows: within a 3*3 window, using the center pixel of the window as a threshold, the grayscale values of the eight adjacent pixels are compared with it. If the value of the surrounding pixels is greater than the value of the center pixel, the position of that pixel is marked as 1; otherwise, it is 0.
  • the comparison of the eight points within the 3*3 neighborhood generates an 8-bit binary number (usually converted to decimal, i.e., LBP code, of which there are 256 types), which is the LBP value of the center pixel of the window.
  • (01111100) 10 124, and this value is used to reflect the texture information of the region.
  • the LBP values of the regions detected from each frame are combined to calculate the LBP value of the video frame texture.
  • the smaller the operator window the more windows a video frame can be divided into, and the greater the computational load. Conversely, if the window is larger, fewer windows are divided, and the computational load will be relatively reduced. Therefore, the size of the detection area of the video frame can be automatically adjusted according to the video frame resolution and computing power to reduce the computational load when calculating image texture values.
  • the video resolution can be adjusted by downsampling. For example, downsampling a 4K video frame to obtain a 2K video frame reduces the number of windows by a factor of four, thus reducing the computational load by a factor of four. In this way, a 2K video frame can be used as a window to calculate texture values, replacing the window calculations from the 4K video frame, and obtaining a similar value.
  • the bitrate when encoding multiple video frames in the same sequence, the bitrate can be updated iteratively, and the encoding bitrate is adjusted based on the bitrate of the previous frame.
  • Video frame encoding Specifically, for each video frame in the sequence of frames to be encoded, each frame is encoded sequentially in a step-by-step manner. During the encoding process, the encoding bitrate of the video encoding kernel is adjusted according to the process (1.1) to (1.4) in (1) above, so as to encode the video frame of the current frame according to the adjusted encoding bitrate.
  • the encoding bitrate control adjustment is performed according to (1) and (2) video frame encoding to complete the encoding of the entire live video or video-on-demand process until the end.
  • Real-time dynamic detection is performed to detect whether the video screen suddenly switches from a static or relatively low bitrate scene to a scene with a higher bitrate and more complex picture. If so, the video encoding bitrate is adjusted in real time, only increasing and not decreasing, to solve the problem of statistical delay in the existing video bitrate statistics method caused by such scene switching. Due to insufficient video bitrate statistics, the video encoding kernel bitrate allocation is insufficient, resulting in poor picture quality.
  • Frame-level bitrate calculation optimizes and improves image quality bitrate control, ensuring that the video encoder's bitrate is as close as possible to the video source bitrate, while not exceeding the set target bandwidth.
  • fixed-duration bitrate statistics can guarantee that the statistical video bitrate will not exceed the original stream, preventing bitrate from getting out of control due to real-time frame dynamic adjustments and increasing too much, ultimately leading to an excessively high video bitrate that negatively impacts the viewing experience for subsequent viewers.
  • this embodiment of the application can obtain the current encoding bitrate of the video encoder in real time. Then, it encodes the video frames in the current frame sequence to be encoded of the target video source according to the encoding bitrate. Furthermore, during the encoding process, the texture complexity between the first video frame to be encoded and the previous adjacent second video frame is compared in real time. The texture complexity represents the richness of the video frame's image content to evaluate the required encoding bitrate. If the texture of the current first video frame is more complex than the previous frame, the image texture ratio between the first and second video frames is determined based on the first and second image texture values. Finally, the encoding bitrate of the video encoder is adjusted according to the image texture ratio.
  • the target encoding bitrate is used to enable the video encoder to encode the first video frame according to the adjusted target encoding bitrate.
  • this application can compare the texture complexity between the preceding and following video frames during the encoding process of the target video source's frame sequence.
  • the encoding bitrate of the video encoder is adjusted according to the texture ratio between the preceding and following video frames. In this way, the encoding bitrate of the video encoder can be flexibly and finely adjusted at the frame level to ensure the encoding quality of the following video frames by the video encoder and guarantee the video frame image quality of the video encoding.
  • this application also provides an apparatus based on the above-described video encoding method.
  • the meanings of the terms used are the same as in the video encoding method described above, and specific implementation details can be found in the descriptions within the method embodiments.
  • FIG. 9 is a schematic diagram of the structure of a video encoding device provided in an embodiment of this application.
  • the video encoding device is integrated into the computer equipment of this application.
  • the video encoding device may include a first acquisition unit 401, an encoding unit 402, a first determination unit 403, a second determination unit 404, and an adjustment unit 405.
  • Acquisition unit 401 is used to acquire the current encoding bitrate of the video encoder
  • the encoding unit 402 is used to acquire the sequence of frames to be encoded from the target video source and encode the first video frame in the sequence of frames to be encoded according to the encoding bitrate by the video encoder.
  • the first determining unit 403 is used to determine the first image texture value of the first video frame currently to be encoded in the frame sequence to be encoded, and to determine the second image texture value of the second video frame adjacent to the first video frame.
  • the first video frame is any video frame after the first video frame.
  • the second determining unit 404 is used to determine the image texture ratio based on the first image texture value and the second image texture value when the texture complexity identified by the first image texture value is greater than the texture complexity identified by the second image texture value.
  • the adjustment unit 405 is used to adjust the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and to encode the first video frame according to the target encoding bitrate.
  • the video encoding apparatus further includes a third determining unit, used for:
  • the first determining unit 403 is also used for:
  • the similarity is less than a preset similarity threshold, the first image texture value of the first video frame to be encoded in the frame sequence is determined.
  • the similarity includes color similarity
  • the third determining unit is further used for:
  • the color similarity between the first and second video frames is determined based on the difference between the first and second histograms.
  • the first statistic of the first video frame in each pixel value dimension is determined based on the first histogram, and the second statistic of the second video frame in each pixel value dimension is determined based on the second histogram.
  • the color similarity between the first video frame and the second video frame is determined based on the difference in the number of pixels in each pixel value dimension.
  • the second determining unit 404 is further configured to:
  • the image texture ratio of the first image texture value and the second image texture value is calculated.
  • the first determining unit 403 is further configured to:
  • the first image texture value of the first video frame is determined based on the grayscale value of each first pixel.
  • the first determining unit 403 is further configured to:
  • the first pixel in the first video frame is divided to obtain multiple target local regions.
  • the first image texture value of the first video frame is determined based on the first local texture value corresponding to each target local region.
  • the first determining unit 403 is further configured to:
  • the gray value of the first pixel at each edge is compared with the gray value of the first pixel at the center to obtain multiple comparison results for each target local region;
  • the multiple comparison results of each target local region are binarized to obtain the first local texture value corresponding to each target local region.
  • the first determining unit 403 is further configured to:
  • the window range list includes the correlation between different available resource amounts and window range values.
  • the candidate local texture window is adjusted according to the target window range value to obtain the target local texture window;
  • the candidate local texture window is determined as the target local texture window.
  • the video encoding apparatus further includes a processing unit for:
  • the first video frame is downsampled to obtain the downsampled first video frame
  • the first determining unit is further configured to: obtain the grayscale value of each first pixel in the first video frame after downsampling.
  • the adjustment unit 405 is further configured to:
  • the candidate coding bitrates are obtained by weighting the coding bitrates based on the image texture ratio.
  • the coding bitrate of the video encoder is adjusted according to the candidate coding bitrate to obtain the target coding bitrate;
  • the encoding bitrate of the video encoder is adjusted according to the upper limit of the encoding bitrate to obtain the target encoding bitrate.
  • the adjustment unit 405 is further configured to:
  • the target image texture ratio between the third video frame and the first video frame is determined.
  • the target coding bitrate of the video encoder is adjusted according to the texture ratio of the target image to obtain the adjusted target coding bitrate, and the third video frame is encoded according to the adjusted target coding bitrate.
  • the third video frame is encoded according to the target encoding bitrate.
  • the acquisition unit 401 is further configured to:
  • the video encoder's bitrate is updated synchronously based on the video source bitrate.
  • this embodiment of the application can obtain the current encoding bitrate of the video encoder in real time. Then, it encodes the video frames in the current frame sequence to be encoded of the target video source according to the encoding bitrate. Furthermore, during the encoding process, the texture complexity between the first video frame to be encoded and the previous adjacent second video frame is compared in real time. The texture complexity represents the richness of the video frame's image content to evaluate the required encoding bitrate. If the texture of the current first video frame is more complex than the previous frame, the image texture ratio between the first and second video frames is determined based on the first and second image texture values. Finally, the encoding bitrate of the video encoder is adjusted according to the image texture ratio.
  • the target encoding bitrate is used to enable the video encoder to encode the first video frame according to the adjusted target encoding bitrate.
  • this application can compare the texture complexity between the preceding and following video frames during the encoding process of the target video source's frame sequence.
  • the encoding bitrate of the video encoder is adjusted according to the texture ratio between the preceding and following video frames. In this way, the encoding bitrate of the video encoder can be flexibly and finely adjusted at the frame level to ensure the encoding quality of the following video frames by the video encoder and guarantee the video frame image quality of the video encoding.
  • FIG 10 is a structural schematic diagram of a terminal provided in an embodiment of this application, it includes a structural block of a portion of the terminal 140 implementing this embodiment.
  • the terminal 140 includes components such as a radio frequency (RF) circuit 510, a memory 515, an input unit 520, a display unit 540, a sensor 550, an audio circuit 560, a wireless fidelity (WiFi) module 570, a processor 580, and a power supply 590.
  • RF radio frequency
  • a memory 515 such as a radio frequency (RF) circuit 510, a memory 515, an input unit 520, a display unit 540, a sensor 550, an audio circuit 560, a wireless fidelity (WiFi) module 570, a processor 580, and a power supply 590.
  • WiFi wireless fidelity
  • the RF circuit 510 can be used to receive and transmit signals during information transmission or calls. In particular, it receives downlink information from the base station and processes it with the processor 580; in addition, it transmits uplink data to the base station.
  • the memory 515 can be used to store software programs and modules.
  • the processor 580 executes various terminal functions and video encoding by running the software programs and modules stored in the memory 515.
  • the input unit 520 can be used to receive input numeric or character information, and to generate key signal inputs related to the terminal's settings and function control.
  • the input unit 520 may include a touch panel 531 and other input devices 532.
  • the display unit 540 can be used to display input or provided information, as well as various menus of the terminal.
  • the display unit 540 may include a display panel 541.
  • Audio circuit 560, speaker 561, and microphone 562 provide an audio interface.
  • the processor 580 included in the terminal 140 can execute the video encoding method of the previous embodiment.
  • the terminal 140 in this application embodiment includes, but is not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, and aircraft.
  • This invention can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, and assisted driving.
  • FIG 11 is a schematic diagram of the server structure provided in an embodiment of this application, which includes a partial structural block of the server 110 implementing this embodiment.
  • the server 110 can vary significantly due to different configurations or performance, and may include one or more central processing units (CPUs) 622 (e.g., one or more processors) and a memory 632, and one or more storage media 630 (e.g., one or more mass storage devices) for storing application programs 642 or data 644.
  • the memory 632 and storage media 630 can be temporary or persistent storage.
  • the program stored in the storage media 630 may include one or more modules (not shown in the figure), each module may include a series of instruction operations on the server 600.
  • the central processing unit 622 may be configured to communicate with the storage media 630 and execute the series of instruction operations in the storage media 630 on the server 600.
  • Server 600 may also include one or more power supplies 626, one or more wired or wireless network interfaces 650, one or more input/output interfaces 658, and/or one or more operating systems 641, such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM , etc.
  • operating systems 641 such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM , etc.
  • the central processing unit 622 in server 600 can be used to execute the video encoding method of the embodiments of this application, as follows:
  • the process involves: obtaining the current encoding bitrate of the video encoder; obtaining the sequence of frames to be encoded from the target video source, and starting to encode the first video frame in the sequence according to the encoding bitrate using the video encoder; determining the first image texture value of the first video frame currently to be encoded in the sequence, and determining the second image texture value of the second video frame adjacent to the first video frame, where the first video frame is any video frame after the first video frame; when the texture complexity indicated by the first image texture value is greater than the texture complexity indicated by the second image texture value, determining the image texture ratio based on the first and second image texture values; adjusting the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encoding the first video frame according to the target encoding bitrate.
  • This application also provides a computer-readable storage medium for storing program code, which is used to execute the video encoding methods of the foregoing embodiments, as follows:
  • the process involves: obtaining the current encoding bitrate of the video encoder; obtaining the sequence of frames to be encoded from the target video source, and starting to encode the first video frame in the sequence according to the encoding bitrate using the video encoder; determining the first image texture value of the first video frame currently to be encoded in the sequence, and determining the second image texture value of the second video frame adjacent to the first video frame, where the first video frame is any video frame after the first video frame; when the texture complexity indicated by the first image texture value is greater than the texture complexity indicated by the second image texture value, determining the image texture ratio based on the first and second image texture values; adjusting the encoding bitrate of the video encoder according to the image texture ratio to obtain the target encoding bitrate, and encoding the first video frame according to the target encoding bitrate.
  • This application also provides a computer program product, which includes a computer program.
  • a processor of a computer device reads and executes the computer program, causing the computer device to perform the video encoding method described above.
  • At least one (item) means one or more, and “more than” means two or more.
  • “And/or” is used to describe the relationship between related objects, indicating that three relationships can exist. For example, “A and/or B” can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character “/” generally indicates that the preceding and following related objects are in an “or” relationship. "At least one (item) of the following” or similar expressions refer to any combination of these items, including any combination of single or plural items.
  • At least one (item) of a, b, or c can represent: a, b, c, "a and b", “a and c", “b and c", or "a and b and c", where a, b, and c can be single or multiple.
  • the disclosed systems, apparatuses, and methods can be implemented in other ways.
  • the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods.
  • multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
  • the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.
  • the units described as separate components may or may not be physically separate.
  • the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
  • the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
  • the integrated unit can be implemented in hardware or as a software functional unit.
  • the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application.
  • the aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
  • module refers to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof.
  • a processor or multiple processors or memory
  • each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • Algebra (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

本申请公开一种视频编码方法、装置、设备以及可读存储介质,可获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。以此,按照帧级调整视频编码器的码率,保证编码后的视频帧画质。

Description

视频编码方法、装置、设备以及可读存储介质
本申请要求于2024年07月09日提交中国专利局、申请号为202410913458X、申请名称为“视频编码方法、装置、设备以及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,具体涉及视频编码。
背景技术
随着流媒体技术的不断发展,带动了在线直播、视频边下载边播放、远程教育、远程医疗等流媒体业务的运营,丰富了人们的生活。对于涉及到视频类的流媒体业务,为了能够在有限的网络带宽下提高传输的视频流量,需要在视频流数据传输过程中进行视频编码,在视频编码过程中,需要先确定视频源码率,以根据视频源码率确定视频编码器的编码码率进行视频编码。
相关技术在确定视频源码率时,通过每间隔固定时长统计一次视频源码率,以根据确定的视频源码率同步调整视频编码器的编码码率。
在对相关技术的研究和实践过程中,本申请的发明人发现相关技术通过固定时长统计视频源码率,统计到的视频源码率比较固定,从而根据确定的视频源码率同步调整视频编码器的编码码率之后,会使得视频编码器在此期间按照固定的编码码率进行编码,由于视频内容的多样性,这样会影响视频编码质量,导致视频编码后的视频帧画质降低。
发明内容
本申请提供一种视频编码方法、装置、设备以及可读存储介质,可按照帧级灵活调整视频编码器的编码码率,保证视频编码后的视频帧画质。
为解决上述技术问题,本申请提供以下技术方案:
本申请实施例提供一种视频编码方法,包括:
获取视频编码器当前的编码码率;
获取目标视频源的待编码帧序列,并通过所述视频编码器按照所述编码码率对所述待编码帧序列中的首个视频帧进行编码;
确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于所述第一视频帧之前相邻的第二视频帧的第二图像纹理值,所述第一视频帧为所述首个视频帧之后的任意视频帧;
当所述第一图像纹理值标识的纹理复杂度大于所述第二图像纹理值标识的纹理复杂度时,根据所述第一图像纹理值和所述第二图像纹理值确定图像纹理比值;
根据所述图像纹理比值调整所述视频编码器的编码码率,得到目标编码码率,并按照所述目标编码码率对所述第一视频帧进行编码。
相应的,本申请实施例提供一种视频编码装置,包括:
获取单元,用于获取视频编码器当前的编码码率;
编码单元,用于获取目标视频源的待编码帧序列,并通过所述视频编码器按照所述编码码率对所述待编码帧序列中的首个视频帧进行编码;
第一确定单元,用于确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于所述第一视频帧之前相邻的第二视频帧的第二图像纹理值,所述第一视频帧为所述首个视频帧之后的任意视频帧;
第二确定单元,用于当所述第一图像纹理值标识的纹理复杂度大于所述第二图像纹理值标识的纹理复杂度时,根据所述第一图像纹理值和所述第二图像纹理值确定图像纹理比值;
调整单元,用于根据所述图像纹理比值调整所述视频编码器的编码码率,得到目标编码码率,并按照所述目标编码码率对所述第一视频帧进行编码。
此外,本申请实施例还提供一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可以在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述视频编码方法。
又一方面,本申请实施例提供一种存储介质,所述存储介质用于存储计算机程序,所述计算机程序用于执行以上方面的方法。
又一方面,本申请实施例提供了一种包括计算机程序的计算机程序产品,当其在计算机上运行时,使得所述计算机执行以上方面的方法。
本申请实施例可获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
基于此,本申请可实时获取视频编码器当前的编码码率,然后,按照该编码码率对目标视频源当前的待编码帧序列中的视频帧进行编码处理,进一步的,在编码过程中,实时对比当前预备编码的第一视频帧与前一相邻的第二视频帧之间的纹理复杂度,通过纹理复杂度来表示视频帧的画面内容丰富度,以评估所需的编码码率,如果当前第一视频帧相较于前一帧的纹理较为复杂,根据第一图像纹理值和第二图像纹理值确定第一视频帧与第二视频帧之间的图像纹理比值,最后,按照图像纹理比值将视频编码器的编码码率调整为目标编码码率,以实现视频编码器按照调整得到的目标编码码率对第一视频帧进行编码;以此,相较于相关技术中视频编码器按照固定时长统计的视频源码率进行视频帧编码的方案而言,本申请可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码的视频帧画质。
本申请的其他特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本申请而了解。本申请的目的和其他优点可通过在说明书、权利要求书以及附图中所特别指出的结构来实现和获得。
附图说明
图1为本申请实施例提供的视频编码系统的场景示意图;
图2为本申请实施例提供的视频编码方法的步骤流程示意图;
图3为本申请实施例提供的视频编码方法中的图像纹理值计算场景示例图;
图4为本申请实施例提供的视频编码方法的另一步骤流程示意图;
图5为本申请实施例提供的视频编码场景示例图;
图6为本申请实施例提供的视频编码的码控场景中的码率变化示例图;
图7为本申请实施例提供的视频编码流程示例图;
图8为本申请实施例提供的视频画面的图像纹理值的计算场景示例图;
图9为本申请实施例提供的视频编码装置的结构示意图;
图10为本申请实施例提供的终端的结构示意图;
图11为本申请实施例提供的服务器的结构示意图。
具体实施方式
为了使本技术领域的人员更好地理解本申请的方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
可以理解的是,在本申请的具体实施方式中,涉及到目标视频源等相关的数据,当本申请以上实施例运用到具体产品或技术中时,需要获得对象许可或者同意,且相关数据的收集、使用和处理需要遵守相关法律法规和标准。
此外,当本申请实施例需要获取目标视频源等相关的数据时,会通过弹窗或者跳转到确认页面等方式获得目标视频源等相关的数据的单独许可或者单独同意,在明确获得目标视频源等相关的数据的单独许可或者单独同意之后,再获取用于使本申请实施例能够正常运行的必要的目标视频源等相关的数据。
需要说明的是,在说明书、权利要求书和上述附图所描述的一些流程中,包含了按照特定顺序出现的多个步骤,但应该清楚了解,这些步骤可以不按照其在本文中出现的顺序来执行或并行执行,步骤序号仅仅是用于区分开各个不同的步骤,序号本身不代表任何的执行顺序。此外,本文中的“第一”、“第二”或者“目标”等描述,是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
对本公开实施例进行进一步详细说明之前,对本公开实施例中涉及的名词和术语进行说明,本公开实施例中涉及的名词和术语适用于如下的解释:
IDR帧:在视频编码算法(H.264/H.265/H.266/AV1等),图像(即视频帧)以序列为单位进行组织。一个序列的第一个图像为即时解码刷新图像(Instantaneous Decoding Refresh,IDR)帧,IDR图像都属于内部图像(intra picture,I)帧,I帧也可以理解为关键帧。
I帧:内部图像、关键帧。IDR帧会导致解码图像缓存(Decoded Picture Buffer,DPB)参考帧列表清空,而I帧不会清空。IDR图像一定是I图像,但I图像不一定是IDR图像。一个序列中可以有很多的I图像,I图像帧之后的图像帧可以引用两个I图像帧之间的图像帧做运动参考。
码控:编码器码率控制,具体是指通过利用编码器已有的信息和编码后实际产生的比特数目及缓存器状态,对即将编码的帧进行比特分配,量化参数(Quantization Parameter,QP)调整,从而保证在有限的目标码率下通过合理的比特分配,达到视频质量最优。
码率/码流:是指视频文件在单位时间内使用的数据流量,也叫码率或码流率,可通俗地理解为取样率,是视频编码中画面质量控制中最重要的部分,一般使用的单位是千比特每秒(kbps)或兆比特每秒(mbps)。在同样分辨率下,视频文件的码流越大,压缩比就越小,画面质量就越高。码流越大,说明单位时间内取样率越大,数据流精度就越高,编码处理后的文件就越接近原始文件,图像质量越好,画质越清晰,要求播放设备的解码能力也越高。
CQP:恒定量化参数(Constant Quantization Parameter)。
QoS:服务质量(Quality of Service),主要负责从网络的角度进行业务管理和提供业务的差异性,网络实体根据不同的质量需求来处理不同业务,比如常用监测指标有卡顿率、卡顿时间、首帧等。
QoE:体验质量(Quality of Experience),评价主体是终端用户,评价对象是业务和支撑业务的网络,以视频领域为例,评价的指标不限于为视频行业的平均用户视频观看时长、视频画质清晰度、画面延时以及卡顿,等等,这些指标都会影响观众端的观看体验QoE,从而也会影响广告转化效果等。
GOP:group of pictures,具体指两个I帧之间的间隔,如间隔时长,间隔长度等。其中,即时解码刷新(IDR)帧是GOP中的首个I帧,视频流重新开始一个新的序列编码,它的作用是使解码器立即刷新,从而使预测错误不致传播。
本申请实施例提供一种视频编码方法、装置、设备以及可读存储介质。具体地,本申请实施例将从视频编码装置的维度进行描述,该视频编码装置具体可以集成在计算机设备中,该计算机设备可以是服务器,也可以是对象终端等设备。其中,该服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。其中,对象终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表、智能家电、车载终端、智能语音交互设备、飞行器等,但并不局限于此。
本申请实施例提供的一种视频编码方法,以视频帧序列中关键帧之间的间隔统计视频源码率,以更新到视频编码器的编码码率,在此基础上,通过前后帧之间的纹理复杂度对比,按照帧级别调整视频编码器的编码码率,以按照调整后的编码码率对视频帧进行编码。具体通过如下实施例进行说明:
相关技术通过固定时长统计视频源码率,或者通过原视频里携带的码率信息确定视频源码率,以将视频源码率更新视频编码器的编码码率,以使得视频编码器按照编码码率对视频源的序列中的视频帧进行编码。然而,这种在固定时长统计视频源码率,并更新调整视频编码器的码率方式,使得视频编码器的编码码率在一定时间内固定不变,如果视频编码器按照该固定的编码码率对序列中的视频帧进行编码,这可能导致图像内容较为丰富、纹理较为复杂的视频帧在编码之后画质较差,降低了视频帧画质的质量,影响了对象视频观感。
对此,为了应对上述问题,本申请实施例提出一种视频编码方法,可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理复杂比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码后的视频帧画质。具体请继续参阅下述具体实施例。
本申请实施例提供一种视频编码系统,该场景系统中的设备可以包括服务器和/或终端,终端可以请求服务器执行本申请的视频编码方法。
例如,系统包括服务器或终端,终端或服务器可以获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
又例如,参见图1,为本申请实施例提供的视频编码系统的场景示意图,系统包括服务器和终端,该终端上安装有客户端,可通过该客户端向服务器后台发送或获取视频的实时流数据,如压缩存储各业务领域的对象属性数据、查询对象属性数据等等。
其中,该终端可以向服务器直接发送或获取视频的实时流数据;此外,终端上可以安装有视频客户端,可以通过视频客户端向服务器发送或获取视频的实时流数据。
其中,该服务器在执行视频编码方法的步骤时,可获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
需要说明的是,视频编码系统可适用于视频直播或视频点播的场景。其中,在视频直播的视频编码过程中,终端可以包括主播端和观众端两部分,主播端向服务器实时发送视频源数据,通过服务器针对视频源的视频帧进行编码处理,并将编码处理后的视频帧流数据发送给观众端,使得观众端进行解码并播放。其中,在视频点播的视频编码过程中,终端可以理解为观众端或点播端,服务器直接从预先存储或者从其他服务端加载有视频,以预先存储或加载的视频作为视频源,服务器针对视频源的视频帧流序列,对视频帧进行编码处理,并将编码处理后的视频帧流数据发送给终端,使得观众端进行解码并播放。
示例性的,以视频直播为例,假设主播端正在进行游戏直播,游戏直播的游戏画面的流数据作为目标视频源主播端实时将游戏画面以流数据传输给服务器,该流数据具体以序列形式传播给服务器,服务器根据序列中的关键帧之间的间隔确定视频源编码,具体的,根据两个关键帧(I帧)之间的帧间隔(group of pictures,GOP)粒度实时确定,帧间隔可以表示一个视频帧组(待编码帧组),具体可以先确定两个关键帧(I帧)之间的帧长度(即间隔),以及确定视频源的帧率,从而根据帧率与帧长度之间的比值确定单位时间的视频帧组的数量,即视频源码率,进而,根据当前的视频源码率动态加载更新到视频编码内核(即视频编码器),以使得视频编码器获取当前基础的编码码率。
进一步的,针对待编码帧序列中的视频帧,服务器按照视频编码器的编码码率开始对待编码帧序列中的视频帧进行编码,并在编码过程中,确定相邻两帧之间的视频帧复杂度,比如,可以按照图像纹理方式表示复杂度,先确定当前帧的图像纹理值,以及确定前一帧的图像纹理值,通过前后帧之间的图像纹理值对比,以确定当前帧是否比前一帧复杂,如果当前准备编码的视频帧的图像纹理值大于前一相邻的视频帧的图像纹理值,则说明当前视频帧比前一视频帧复杂,此时,可确定当前的视频帧与前一视频帧之间的图像纹理比值,由于该图像比值大于1,按照图像纹理比值调整视频变密码器中的编码码率,当前调整得到的目标编码码率比前一帧编码时的编码码率大,按照该目标编码码率对当前的视频帧进行编码处理,以确保当前比较复杂的视频帧的画面编码质量,保证视频帧画质。此后,将该编码后的视频帧数据传输给观众端进行解码播放,观众端针对内容丰富的、复杂的游戏画面,以较佳的画质进行显示,具有可靠性。
需要说明的是,对于实时的音视频场景,比如,语音视频通话的即时通讯场景,可参照以上视频直播场景,其实时过程相同或相似,此处不做一一赘述。
示例性的,以视频点播为例,视频点播要求视频流数据的实时性,服务器直接从预先存储或者从其他服务端加载有视频,以预先存储或加载的视频作为视频源,服务器针对视频源的视频帧流序列,根据序列中的关键帧之间的间隔确定视频源编码,具体的,根据两个关键帧(I帧)之间的帧间隔(group of pictures,GOP)粒度实时确定,帧间隔可以表示一个视频帧组(待编码帧组),具体可以先确定两个关键帧(I帧)之间的帧长度,以及确定播放客户端的帧率,从而根据帧率与帧长度之间的比值确定单位时间的视频帧组的数量,即视频源码率,进而,根据当前的视频源码率动态加载更新到视频编码内核(即视频编码器),以使得视频编码器获取当前基础的编码码率。
进一步的,针对待编码帧序列中的视频帧,服务器按照视频编码器的编码码率开始对待编码帧序列中的视频帧进行编码,并在编码过程中,确定相邻两帧之间的视频帧复杂度,比如,可以按照图像纹理方式表示复杂度,先确定当前帧的图像纹理值,以及确定前一帧的图像纹理值,通过前后帧之间的图像纹理值对比,以确定当前帧是否比前一帧复杂,如果当前准备编码的视频帧的图像纹理值大于前一相邻的视频帧的图像纹理值,则说明书当前视频帧比前一视频帧复杂,此时,可确定当前的视频帧与前一视频帧之间的图像纹理比值,由于该图像比值大于1,按照图像纹理比值调整视频变密码器中的编码码率,当前调整得到的目标编码码率比前一帧编码时的编码码率大,按照该目标编码码率对当前的视频帧进行编码处理,以确保当前比较复杂的视频帧的画面编码质量,保证视频帧画质。此后,将该编码后的视频帧数据传输给终端(上的视频客户端)进行解码播放,如此,终端针对内容丰富的、复杂的游戏画面,以较佳的画质进行显示,具有可靠性。
基于以上示例可得,相较于相关技术中视频编码器按照固定时长统计的视频源码率进行视频帧编码的方案而言,本申请可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码的视频帧画质。
需要说明的是,以上仅为示例,还可应用于其他视频编码场景中,此处不做一一赘述。
为了便于理解,以下将分别对视频编码方法的各步骤进行详细说明。需说明的是,以下实施例的顺序不作为对实施例优选顺序的限定。
在本申请实施例中,将从视频编码装置的维度进行描述,以该视频编码装置具体可以集成在计算机设备,如终端或服务器中。参见图2,图2为本申请实施例提供的视频编码方法的步骤流程示意图,本申请实施例以视频编码装置具体集成在服务器上为例,服务器上的处理器执行视频编码方法对应的程序指令时,具体流程如下:
101、获取视频编码器当前的编码码率。
视频编码可以理解为将视频源数据进行压缩,并将压缩后的数据传输至播放端进行解码和播放,以在播放端页面呈现出视频源对应的视频画面。需要说明的是,视频流数据以帧序列形式进行组织、传输,视频编码是通过视频编码器对帧序列中的视频帧进行编码,而视频编码器具有编码码率,即视频编码器在对帧序列中的视频帧进行编码时,是按照编码码率进行编码的,即按照编码码率依序对帧序列中视频帧进行压缩处理,以使得视频帧在压缩之后的码率小于压缩之前的码率,得到序列对应的视频文件,可以理解为视频片段,以便占用较小的通信带宽传输至播放端进行解码和播放。
其中,视频编码器是一种用于将视频信号压缩并转换为数字格式的应用程序,其主要作用是通过压缩技术减小视频文件的大小,以便在网络传输或存储时占用更少的带宽和存储空间。视频编码器可以将原始视频信号转换为各种数字格式,如H.264、MPEG-4、AVC、VP9等。视频编码器的功能包括压缩视频数据、更改视频格式以及调整图像质量。它采用多种输入信号(如HDMI、SDI、IP视频等),并将这些信号编码为压缩数字格式,例如H.264或H.265,这需要较少的带宽来传输和存储。进一步的,通过网络传输到后端的监测中心,并由终端上运行的相应的解码软件或硬件进行解码。
然而,不同的视频帧之间的内容可能不同,可以理解为视频帧之间的内容丰富度不同,即复杂度不同,而内容较为丰富的视频帧的占用内存量通常大于内容较为简单的视频帧的占用内存量,因此,在编码过程中,在视频编码器的统一编码码率下进行编码,内容较为简单的视频帧在编码之后的画质相对较好,而内容较为丰富的视频帧在编码之后的画质相对较差。对此,可以调整视频编码器的编码码率,以减少内容丰富的视频帧在编码后得到的画质较差的现象。
其中,编码码率可以是每秒传送信息的比特数,可使用千比特每秒(kbps)或兆比特每秒(mbps)的单位来表示。具体的,码率是数据传输时单位时间传送的数据位数或数据流量,反映了视频数据的传输速率和质量。在视频编码过程中,可通过对编码码率进行控制,以优化视频质量和文件大小。
为了使得视频编码器的编码码率较为合理,可根据视频源的视频源码率作为依据,调整视频编码码率。相关技术通过固定时长(比如,1秒、3秒等固定时长)来定期获取视频源的源码率,以按照获取的源码率来定期调整视频编码器的编码码率。然而,如果按照固定时长获取的源码率来调整视频编码器的编码码率,会使得视频编码器的编码码率在固定时长内时固定不变的,粒度较大,由于实时传输的视频源的序列中包含多个视频帧,视频帧之间的复杂度不同,这中情况下采用粒度较大的编码码率对视频帧进行编码,会使得复杂度较高的视频帧在编码之后会变得模糊,画质不佳。
其中,视频源码率可以是源视频在每秒钟传输的比特数,可使用千比特每秒(kbps)或兆比特每秒(mbps)的单位来表示。源码率越高,表示单位时间内传输的数据量越大,视频的精度和质量就越高,画面也会更清晰。码率是决定视频文件大小和画质的重要因素之一,在同样的分辨率下,源码率越高,视频文件容量越大,画质也越好。
在本申请实施例中,为了使得复杂度较高的视频帧在编码之后的画质较佳,通过减少视频源码率的采集粒度,以采集目标视频源的视频源码率,以同步调整视频编码器的编码码率,实现对视频编码器的编码码率进行较精细的调整,以此作为视频编码的基础码率,具有可靠性。
其中,目标视频源可以是实时传输的视频源,可以理解为视频的信号源,或视频源端,其可提供实时的流数据。例如,可以视频直播中主播端上传、传输到服务器的视频帧的流数据,即信号源,还可以是视频点播场景中服务器从其他平台或数据库中实时读取、加载的视频帧流数据,还可以是音视频通话场景中的音视频流数据,等等。以上仅为示例,不作为具体限定方式,其它能够实时的视频流数据的视频源同样适用,此处不做一一举例。
在一些实施方式中,可根据目标视频源中关键视频帧之间的间隔确定视频源码率,以根据视频源码率同步更新视频编码器的编码码率。例如,步骤101可以包括:获取目标视频源当前的视频源码率;根据视频源码率同步更新视频编码器的编码码率。
视频编码器的编码码率是可调整的,视频编码器实时的编码码率可以根据目标视频源的相邻两个关键视频帧之间的间隔调整得到。其中,目标视频源的视频帧流数据可通过视频帧序列形式进行组织和传输到服务器,视频帧序列中可以包括不同类型的视频帧,如包括关键视频帧(Intra-coded Frame,I帧)、前向预测帧(Predicted Frame,P帧)和双向预测帧(Bi-directional Predicted Frame,B帧)。可以根据两个关键帧之间的间隔(group of pictures,GOP)来统计确定来两个关键帧之间的视频源码率。具体的,确定目标视频源的帧率,以及实时检测目标视频源的传输序列中相近的两个关键视频帧之间的间隔,如间隔长度或间隔时长,进而,根据相近的两个关键视频帧之间的间隔以及帧率计算视频源码率,如根据帧率与间隔之间的比值确定视频源码率。进一步的,根据视频源码率同步更新视频编码器中的编码码率,以使得当前的编码码率能够适配视频帧序列中当前两个关键帧之间的待编码帧序列,可以理解为子序列或片段序列。基于此,由于目标视频源实时的视频帧流数据以序列形式进行组织,通过采用关键帧之间的间隔来确定实时阶段的视频源码率,作为视频编码器进行编码时的基础码率,以更贴合对每个视频帧序列的编码码率需求,具有灵活性和可靠性。
在本申请实施例中,编码码率可以具有实时性。视频编码器当前的编码码率可以是根据视频源码率同步更新的初始编码码率,还可以是视频编码过程中针对前一视频帧进行编码时所使用的历史编码码率,具体根据实际情况而定。需要说明的是,该“前一视频帧”可以是指本申请实施例中“待编码帧序列中的一个视频帧”,后续会对“待编码帧序列”展开介绍,此处不做论述。
通过以上方式,可获取视频编码器实时的编码码率,以此作为视频编码的基础码率,以更贴合对每个视频帧序列的编码码率需求,还具有可靠性。
102、获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码。
在本申请实施例中,获取到视频编码器实时的编码码率之后,即可获取目标视频源对应的待编码帧序列,以通过视频编码器按照当前的编码码率开始对待编码帧序列中的视频帧进行编码,由于视频编码器的编码过程可以是逐帧编码的,因此,可以按照编码码率对待编码帧序列中排在首位的第一个视频帧进行编码,以便对视频帧进行压缩,提高在特定带宽下单位时间内的数据传输流量,确保播放端的视频播放流畅度。
其中,该待编码帧序列可以是目标视频源实时传输的子序列,或序列片段。具体的,目标视频源提供的所有视频帧以视频帧序列方式进行传输,该待编码帧序列可以是整个视频帧序列的一个子序列,例如,可以是当前相近的两个关键视频帧以及位于这两个关键视频帧之间的非关键视频帧(如前述的前向预测帧和/或双向预测帧)组成的序列,或者可以是由多个关键视频帧和非关键视频帧组成的序列,此处不做限定。
其中,该首个视频帧可以是指当前的待编码帧序列中排在第一位的视频帧,需要说明的是,这首个视频帧是指目标视频源当前正在传输的子序列中的第一帧,即在视频编码过程中,不同时刻的第一帧是不同的,具体根据实时的待编码帧序列而定。因此,该首个视频帧可以是目标视频源对应的整个视频帧序列的第一帧,也可以是位于视频帧序列的中间帧,此处不做限定。该首个视频帧的类型可以是关键视频帧。
本申请实施例的服务器在进行视频编码时,可以是一边接收、获取目标视频源的视频帧流数据,并一边对实时获取到的视频帧流数据进行编码处理,假设视频帧流数据以序列形式进行传输时,服务器可先后接收、获取目标视频源的每一个待编码帧序列,并先后对每个待编码帧序列中的视频帧进行编码处理。因此,目标视频源的视频流数据的编码过程是实时进行的,如果服务器已经对历史时间获取到的历史的待编码帧序列中的视频帧完成编码后,当服务器获取到一个待编码帧序列时,且服务器中的视频编码器已更新调整到对应的编码码率时,视频编码器以当前的编码码率作为基础码率,即按照当前实时的编码码率开始对待编码帧序列中首个视频帧进行编码。
示例性的,以视频直播为例,目标视频源可以理解为主播端的直播视频源,服务器实时从主播端获取直播画面帧序列,当根据直播画面帧序列中的关键视频帧之间的间隔计算出的视频源码率同步更新视频编码器的编码码率之后,视频编码器即以当前实时的编码码率作为基础,按照编码码率开始对待编码帧序列中的第一个直播画面帧进行编码,以获得编码流数据,以便后续传输至观众端。
示例性的,以视频点播为例,目标视频源可以理解为从视频数据库或其他服务端实时加载的目标视频流数据,该实时加载的目标视频流数据以序列形式传输至服务器,服务器实时获取目标视频流数据的待编码帧序列,当根据关键视频帧之间的间隔计算出的视频源码率同步更新视频编码器的编码码率之后,视频编码器即以当前实时的编码码率作为基础,按照编码码率开始对待编码帧序列中的第一个目标视频帧进行编码,以获得编码流数据,以便后续传输至播放端。
通过以上方式,可获取目标视频源对应的待编码帧序列,并以视频编码器当前的编码码率作为基础码率,以通过视频编码器按照当前的编码码率开始对待编码帧序列中的视频帧进行编码,实现对视频帧进行压缩,提高在特定带宽下单位时间内的数据传输流量,确保播放端的视频播放流畅度。
103、确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值。
在本申请实施例中,对待编码帧序列中视频帧的编码过程中,可以确定当前编码进度对应的视频帧的复杂度,以及确定前一视频帧的复杂度,从而,后续可根据当前视频帧与前一视频帧之间的复杂度对比,以便判定当前编码进度对应的视频帧是否比前一视频帧复杂,从而决策是否调整视频编码器的编码码率,具有可靠性。
需要说明的是,本申请实施例在表示视频帧的复杂度时,可以通过视频帧的组成元素和/或灰度级变化等方面来描述,例如,可以通过欧几里得距离、统计直方图、局部二值模式(Local Binary Patterns,LBP)检测算法以及卷积神经网络(Convolutional Neural Networks,CNN)特征提取分类等算法。为了便于理解,本申请实施例将以局部二值模式检测算法来对前后视频帧的复杂度进行表示,该局部二值模式可以是指图像纹理来表示视频帧的复杂度。
其中,该第一视频帧可以是待编码帧序列中当前编码进度对应的准备编码的视频帧,而第二视频帧可以是待编码帧序列中位于当前准备编码的第一视频帧的前一视频帧,需要说明的是,该第二视频帧通常为当前正在编码或已经完成编码的视频帧,而第一视频帧是指接下来准备开始编码的视频帧,因此,第一视频帧为待编码帧序列中首个视频帧之后的任意视频帧。假设待编码帧序列中有N个时序排列的视频帧,第一视频帧可以为第i个视频帧,第二视频帧可以为第i-1个视频帧,i大于1且小于或等于N。
其中,该图像纹理值可以是表示视频帧的纹理特征的参数,用于定量或定性地描述视频帧的纹理特性,图像纹理值可以基于视频帧中重要的表面灰度信息对纹理特征的分析而确定。需要说明的是,纹理特征是从视频帧中计算出来的一个值,用于量化区域内部灰度级变化的特征,具体通过计算每个小窗口形成的子影像的灰度共生矩阵和纹理特征值来生成纹理特征影像。因此,图像纹理值不仅可以反映图像的视觉复杂度,还可以作为量化图像信息复杂度的一个重要指标。因此,可通过第一图像纹理值来表示第一视频帧的图像信息复杂程度,以及通过第二图像纹理值来表示第二视频帧的图像信息复杂程度。需要说明的是,图像纹理值具体可以是一个数值;也可以是一个矩阵形式,如图像纹理值表示为一个图像矩阵,其中包含R、G、B三个二维矩阵,数值在0-255之间,这些数值表示色彩的深浅。
在一些实施方式中,可以根据第一视频帧中每个第一像素点的灰度值来确定对应的第一图像纹理值。例如,步骤103中的“确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值”,可以包括:
(103.1)获取待编码帧序列中当前预备编码的第一视频帧中每个第一像素点的灰度值;
(103.2)根据每个第一像素点的灰度值确定第一视频帧的第一图像纹理值。
其中,灰度值可以是黑白图像中像素点点的颜色深度,即第一视频帧中每个第一像素点的颜色深度,其中,灰度值范围一般从0到255,白色为255,黑色为0,灰度值表示亮度从深到浅的变化,对应视频帧中的颜色为从黑到白,可以反映视频帧的统计特征和对比度,需要说明的是,灰度图像上每个像素的颜色值可理解为灰度,指黑白图像中点的颜色深度。
具体的,在对待编码帧序列中的视频帧进行编码过程中,为了判定该第一视频帧是否比前一视频帧(即第二视频帧)更为复杂,需要先分别确定第一视频帧和第二视频帧的图像纹理值。以第一视频帧的第一图像纹理值计算为例,针对待编码帧序列中当前编码进度为准备编码的第一视频帧,可以获取该第一视频帧中每个第一像素点对应的灰度值,例如,可以按照每个第一像素点的颜色三通道(红、绿、蓝)的颜色值进行加权平均,得到每个第一像素点的灰度值,以表示颜色三通道的颜色值对亮度的贡献;又如,可以确定每个第一像素点在颜色三通道中的颜色值,并将第一像素点在颜色三通道的颜色值中的最大值/最小值作为该第一像素点的灰度值;以上灰度值的确定过程仅为示例,不作为具体限定方式。进一步的,根据每个第一像素点的灰度值确定第一视频帧的第一图像纹理值。
同理,可以按照以上方式确定第二视频帧的第二图像纹理值。以此,后续基于第一图像纹理值与第二图像纹理值之间的大小关系,判定该第一视频帧是否比前一视频帧(即第二视频帧)更为复杂,以便进行视频编码的码率调整。
需要说明的是,在计算确定第一视频帧的第一图像纹理值时,不仅可以针对第一视频帧的全部区域信息来计算生成第一图像纹理值,还可以根据第一视频帧中的目标区域信息、目标对象信息和/或目标事物信息的灰度值来确定第一图像纹理值;同理,可根据第二视频帧中的目标区域信息、目标对象信息和/或目标事物信息的灰度值来确定第二图像纹理值。
例如,在确定第一视频帧和第二视频帧的图像纹理值时,可以针对视频帧中的目标图像区域内的像素点的灰度值来计算图像纹理值,其中,该目标图像区域可以为特定对象相应的图像区域或者固定区域的图像区域。
具体的,以第一视频帧的第一图像纹理值计算为例,获取针对目标掩码图像,目标掩码图像为针对第一视频帧中目标图像区域进行像素展示的图像,根据目标掩码图像对的第一视频帧进行掩码处理,得到处理后的目标第一视频帧,该目标第一视频帧只显示目标图像区域内的内容,进而,获取目标第一视频帧中每个第一像素点的灰度值,以便根据每个第一像素点的灰度值计算目标第一视频帧的第一图像纹理值。由于目标第一视频帧中针对目标图像区域的可视化状态显示原第一视频帧中相应的区域内容信息,而第一视频帧中目标图像区域之外的其他图像区域的可视化状态显示为空白,基于此进行图像纹理值计算,可有针对性去描述视频帧中目标图像区域的关键纹理特征,提高纹理复杂度的计算效率;此后,在后续的第一视频帧与第二视频帧之间的复杂度对比中,针对前向预测视频帧或双向预测视频帧这种去除图像冗余信息的图像帧,如果第一视频帧与第二视频帧之间仅目标图像区域上存在图像内容信息的区别,这种按照掩码方式对图像纹理值的计算就显得特别有意义,实现快速定位第一视频帧与第二视频帧之间的内容差异区域,以该内容差异区域的显态区别信息作为图像纹理值计算的主要依据,减少图像纹理值计算过程中的计算量,具有可靠性。
在一些实施方式中,可以先分别根据第一视频帧中每个视频帧子区域内第一像素点的灰度值确定每个视频帧子区域的局部纹理值,在结合各个视频帧子区域的局部纹理值确定第一视频帧的第一图像纹理值。例如,步骤(103.2)可以包括:
(103.2.1)获取目标局部纹理窗口;
(103.2.2)按照目标局部纹理窗口,对第一视频帧中的第一像素点进行划分,得到划分后的多个目标局部区域;
(103.2.3)基于每个目标局部区域内包含的第一像素点的灰度值,确定第一视频帧中每个目标局部区域对应的第一局部纹理值;
(103.2.4)基于每个目标局部区域对应的第一局部纹理值,确定第一视频帧的第一图像纹理值。
其中,该目标局部纹理窗口可以是理解为一个特定大小范围的邻域范围区域,例如,大小为3像素乘3像素的范围区域,具体的,目标局部纹理窗口可以理解为局部二值模式算法中算子的覆盖范围,在该目标局部纹理窗口,以位于窗口的中心位置的第一像素点的灰度值为当前该目标局部纹理窗口的灰度判断阈值,将相邻的像素点的灰度值与该阈值进行比较,如果周围像素点的灰度值大于中心位置的第一像素点的灰度值,则该像素点的位置被标记,或者被赋值为1,反之,则被赋值为0。
其中,该目标局部区域可以是第一视频帧中的一个图像子区域,即视频帧子区域,可以理解的是,按照目标局部纹理窗口的大小对第一视频帧的第一像素点进行划分,第一视频帧可被划分为多个目标局部区域,每个目标局部区域的大小与目标局部纹理窗口的大小一致。例如,以第一视频帧的目标局部区域为例,目标局部纹理窗口可以为3像素乘3像素大小的范围窗口,则每个目标局部区域的长和宽都为3个第一像素点组成的区域,即一个目标局部区域包括9个第一像素点;又如,假设目标局部纹理窗口可以为4像素乘4像素大小的范围窗口时,一个目标局部区域包含16个第一像素点,而5像素乘5像素大小的范围窗口,目标局部区域包含25个第一像素点。
具体的,为了确定第一视频帧的第一图像纹理值,可以根据第一视频帧中多个区域的第一局部纹理值来计算第一视频帧的第一图像纹理值。具体的,可以先获取目标局部纹理窗口,并按照目标局部纹理窗口的大小对第一视频帧进行划分,从而,以将第一视频帧划分为多个大小一致的目标局部区域。进一步的,在确定第一视频帧中的每个目标局部区域之后,针对每个目标局部区域,可根据目标局部区域内包含的第一像素点的灰度值来确定该目标局部区域对应的第一局部纹理值,该第一局部纹理值可以理解为目标局部区域的中心位置的第一像素点的纹理特征值,从而,基于每个目标局部区域对应的第一局部纹理值进行汇总计算,得到第一视频帧的第一图像纹理值,其中,计算过程可以是加权计算,也可以是拼接,此处不做限定。以此,可根据第一视频帧中每个视频帧子区域内第一像素点的灰度值确定每个视频帧子区域的局部纹理值,并结合各个视频帧子区域的局部纹理值确定第一视频帧的第一图像纹理值,以用于后续第一视频帧与第二视频帧之间复杂度的对比,提高视频帧复杂度对比的准确性,具有可靠性。
在一些实施方式中,针对第一视频帧中的每个目标局部区域,确定区域中心位置的第一像素点的灰度值与周围的第一像素点的灰度值之间的差异,并根据差异进行二值化转换,得到每个目标局部区域对应的第一局部纹理值。例如,步骤(103.2.4)可以包括:确定每个目标局部区域内的中心第一像素点以及中心第一像素点周围的边缘第一像素点;针对每个目标局部区域,将每个边缘第一像素点的灰度值与中心第一像素点的灰度值进行大小对比,得到每个目标局部区域的多个对比结果;将每个目标局部区域的多个对比结果分别进行二值化处理,得到每个目标局部区域对应的第一局部纹理值。
其中,中心第一像素点可以是第一视频帧中相应的目标局部区域内的中心位置的像素点,而边缘第一像素点为相应的目标局部区域内位于中心第一像素点周围的其他像素点,例如,假设目标局部区域为3像素乘3像素大小的目标局部纹理窗口对应的图像区域,则目标局部区域包含9个第一像素点,位于中心位置的1个像素点为中心第一像素点,而位于中心第一像素点周围的其他8个像素点都为边缘第一像素点。需要说明的是,中心第一像素点和边缘第一像素点是以所在的一个目标局部区域而论的,第一视频帧中的每个目标局部区域都单独具有中心第一像素点和边缘第一像素点。
具体的,在将第一视频帧划分为多个目标局部区域之后,为了获取目标局部区域对应的第一局部纹理值,首先,可将目标局部区域内的位于中心位置的第一像素点确定为中心第一像素点,以及确定位于中心第一像素点周围位置的其他第一像素点确定为边缘第一像素点;然后,以中心第一像素点的灰度值作为灰度参考值或灰度阈值,并分别将每个边缘第一像素点的灰度值与中心的灰度参考值进行对比,得到每个边缘第一像素点相对于中心第一像素点的灰度对比结果;最后,基于多个灰度对比结果,进行二值化转换,得到目标局部区域的第一局部纹理值。
示例性的,每个目标局部区域为3像素乘3像素大小的目标局部纹理窗口对应的图像区域,则每个目标局部区域都包含9个第一像素点,分别为1个中心第一像素点和8个边缘第一像素点。结合图3所示,以其中一个目标局部区域为例,该中心第一像素点的灰度值为83,周围的8个边缘第一像素点分别为44、118、192、204、250、174、61、32,对于每个边缘第一像素点的灰度值,都与中心第一像素点的灰度值进行对比,得到8个灰度对比结果,分别将每个灰度对比结果进行二值化转换,如果边缘第一像素点的灰度值大于中心第一像素点的灰度值,经过二值化转换,赋值为1,如果边缘第一像素点的灰度值小于或等于中心第一像素点的灰度值,则赋值为0,因此,针对以上8个灰度对比结果,经过二值化转换,分别赋值为0、1、1、1、1、1、0、0(顺时针的顺序),表示为8位二进制数为01111100,通过8位二进制表示图像纹理值,针对每个目标局部区域的第一图像纹理值,都可以有256种不同的结果,将该目标局部区域的二进制形式的第一图像纹理值转换为十进制形式表示为124,二进制数的“01111100”和十进制的“124”都可表示该目标局部区域对应第一图像纹理值。
需要说明的是,对于按照其他规格大小的目标局部纹理窗口划分的目标局部区域,可以确定位于目标局部区域内中间位置的一个或多个像素点作为中心像素点组合区,该中心像素点组合区可以是视为一个整体,即作为“中心像素点”。例如,以第一视频帧的目标局部区域为例,即中心第一像素点组合区包含位于目标局部区域中心位置的多个第一像素点,目标局部区域内位于中心第一像素点组合区之外的其他第一像素点作为边缘第一像素点。在计算这种规格大小下的目标局部区域的图像纹理值时,可根据中心第一像素点组合区内的多个像素点的灰度值确定中心第一像素点组合区的灰度值,或定义为“中心第一像素点组合区的目标灰度值”,并对中心第一像素点组合区的多个第一像素点的灰度值进行加权平均,得到中心第一像素点组合区对应的目标灰度值;从而,将每个边缘像素点的灰度值与中心像素点组合区对应的目标灰度值进行对比,得到多个灰度对比结果;进而,通过对多个灰度对比结果进行二值化转换,得到目标局部区域对应的第一局部纹理值。
示例性的,每个目标局部区域为4像素乘4像素大小的目标局部纹理窗口对应的图像区域,则区域内包含16个第一像素点,确定目标局部区域内的中心第一像素点组合区时,可将位于目标局部区域中心位置的“2像素乘2像素”区域内的4个第一像素点作为中心第一像素点组合区,进而,基于中心第一像素点组合区内4个第一像素点的灰度值,确定中心第一像素点组合区的目标灰度值,例如,通过对这4个第一像素点的灰度值进行加权平均,或者取这4个第一像素点的灰度值中的最大值或最小值,以作为中心第一像素点组合区的目标灰度值;此后,将目标局部区域内处于中心第一像素点组合区周围的12个边缘第一像素点,分别与中心第一像素点组合区的目标灰度值进行对比,得到12个灰度对比结果,通过二值化转换,得到目标局部区域对应的第一局部纹理值。
此外,还可以按照其他规格大小的目标局部纹理窗口划分目标局部区域,其实施过程可以参考以上示例,此处不做一一赘述。
在一些实施方式中,为了减少在计算视频帧的图像纹理值时的计算量,提高图像纹理值的计算效率,在划分视频帧进行图像纹理值计算之前,可以调整用于划分视频帧的局部区域的局部纹理窗口的规格尺寸参数,以便按照调整后得到的目标局部纹理窗口。例如,步骤(103.2.1)可以包括:获取候选局部纹理窗口,并确定候选局部纹理窗口的候选窗口范围值;获取图像算力资源的目标可用资源量,并根据目标可用资源量查询窗口范围列表,得到目标窗口范围值,窗口范围列表包括不同的可用资源量与窗口范围值之间的关联关系;当候选窗口范围值小于目标窗口范围值时,根据目标窗口范围值调整候选局部纹理窗口,得到目标局部纹理窗口;当候选窗口范围值大于或等于目标窗口范围值时,将候选局部纹理窗口确定为目标局部纹理窗口。其中,该候选局部纹理窗口可以是预先设定的规格范围的邻域区域,其可以理解为局部二值化模式算法默认的算子覆盖范围。例如,候选局部纹理窗口的大小为3像素乘3像素的邻域范围区域。
其中,图像算力资源可以是服务器中用于图像处理的运算资源,如中央处理器(CPU)、图像处理单元(GPU)、内存、缓存等中的一种或多种运算资源,这些运算资源会影响图像纹理值的计算效率。而目标可用资源量可以是以上任意一种或多种运算资源的可用量,例如,为GPU算力资源的可用量。
其中,该窗口范围列表可以是一种或多种图像算力资源的可用资源量与窗口范围值的列表,具体包括一种或多种类型的图像算力资源的可用资源量与窗口范围值之间的关联关系。需要说明的是,服务器会实时检测本地的图像算力资源的剩余可用量,以根据图像算力资源的剩余可用量同步更新至窗口范围列表中对应类型的图像算力资源的可用资源标量。
具体的,获取局部二值化模式算法对应的默认的候选局部纹理窗口,并确定候选局部纹理窗口的候选窗口范围值,该候选窗口范围值表示候选局部纹理窗口的尺寸大小;进而,获取服务器本地的图像算力资源的目标可用资源量,按照该目标可用资源量查询窗口范围列表,以从窗口范围列表中确定与当前图像算力资源的目标可用资源量相匹配的目标窗口范围值;最后,将目标窗口范围值与候选窗口范围值进行大小对比,如果目标窗口范围值与候选窗口范围值大于候选窗口范围值,则按照目标窗口范围值调整候选局部纹理窗口的大小,得到调整后的目标局部纹理窗口,反之,如果目标窗口范围值小于或等于候选窗口范围值,则直接将候选局部纹理窗口作为目标局部纹理窗口。以此,可尽可能选取覆盖较大的纹理窗口作为目标局部纹理窗口,以使得后续在按照目标局部纹理窗口将视频帧划分为多个目标局部区域时,尽可能减少窗口(即“目标局部区域”)的数量,从而减少后续在计算图像纹理值时的计算量,提高图像纹理值的计算效率,有效避免由于图像纹理值的计算过程延误后续调整视频编码器的编码码率,从而影响了视频编码进度和效率,具有可靠性。
在本申请实施例中,为了加快针对视频帧的图像纹理值的计算速度,除了通过调大局部纹理窗口的规格尺寸之外,针对本申请实施例中的任意一个“视频帧”,还可以降低视频帧的分辨率,以达到减少图像纹理值的计算量,从而提高针对视频帧的图像纹理值的计算效率。需要说明的是,可在降低视频帧的图像分辨率来减少计算量,并在此基础上,进一步结合调大规格尺寸后的目标局部纹理窗口,以进一步减少针对视频帧的图像纹理值的计算量,以此,进一步提高图像纹理值的计算效率,有效避免由于图像纹理值的计算过程延误后续的视频编码效率,具有可靠性。
在一些实施方式中,以减少第一视频帧在计算图像纹理值的计算量为例,可通过下采样方式降低第一视频帧的分辨率,以便根据下采样处理后的第一视频帧来进行后续的图像纹理值计算,提高图像纹理值的计算效率。例如,步骤(103.1)之前可以包括:获取待编码帧序列中当前预备编码的第一视频帧对应的图像分辨率信息;基于图像分辨率信息,对第一视频帧进行下采样处理,得到下采样处理后的第一视频帧;则步骤(103.1)之前,还可以包括:获取下采样处理后的第一视频帧中每个第一像素点的灰度值。
其中,该图像分辨率信息可以是视频帧中包含信息量,通过像素点的数量来表示图像分辨率信息,具体的,图像分辨率信息可以表示视频帧在单位长度(如每英寸)内所包含的像素点的数量,即表示视频帧中在长和宽维度上所包含的像素点的个数。可以理解的是,图像分辨率信息决定了视频帧的精细程度,分辨率越高,图像越清晰。
需要说明的是,可通过像素点下采样方式来减少针对第一视频帧的图像纹理值的计算量。具体的,针对待编码帧序列中当前编码进度对应的准备编码的第一视频帧,可获取第一视频帧的图像分辨率信息,该图像分辨率信息可以表示第一视频帧所包含的第一像素点的分布和数量,进而,获取第一视频帧中每个第一像素点对应的像素值,基于图像分辨率信息反映的第一视频帧中分布的各第一像素点的,按照每个第一像素点的像素值的大小关系进行下采样处理,例如,以“2像素乘2像素”或“3像素乘3像素”的第一像素点区域为单位,采用每个第一像素点区域中像素值最大的第一像素点,如此,得到下采样处理后的第一视频帧。进而,获取下采样处理后的第一视频帧中每个第一像素点的灰度值,以便后续基于下采样处理后的第一视频帧中每个第一像素点的灰度值,确定第一视频帧的第一图像纹理值。
在本申请实施例中,由于网络带宽资源有限,为了减少带宽资源的占用率,如果待编码帧序列中的第一视频帧相对于第二视频帧的差异过小,将继续使用视频编码器在对前一视频帧编码时的编码码率对当前编码的视频帧进行编码,其当前编码得到的视频帧画质相对于前一视频帧的画质也是相近的。因此,如果待编码帧序列中的第一视频帧相对于第二视频帧的差异过小,即便第一视频帧的纹理复杂度大于第二视频帧的纹理复杂度,也不调整视频编码器的编码码率,而是沿用视频编码器在编码第二视频帧时的编码码率,对第一视频帧进行编码。以此,可减少视频编码过程中编码码率的调整频次,以尽可能减少视频编码后视频帧流数据的传输对带宽资源的占用率。
在一些实施方式中,为了减少编码后的视频帧流数据对带宽资源的占用率,可先确定准备编码的第一视频帧相对于前一帧已经编码的第二视频帧之间的相似度,如果相似度小于特定阈值,则确定第一视频帧的第一图像纹理值,以确定第一视频帧的纹理复杂度。例如,步骤103之前,还可以包括:
(103.a)确定第一视频帧与第二视频帧之间的相似度;
则步骤103可以包括:当相似度小于预设相似度阈值时,确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值。
其中,预设相似度阈值可以是用于判定准备编码的第一视频帧与前一已经编码的第二视频帧之间的相似程度的阈值,从而判定第一视频帧与第二视频帧之间的差异程度,如果相似度越大,则第一视频帧相对于第二视频帧的差异程度越小,反之,第一视频帧相对于第二视频帧的差异程度越大。通过该预设相似度阈值进行第一视频帧与第二视频帧之间的差异判定,以决策是否需要确定第一视频帧和第二视频帧的图像纹理值,从而进一步调整视频编码器的编码码率。
其中,在确定第一视频帧与第二视频帧之间的相似度时,可以采样颜色相似度估计(Hue Saturation Value,HSV)、直方图统计、哈希相似度统计等算法,通过以上任一中算法来确定待编码帧序列中当前编码进度对应的准备编码的第一视频帧与前一帧已经编码完成的第二视频帧之间的相似度。进一步的,在确定第一视频帧与第二视频帧之间的相似度之后,将该相似度与预设相似度阈值进行对比。
一方面,当第一视频帧与第二视频帧之间的相似度小于预设相似度阈值时,表示第一视频帧与第二视频帧之间的差异过大,此时,确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,以便后续在第一图像纹理值大于第二图像纹理值时,调整视频编码器的编码码率。
另一方面,当相似度大于或等于预设相似度阈值时,通过视频编码器按照当前的编码码率(即在编码第二视频帧时的编码码率)对待编码帧序列中当前预备编码的第一视频帧进行编码。
在一些实施方式中,以直方图统计算法计算第一视频帧与第二视频帧之间的色彩相似度。例如,相似度包括色彩相似度,步骤(103.a)可以包括:
(103.a.1)获取待编码帧序列中当前预备编码的第一视频帧中每个第一像素点的第一像素值,并根据不同的第一像素值的统计数量,生成针对第一视频帧的第一直方图;
(103.a.2)获取第二视频帧中每个第二像素点的第二像素值,并根据不同的第二像素值的统计数量,生成针对第二视频帧的第二直方图;
(103.a.3)基于第一直方图和第二直方图之间的差异,确定第一视频帧与第二视频帧之间的色彩相似度。
其中,第一像素值是指第一视频帧中相应的第一像素点的像素值,第二像素点是指第二视频帧中相应的第二像素点的像素值。
其中,第一直方图是用于统计第一视频帧的各像素值维度对应的第一像素点的数量,第一直方图的宽度可以包括256个像素值维度,即包括像素值0至255,而第一直方图中的每个柱子对应一个目标像素值,而柱子的高度表示该第一视频中该目标像素值对应的第一像素点的统计数量,该第一直方图可以反映第一视频帧的色彩情况。同理,第二直方图是用于统计第二视频帧的各像素值维度对应的第二像素点的数量,第二直方图的宽度可以包括256个像素值维度,即包括像素值0至255,该第二直方图可以反映第二视频帧的色彩情况。
其中,色彩相似度可以表示第一视频帧与第二视频帧在色彩上的相似程度,也反映了第一视频帧与第二视频帧之间的色彩差异。
具体的,在根据直方图统计算法确定第一视频帧与第二视频帧之间的色彩相似度时,首先,可获取第一视频帧中每个第一像素点的第一像素值,并统计第一视频帧中针对每个第一像素值维度对应的第一像素点的统计数量,以每个第一像素点值维度作为直方图的宽(即横坐标的数值),以每个第一像素点值维度对应的第一像素点的统计数量作为直方图中相应柱子的高,生成针对第一视频帧的第一直方图,以表示第一视频帧的色彩情况。同时,获取第二视频帧对应的第二直方图,该第二直方图的生成过程可以参照第一直方图,如在历史时间已经生成,可直接获取第二视频帧对应的第二直方图。进一步的,根据第一直方图与第二直方图之间在各像素值维度上的差异,计算第一视频帧与第二视频帧之间的色彩相似度。以此,通过色彩相似度来评估第一视频帧相对于第二视频帧之间的在色彩特征上的差异程度,以便后续决策是否根据第一视频帧与第二视频帧之间的纹理差异调整视频编码器的编码码率。
在一些实施方式中,根据第一直方图与第二直方图在每个像素值维度上的像素点数量差值,确定第一视频帧与第二视频帧之间的色彩相似度。例如,步骤(103.a.3)可以包括:根据第一直方图确定第一视频帧在每个像素值维度上的第一统计数,以及根据第二直方图确定第二视频帧在每个像素值维度上的第二统计数;根据每个像素值维度上的第一统计数和第二统计数,确定第一视频帧与第二视频帧在每个像素值维度上的像素数量差值;基于每个像素值维度上的像素数量差值,确定第一视频帧与第二视频帧之间的色彩相似度。
其中,第一统计数可以是第一直方图中相应的第一像素点值维度对应的第一像素点的数量,而第二统计数为第二直方图中相应的第二像素点值维度对应的第二像素点的数量。
其中,像素数量差值是指第一直方图与第二直方图之间在相同的像素值维度上的像素点的数量差值。示例性的,第一直方图中像素点值为100的第一像素点的数量为60,第二直方图中像素点值为100的第二像素点的数量为70,则在像素点值100这一维度上的像素数量差值为30。
在根据每个像素值维度上的像素数量差值确定第一视频帧与第二视频帧之间的色彩相似度时,具体的,首先,获取在该像素值维度上第一统计数和第二统计数之间的最大值作为目标值,然后,针对每个像素值维度,确定像素数量差值与目标值之间的目标比值,该目标比值可以表示第一视频帧与第二视频帧在当前的像素值维度上的差异比例,即差异程度,进而,相似度最高为1,通过1减去目标比值,得到第一视频帧与第二视频帧在当前的像素值维度上的色彩子相似度。最后,对各像素值维度上的色彩子相似度进行求和平均,得到色彩相似度。
需要说明的是,关于第二视频帧的第二图像纹理值的计算过程可以参见以上“第一视频帧”的描述,此处不做赘述。
通过以上方式,可在视频帧的编码过程中,确定当前编码进度对应的视频帧的复杂度,以及确定前一视频帧的复杂度,以便后续在确定当前视频帧相对于前一视频帧的纹理复杂度递增时,以实现按照帧级别决策调整视频编码器的编码码率,以满足当前视频帧的画质需求,具有可靠性。
104、当第一图像纹理值标识的纹理复杂度大于第二图像纹理值标识的纹理复杂度时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值。
在本申请实施例中,得到第一视频帧的第一图像纹理值以及第二视频帧的第二图像纹理值之后,将第一图像纹理值与第二图像纹理值分别标识的纹理复杂度进行对比,通过第一视频帧与第二视频帧之间在纹理复杂度上的对比,以便决策后续是否调整比视频编码器的编码码率。以图像纹理值越大,对应视频帧的纹理复杂度就越大的情况,一方面,当第一图像纹理值大于第二图像纹理值时,则决策后续调整视频编码器的编码码率,另一方面,当第一图像纹理值小于或等于第二图像纹理值时,则不调整视频编码器的编码码率,以此,以确保视频编码器的编码码率能够满足当前准备编码的第一视频帧在编码后的视频帧画质,具有可靠性。
其中,该图像纹理比值可以是表示第一视频帧相对于第二视频帧的纹理复杂度的比值,可以理解的是,第一视频帧的纹理复杂度大于第二视频帧的纹理复杂度时,图像纹理比值大于1,表示第一视频帧比第二视频帧复杂。
需要说明的是,当决策后续调整视频编码器的编码码率时,为了合理地调整视频编码器的编码码率,可以确定第一图像纹理与第二图像纹理值之间的比值,作为第一视频帧与第二视频帧之间的图像纹理比值,以便后续根据图像纹理比值来调整视频编码器的编码码率,具体可以是调整在编码第二视频帧时所使用的编码码率。以此,可使得视频编码器的编码码率在调整后,能够满足当前准备编码的第一视频帧在编码之后的视频帧画质需求,且减少视频帧流数据对传输带宽资源的占用量,具有可靠性。
在一些实施方式中,为了避免较为频繁地调整视频编码器的编码码率,可在第一图像纹理值大于第二图像纹理值时,根据第一视频帧与第二视频帧之间的纹理复杂度的差异程度较大,则计算生成图像纹理比值,以便后续调整视频编码器的编码码率。例如,步骤104中的“根据第一图像纹理值和第二图像纹理值确定图像纹理比值”可以包括:获取第一图像纹理值与第二图像纹理值的图像纹理差值;当图像纹理差值大于预设纹理差阈值时,计算第一图像纹理值和第二图像纹理值的图像纹理比值。
其中,图像纹理差值可以表示第一视频帧与第二视频帧之间的纹理差异程度,具体根据第一图像纹理值与第二图像纹理值来确定纹理差值,如果图像纹理差值越大,表示第一视频帧与第二视频帧之间的纹理差异越大,反之,如果图像纹理差值越小,表示第一视频帧与第二视频帧之间的纹理差异越小。
具体的,将第一图像纹理值与第二图像纹理值进行对比,当第一图像纹理值大于第二图像纹理值时,说明当前准备编码的第一视频帧的图像纹理比前一已经编码的第二视频帧的图像纹理更复杂;如果第一视频帧相对于第二视频帧的图像纹理复杂度差异较小,可以继续使用视频编码器在编码第二视频帧时的编码码率对该第一视频帧进行编码,对第一视频帧的画质影响较小,且能够减低传输带宽资源的占用量。
因此,为了避免频繁调高视频编码器的编码码率,当第一图像纹理值大于第二图像纹理值时,还可确定第一图像纹理值与第二图像纹理值的图像纹理差值,并将图像纹理差值与预设纹理差阈值进行对比,该预设纹理差阈值用于判定准备编码的第一视频帧与前一已经编码的第二视频帧之间的差异程度的阈值。一方面,如果图像纹理差值大于预设纹理差阈值,则说明第一视频帧与第二视频帧之间的差异程度较大,视频帧编码器此前的编码码率无法满足第一视频帧的画质要求,此时,需要确定第一图像纹理值与第二图像纹理值之间的图像纹理比值,以便后续按照图像纹理比值来调高视频编码器此前的编码码率。另一方面,如果图像纹理差值小于或等于预设纹理差阈值,则说明第一视频帧与第二视频帧之间的差异程度较小,可不调高视频编码器此前的编码码率,后续可继续沿用在编码第二视频帧时的编码码率对第一视频帧进行编码。以此,降低视频编码器的编码码率的调整频次,且能够减低传输带宽资源的占用量。
通过以上方式,可通过第一图像纹理值与第二图像纹理值进行对比,确定第一视频帧与第二视频帧之间在纹理复杂度上的对比结果,从而,在第一视频帧比第二视频帧的纹理更复杂时,表示当前视频帧相对于前一视频帧的纹理复杂度递增,此时,决策按照第一视频帧与第二视频帧之间的图像纹理比值调整视频编码器的编码码率,实现按照帧级别决策调整视频编码器的编码码率,实现更细粒度、精细地调整视频编码器的编码码率。
105、根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
在本申请实施例中,得到第一视频帧与第二视频帧之间的图像纹理比值之后,可根据图像纹理比值来调整视频编码器此前的编码码率,由于视频编码器的编码码率可能在对待编码帧序列中的前面视频帧的编码过程中实时调整,此时,视频编码器当前的编码码率可以理解为在编码第二视频帧时所使用的编码码率,因此,按照图像纹理比值来调整视频编码器此前的编码码率,使得视频编码器的编码码率的调整幅度与前后视频帧的纹理复杂差异比例相匹配,以更细腻、精确地按照帧级别来调整视频编码器的编码码率,以按照新调整的码率来编码当前的第一视频帧,从而,可在保证第一视频帧编码后的画质的同时,实现最大化节省带宽资源,具有可靠性。
其中,目标编码码率可以是视频编码器的调整之后重新确定的编码码率,该目标编码码率可以是按照图像纹理比值对此前的编码码率进行调整得到,用于对第一视频帧进行编码,以应对图像内容丰富、信息复杂的第一视频帧的编码,保证第一视频帧在编码之后的画质。
需要说明的是,由于网络带宽资源有限,需要合理利用网络带宽资源后续对编码后的视频帧资源进行传输,以在确保视频帧画面质量的同时避免视播放卡顿,并尽可能地节省网络带宽资源。基于此,针对视频编码器的调整/码控过程中,可以设定编码码率的上限值,以限制视频编码器的编码码率超过该上限值,从而,实现在合理使用的网络带宽资源,以在确保视频帧画面质量的同时避免视播放卡顿。
在一些实施方式中,根据图像纹理比值调整视频编码器的编码码率,并将调整得到的码率与视频编码器的限制码率进行对比,从而确定视频编码器最终的目标编码码率。例如,步骤105中的“根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率”,可以包括:获取针对视频编码器的编码码率上限值;根据图像纹理比值对编码码率进行加权处理,得到候选编码码率;当编码码率上限值大于候选编码码率时,按照候选编码码率对视频编码器的编码码率进行调整,得到目标编码码率;当编码码率上限值小于候选编码码率时,按照编码码率上限值对视频编码器的编码码率进行调整,得到目标编码码率。
其中,编码码率上限值可以是视频编码器的编码码率限制值,可以理解为为视频编码器最大的编码码率,该编码码率上限值可以根据带宽资源可用量或所期望的目标带宽资源量来设定,使得在编码码率调整(即码控)过程中,编码码率最大不能超过编码码率上限值,以此,以最大化地确保视频帧画质,同时在限制的带宽资源下使得编码后的视频帧流数据传输流畅,避免视频播放卡顿的现象,具有可靠性。
具体的,在确定对视频编码器的编码码率进行调整时,获取视频编码器当前的编码码率,比如,获取在编码第二视频帧时所使用的编码码率,以及,获取针对视频编码器的编码码率上限值;进一步的,根据图像纹理比值对编码码率进行加权处理,以根据前后视频帧的纹理复杂差异比例作为调整幅度,调高视频编码器的编码码率,从而,实现按照帧级别调整视频编码器的编码码率,得到候选编码码率。进一步的,以视频编码器的编码码率上限值作为码率调整限制阈值,如果调整得到的候选编码码率大于或等于视频编码器的编码码率上限值,则以视频编码器的编码码率上限值作为目标编码码率,反之,如果调整得到的候选编码码率小于视频编码器的编码码率上限值,则按照候选编码码率调整视频编码器的编码码率,即以候选编码码率作为视频编码器的目标编码码率。
在一些实施方式中,视频编码过程是依序对待编码帧序列中的视频帧进行编码的,待编码帧序列中第一视频帧之后的其他视频帧也需要按照第一视频帧的编码过程进行编码。例如,步骤105中的“按照目标编码码率对第一视频帧进行编码”之后,还可以包括:获取待编码帧序列中位于第一视频帧之后且相邻的第三视频帧的第三图像纹理值;当检测到第三图像纹理值大于第一图像纹理值时,确定第三视频帧与第一视频帧之间的目标图像纹理比值;根据目标图像纹理比值调整视频编码器的目标编码码率,得到调整后的目标编码码率,并按照调整后的目标编码码率对第三视频帧进行编码;当检测到第三图像纹理值小于或等于第一图像纹理值时,按照目标编码码率对第三视频帧进行编码。
其中,第三视频帧可以是待编码帧序列中时序处于第一视频帧之后的视频帧,即为第一视频帧的后一视频帧。而第三图像纹理值可以表示该第三视频帧的图像纹理复杂度。假设待编码帧序列中有N个时序排列的视频帧,第一视频帧可以为第i个视频帧,第二视频帧可以为第i+1个视频帧,i大于1且小于N。
具体的,在完成对待编码帧序列中的第一视频帧的编码之后,接下来准备对第一视频帧的后一帧(即第三视频帧)进行编码。在对第三视频帧编码之前,可确定第三视频帧的第三图像纹理值,将第三图像纹理值与第一图像纹理值进行对比。
一方面,如果第三图像纹理值大于第一图像纹理值,说明第三视频帧比第一视频帧的纹理更复杂,视频帧的内容更丰富,此时,决策调整视频编码器的编码码率,此时,计算第三图像纹理值与第一图像纹理值之间的比值,作为确定第三视频帧与第一视频帧之间的目标图像纹理比值,并根据目标图像纹理比值调整视频编码器的目标编码码率,该目标编码码率为视频编码器在对第一视频帧进行编码时的码率,得到目标候选编码码率,此时,还可将目标候选编码码率与编码码率上限值进行对比,如果目标候选编码码率大于编码码率上限值,则将编码码率上限值确定为编码第三视频帧的码率,拒绝调整视频编码器当前的编码码率,如果目标候选编码码率小于编码码率上限值,则将目标候选编码码率作为视频编码器调整后的目标编码码率;进一步的,通过视频编码器按照调整后的目标编码码率对第三视频帧进行编码。
另一方面,如果第三图像纹理值小于或等于第一图像纹理值,则沿用视频编码器此前的目标编码码率,对第三视频帧进行编码,以保证第三视频帧在编码之后的视频画面质量,具有可靠性。
通过以上方式,可按照前后视频帧之间的图像纹理比值来调整视频编码器的编码码率,使得视频编码器的编码码率的调整幅度与前后视频帧的纹理复杂差异比例相匹配,以更细腻、精确地按照帧级别来调整视频编码器的编码码率,按照新调整的码率来编码当前的第一视频帧,以在保证第一视频帧编码后的画质的同时,实现最大化节省带宽资源,具有可靠性。
由本申请实施例的以上整体描述可知,本申请实施例可获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
基于此,本申请可实时获取视频编码器当前的编码码率,然后,按照该编码码率对目标视频源当前的待编码帧序列中的视频帧进行编码处理,进一步的,在编码过程中,实时对比当前预备编码的第一视频帧与前一相邻的第二视频帧之间的纹理复杂度,通过纹理复杂度来表示视频帧的画面内容丰富度,以评估所需的编码码率,如果当前第一视频帧相较于前一帧的纹理较为复杂,根据第一图像纹理值和第二图像纹理值确定第一视频帧与第二视频帧之间的图像纹理比值,最后,按照图像纹理比值将视频编码器的编码码率调整为目标编码码率,以实现视频编码器按照调整得到的目标编码码率对第一视频帧进行编码;以此,相较于相关技术中视频编码器按照固定时长统计的视频源码率进行视频帧编码的方案而言,本申请可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码的视频帧画质。
结合上述实施例所描述的方法,以下将举例作进一步详细说明。
图4是本申请实施例提供的视频编码方法的另一步骤流程示意图。为了便于理解,本申请实施例结合图4进行描述。
在本申请实施例中,将从视频编码装置的角度进行描述,该视频编码装置具体可以集成在计算机设备如终端或服务器中。例如,该计算机设备上的处理器执行视频编码方法对应的程序时,该视频编码方法的具体流程如下:
201、获取目标视频源当前的视频源码率,并根据视频源码率同步更新视频编码器的编码码率。
在本申请实施例中,视频编码器的编码码率是可调整的,为了使得视频编码器的编码码率较为合理,可根据视频源的视频源码率作为依据,调整视频编码码率,使得复杂度较高的视频帧在编码之后的画质较佳。具体可通过减少视频源码率的采集粒度,以采集目标视频源的视频源码率,以同步调整视频编码器的编码码率,实现对视频编码器的编码码率进行较精细的调整,以此作为视频编码的基础码率,具有可靠性。
具体的,可以根据目标视频源的相邻两个关键视频帧之间的间隔,确定目标视频源的视频源码率,从而调整视频编码器的编码码率。需要说明的是,目标视频源的视频帧流数据可通过视频帧序列形式进行组织和传输到服务器,视频帧序列中可以包括不同类型的视频帧,如包括关键视频帧(Intra-coded Frame,I帧)、前向预测帧(Predicted Frame,P帧)和双向预测帧(Bi-directional Predicted Frame,B帧)。可以根据两个关键帧之间的间隔(group of pictures,GOP)来统计确定来两个关键帧之间的视频源码率。
具体的,确定目标视频源的帧率,以及实时检测目标视频源的传输序列中相近的两个关键视频帧之间的间隔,如间隔长度或间隔时长,进而,根据相近的两个关键视频帧之间的间隔以及帧率计算视频源码率,如根据帧率与间隔之间的比值确定视频源码率。进一步的,根据视频源码率同步更新视频编码器中的编码码率,以使得当前的编码码率能够适配视频帧序列中当前两个关键帧之间的待编码帧序列,可以理解为子序列或片段序列。基于此,由于目标视频源实时的视频帧流数据以序列形式进行组织,通过采用关键帧之间的间隔来确定实时阶段的视频源码率,作为视频编码器进行编码时的基础码率,以更贴合对每个视频帧序列的编码码率需求,具有灵活性和可靠性。
202、获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码。
在本申请实施例中,获取到视频编码器实时的编码码率之后,即可获取目标视频源对应的待编码帧序列,以通过视频编码器按照当前的编码码率开始对待编码帧序列中的视频帧进行编码,由于视频编码器的编码过程可以是逐帧编码的,因此,可以按照编码码率对待编码帧序列中排在首位的第一个视频帧进行编码,以便对视频帧进行压缩,提高在特定带宽下单位时间内的数据传输流量,确保播放端的视频播放流畅度。
需要说明的是,服务器在进行视频编码时,可以是一边接收、获取目标视频源的视频帧流数据,并一边对实时获取到的视频帧流数据进行编码处理,假设视频帧流数据以序列形式进行传输时,服务器可先后接收、获取目标视频源的每一个待编码帧序列,并先后对每个待编码帧序列中的视频帧进行编码处理。因此,目标视频源的视频流数据的编码过程是实时进行的,如果服务器已经对历史时间获取到的历史的待编码帧序列中的视频帧完成编码后,当服务器获取到一个待编码帧序列时,且服务器中的视频编码器已更新调整到对应的编码码率时,视频编码器以当前的编码码率作为基础码率,即按照当前实时的编码码率开始对待编码帧序列中首个视频帧进行编码。
203、确定待编码帧序列中当前预备编码的第一视频帧与位于第一视频帧之前相邻的第二视频帧之间的相似度。
在本申请实施例中,由于网络带宽资源有限,为了减少带宽资源的占用率,如果待编码帧序列中的第一视频帧相对于第二视频帧的差异过小,将继续使用视频编码器在对前一视频帧编码时的编码码率对当前编码的视频帧进行编码,其当前编码得到的视频帧画质相对于前一视频帧的画质也是相近的。因此,如果待编码帧序列中的第一视频帧相对于第二视频帧的差异过小,即便第一视频帧的纹理复杂度大于第二视频帧的纹理复杂度,也不调整视频编码器的编码码率,而是沿用视频编码器在编码第二视频帧时的编码码率,对第一视频帧进行编码。以此,可减少视频编码过程中编码码率的调整频次,以尽可能减少视频编码后视频帧流数据的传输对带宽资源的占用率。
其中,该相似度可以是指第一视频帧与第二视频帧之间的色彩相似度。
具体的,在根据直方图统计算法确定第一视频帧与第二视频帧之间的色彩相似度时,首先,可获取第一视频帧中每个第一像素点的第一像素值,并统计第一视频帧中针对每个第一像素值维度对应的第一像素点的统计数量,以每个第一像素点值维度作为直方图的宽(即横坐标的数值),以每个第一像素点值维度对应的第一像素点的统计数量作为直方图中相应柱子的高,生成针对第一视频帧的第一直方图,以表示第一视频帧的色彩情况。同时,获取第二视频帧对应的第二直方图,该第二直方图的生成过程可以参照第一直方图,如在历史时间已经生成,可直接获取第二视频帧对应的第二直方图。进一步的,确定第一直方图中各个像素值维度上的像素点的第一统计数量,以及确定第二直方图中各个像素值维度上的像素点的第二统计数量,根据每个像素值维度上的第一统计数和第二统计数,确定第一视频帧与第二视频帧在每个像素值维度上的像素数量差值;基于每个像素值维度上的像素数量差值,确定第一视频帧与第二视频帧之间的色彩相似度。
以此,通过色彩相似度来评估第一视频帧相对于第二视频帧之间的在色彩特征上的差异程度,以便后续决策是否根据第一视频帧与第二视频帧之间的纹理差异调整视频编码器的编码码率。
204、当相似度小于预设相似度阈值时,确定第一视频帧的第一图像纹理值,以及确定第二视频帧的第二图像纹理值。
在本申请实施例中,将第一视频帧与第二视频帧之间的相似度,与预设相似度阈值进行对比,该预设相似度阈值可以是用于判定准备编码的第一视频帧与前一已经编码的第二视频帧之间的相似程度,从而判定第一视频帧与第二视频帧之间的差异程度。如果相似度越大,则第一视频帧相对于第二视频帧的差异程度越小,反之,第一视频帧相对于第二视频帧的差异程度越大。通过该预设相似度阈值进行第一视频帧与第二视频帧之间的差异判定,以决策是否需要确定第一视频帧和第二视频帧的图像纹理值。
一方面,当第一视频帧与第二视频帧之间的相似度小于预设相似度阈值时,表示第一视频帧与第二视频帧之间的差异过大,此时,确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,以便后续在第一图像纹理值大于第二图像纹理值时,调整视频编码器的编码码率。
另一方面,当相似度大于或等于预设相似度阈值时,通过视频编码器按照当前的编码码率(即在编码第二视频帧时的编码码率)对待编码帧序列中当前预备编码的第一视频帧进行编码。
205、当第一图像纹理值大于第二图像纹理值时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值。
在本申请实施例中,在得到第一视频帧的第一图像纹理值,以及第二视频帧的第二图像纹理值之后,将第一图像纹理值与第二图像纹理值进行对比,以确定第一视频帧与第二视频帧之间的纹理复杂度,本步骤以图像纹理值越大,纹理复杂度越大为例。
如果图像纹理差值大于预设纹理差阈值,则说明第一视频帧与第二视频帧之间的差异程度较大,视频帧编码器此前的编码码率无法满足第一视频帧的画质要求,此时,需要确定第一图像纹理值与第二图像纹理值之间的图像纹理比值,以便后续按照图像纹理比值来调高视频编码器此前的编码码率。另一方面,如果图像纹理差值小于或等于预设纹理差阈值,则说明第一视频帧与第二视频帧之间的差异程度较小,可不调高视频编码器此前的编码码率,后续可继续沿用在编码第二视频帧时的编码码率对第一视频帧进行编码。以此,降低视频编码器的编码码率的调整频次,且能够减低传输带宽资源的占用量。
206、根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
在本申请实施例中,可根据图像纹理比值来调整视频编码器此前的编码码率,由于视频编码器的编码码率可能在对待编码帧序列中的前面视频帧的编码过程中实时调整,此时,视频编码器当前的编码码率可以理解为在编码第二视频帧时所使用的编码码率,因此,按照图像纹理比值来调整视频编码器此前的编码码率,使得视频编码器的编码码率的调整幅度与前后视频帧的纹理复杂差异比例相匹配,以更细腻、精确地按照帧级别来调整视频编码器的编码码率,以按照新调整的码率来编码当前的第一视频帧,从而,可在保证第一视频帧编码后的画质的同时,实现最大化节省带宽资源,具有可靠性。
具体的,在确定对视频编码器的编码码率进行调整时,获取视频编码器当前的编码码率,比如,获取在编码第二视频帧时所使用的编码码率,以及,获取针对视频编码器的编码码率上限值;进一步的,根据图像纹理比值对编码码率进行加权处理,以根据前后视频帧的纹理复杂差异比例作为调整幅度,调高视频编码器的编码码率,从而,实现按照帧级别调整视频编码器的编码码率,得到候选编码码率。进一步的,以视频编码器的编码码率上限值作为码率调整限制阈值,如果调整得到的候选编码码率大于或等于视频编码器的编码码率上限值,则以视频编码器的编码码率上限值作为目标编码码率,反之,如果调整得到的候选编码码率小于视频编码器的编码码率上限值,则按照候选编码码率调整视频编码器的编码码率,即以候选编码码率作为视频编码器的目标编码码率。
其中,编码码率上限值可以是视频编码器的编码码率限制值,可以理解为为视频编码器最大的编码码率,该编码码率上限值可以根据带宽资源可用量或所期望的目标带宽资源量来设定,使得在编码码率调整(即码控)过程中,编码码率最大不能超过编码码率上限值,以此,以最大化地确保视频帧画质,同时在限制的带宽资源下使得编码后的视频帧流数据传输流畅,避免视频播放卡顿的现象,具有可靠性。
通过以上方式,可按照前后视频帧之间的图像纹理比值来调整视频编码器的编码码率,使得视频编码器的编码码率的调整幅度与前后视频帧的纹理复杂差异比例相匹配,以更细腻、精确地按照帧级别来调整视频编码器的编码码率,按照新调整的码率来编码当前的第一视频帧,以在保证第一视频帧编码后的画质的同时,实现最大化节省带宽资源,具有可靠性。
为了便于对本申请实施例的理解,将以具体的应用场景实例对本申请实施例进行描述。具体的,通过执行以上步骤201-206,对该应用场景实例进行描述。
需要说明的是,该视频编码方法适用于视频直播、实时音视频等场景,如游戏直播、游戏画面、多人组队协作玩游戏、影视在线观看等。其中,该视频编码主要时对直播中的视频帧进行压缩,以提高视频文件在单位时间内的数据流量,可以理解为数据传输量,以在满足目标带宽的前提下达到视频画面质量和用户观看卡顿时长之间的最优秀平衡目的,提升视频画质。以下,以该视频编码场景实例视频编码方法进行介绍,具体如下:
一、该视频编码场景实例简介如下:
视频编码可以基于视频编码码控(即码率控制)来实现,其中,视频编码码控通过分析视频的复杂度和当前剩余比特数目,调整编码过程中图像层和编码单元层量化参数,使得编码器在满足目标带宽(比如,视频源码率相近的范围值)的前提下达到视频质量和用户观看卡顿时长之间最优平衡目的。因此,在直播或实时音视频场景中,可根据视频源的视频源码率来调整控制编码器的编码码率,以保证视频画面质量。
本视频编码场景实例基于帧级别的码率计算,以调整控制编码器的编码码率,使得编码器在满足目标带宽(如,视频源码率相近的范围值)的前提下达到视频质量和用户观看卡顿时长之间最优平衡目的,保证视频画质。
图5为本申请实施例提供的视频编码场景示例图。为了在有限带宽资源内实现对视频数据传输的优化分配问题,结合图5所示,本视频编码场景具体如下:输入一个视频源,视频源以视频帧(图像)序列方式进行传输,序列中包括多个视频帧,在对每个视频帧进行编码过程中,可对视频帧进行预分析,以确定视频帧的时空复杂度,从而基于视频帧的时空复杂度对编码器进行码率控制,具体的,调整编码器中图像层的量化参数(Quantization Parameter,QP),以及调整编码器中编码单元的量化参数(QP),以此,使得编码器的实际码率得到压缩缓存,以按照在满足目码率对视频帧进行编码,如此,使得视频画质质量在目标带宽下尽可能达到最优。
图6为本申请实施例提供的视频编码的码控场景中的码率变化示例图。参见图6所示,在视频编码进度中,进度A到B之间不执行码控,在A至B阶段,实际码率大小起伏不定,时高时低,不稳定,实际码率存在超过目标带宽上限的情况,为了使得编码码率满足目标带宽要求,可进行码控,经过码控,可使得输出码率一般在目标带宽上限以下,且输出码率偏向稳定,不存在大幅度的上下起伏的情况,有效确保了所编码的视频画面质量,具有可靠性。
二、该视频编码场景实例的具体实施过程如下:
本视频编码场景实例不限于应用在视频直播和视频点播场景,支持多种数据格式的视频媒体流数据的编码,例如,支持实时消息协议(Real-Time Messaging Protocol,RTMP)、流媒体(FLASH VIDEO,FLV)、码率自适应(HTTP Live Streaming,HLS)、动态自适应流媒体(Dynamic Adaptive Streaming over HTTP,DASH)、网页视频语音实时通讯(Web Real-Time Communications,WebRTC)、数字电视广播(Transport Stream,TS)、动态图像(Moving Picture Experts Group 4,MP4)等格式。以视频直播场景为例,主播的客户端可以实时传输视频流数据到视频编码服务器,以通过视频编码服务器对视频直播流进行编码,直播流可以是以帧序列为单位组织连续多个视频帧形成的图像流,通过视频编码服务器对帧序列中的每个视频帧进行编码处理,该编码过程可以理解为压缩,以利于在有限的带宽资源内提高数据流量,确保视频直播画面流畅、不卡顿。
其中,视频编码过程可以包括编码码率控制调整和视频帧编码两部分,本视频编码场景实例将着重介绍编码码率控制调整的过程。
(1)编码码率控制调整
图7为本申请实施例提供的视频编码流程示例图。结合图7,对视频编码过程中的编码码率控制调整进行叙述,具体如下:
视频帧以序列为单位进行组织,一个序列的第一个视频帧叫做立即刷新图像(Instantaneous Decoder Refresh,IDR)视频帧,IDR帧都是关键帧(I帧)图像,一个待编码的帧序列中可以包含很多I帧图像,I帧图像之后的图像可以引用I帧图像之间的图像做运动参考。
(1.1)根据关键帧之间的间隔时长统计视频源码率。
在视频直播或实时音视频场景中,为了满足视频编码过程的码率需求,可以根据视频源码率来初步调整视频编码器的编码码率,以此编码码率作为当前待编码帧序列的视频编码基础编码码率,以便在此基础上进行编码码率调整控制。该视频源编码可以根据两个关键帧(I帧)之间的帧间隔(group of pictures,GOP)粒度实时确定,帧间隔可以表示一个视频帧组(待编码帧组),具体可以先确定两个关键帧(I帧)之间的帧长度,以及确定播放客户端的帧率,从而根据帧率与帧长度之间的比值确定单位时间的视频帧组的数量,即视频源码率,进而,根据当前的视频源码率动态加载更新到视频编码内核(即视频编码器),以使得视频编码器获取当前基础的编码码率。
(1.2)按照帧级别检测任意相邻的两个视频画面(视频帧)之间是否发现突变,检测方法可以为颜色相似度估计(Hue Saturation Value,HSV)、直方图统计、哈希相似度统计等。以按照帧级别直方图检测任意相邻的两个视频画面是否突变为例,具体如下:
对于相邻的两帧视频画面,分别计算生成每个视频画面的直方图,具体如下:计算视频帧中每个像素点的像素值,并按照0至255,一共256个像素值标量,统计每个像素值对应的像素点数量,从而,基于每个像素值对应的像素点数量生成该视频帧的关于颜色的直方图。
进一步的,基于两个视频帧的直方图,计算视频帧之间的色彩相似度,具体表达如下:
其中,Sh表示两个视频帧之间的色彩相似度,相似度越接近1,代表两个视频帧越相似,相似度越接近0,代表两个视频帧间差异越大;n表示直方图宽度,宽度最大为256,ai表示其中一个视频帧在直方图的像素值i上的值(即像素点的统计量),bi表示其中一个视频帧在直方图的像素值i上的值。
如此,通过以上方式,可确定两个视频帧之间的相似度,从而确定两个视频帧之间的差异值,具体可根据“1-Sh”表示差异值。
(1.3)对于相邻的两个视频画面,如果差异值超过20%,则计算这两帧视频画面的纹理复杂度。例如,画面纹理复杂度分析方法有:欧几里得距离、统计直方图、局部二值模式(Local Binary Patterns,LBP)检测算法以及卷积神经网络(Convolutional Neural Networks,CNN)特征提取分类等算法等,以LBP检测算法为例,局部二值模式是一种用来描述图像局部特征的算子,LBP特征具有灰度不变性和旋转不变性等显著优点,具体过程如下:
图8是本申请实施例提供的视频画面的图像纹理值的计算场景示例图。参见图8所示,对图像纹理值的计算过程进行叙述。原始的LBP算子定义为在3*3的窗口内,以窗口中心像素为阈值,将相邻的8个像素的灰度值与其进行比较,若周围像素值大于中心像素值,则该像素点的位置被标记为1,否则为0。这样,3*3邻域内的8个点经比较可产生8位二进制数(通常转换为十进制数即LBP码,共256种),即得到该窗口中心像素点的LBP值,如图8所示,得到(01111100)10=124,并用这个值来反映该区域的纹理信息,综合各画面检测的区域LBP值汇总计算视频帧纹理LEB值。
需要说明的是,在检测视频帧的图像纹理值时,算子窗口越小,一个视频画面能分的窗口越多,计算量就会越大,反之,如果窗口越大,分到的窗口越少,计算量就会相对减少,因此,可以根据视频画面分辨率和算力大小自动调整视频帧的检测区域的大小,以减少在计算图像纹理值时的计算量。
需要说明的是,在检测视频帧的图像纹理值时,视频画面分辨率越大,对于同样大小的窗口,分到的窗口越多,计算量越大。基于此,可通过下采样方式调整视频画面分辨率大小,例如,将4K分辨率的视频画面下采样得到2K分辨率的视频画面,分到的窗口就减少4倍了,计算量就减少4倍了,如此,可以用一个2K分辨率的视频画面进行窗口进行计算纹理值,从而替代使用4K分辨率的视频画面的窗口计算值,取一个相似值。
(1.4)纹理复杂度越高,编码所消耗的码率就越高,如果当前的视频帧的图像纹理值大于前一视频帧的图像纹理值,则调整视频编码器的编码码率。例如,当前视频帧的图像纹理值为LEB1,上一帧视频帧的图像纹理值为LEB0,如果LEB1>LEB0,则实时更新增加视频编码内核的视频编码码率,设当前视频编码内核的编码码率值为bitrate,视频编码内核可配置最大视频码率为max-bitrate,则调整视频编码内核的编码码率,得到目标编码码率,具体表示为:bitrate=min(max-bitrate,bitrate*LEB1/LEB0)。
在本视频编码场景中,在对同一序列中的多个视频帧进行编码时,bitrate可以迭代更新,基于前一帧刻的bitrate编码码率进行调整。
(2)视频帧编码。具体的,针对待编码帧序列中的每个视频帧,按照循序渐渐方式,依序对每帧进行编码,并在编码过程中,根据上述(1)中(1.1)至(1.4)流程进行调整视频编码内核的编码码率,以按照调整后的编码码率对当前帧的视频帧进行编码。
对于整个视频直播或视频点播的视频编码场景中,按照上述(1)编码码率控制调整,以及(2)视频帧编码,完成对整个视频直播或视频点播过程的编码,直至结束。实时的动态检测视频画面是否有从静止或相对码率比较低的场景突然切到码率比较高、画面比较复杂的场景,如果有就实时调整视频编码码率只上调不下降,解决这类场景切换导致的现有的视频码率统计方法统计延迟问题,由于视频码率统计不足出现视频编码内核码率分配不足导致画质比较差的情况
通过执行以上视频编码场景实例,可以实现如下效果:基于帧级码率计算优化提升画质码控,以使得视频编码器的编码码率尽量接近视频源码率,同时不超过设置的目标带宽,如此,当视频画面场景稳定以后,固定时长码率统计可以保证统计的视频码率不会超过源始流,防止由于实时帧动态调整导致码率失控,向上增加比较多,最后导致视频码率过高反而影响以后观众的视频观看质量体验。
由上述可知,本申请实施例可实时获取视频编码器当前的编码码率,然后,按照该编码码率对目标视频源当前的待编码帧序列中的视频帧进行编码处理,进一步的,在编码过程中,实时对比当前预备编码的第一视频帧与前一相邻的第二视频帧之间的纹理复杂度,通过纹理复杂度来表示视频帧的画面内容丰富度,以评估所需的编码码率,如果当前第一视频帧相较于前一帧的纹理较为复杂,根据第一图像纹理值和第二图像纹理值确定第一视频帧与第二视频帧之间的图像纹理比值,最后,按照图像纹理比值将视频编码器的编码码率调整为目标编码码率,以实现视频编码器按照调整得到的目标编码码率对第一视频帧进行编码;以此,相较于相关技术中视频编码器按照固定时长统计的视频源码率进行视频帧编码的方案而言,本申请可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码的视频帧画质。
以上各个步骤的具体实施可参见前面的实施例,在此不再赘述。
为便于更好的实施本申请实施例提供的视频编码方法,本申请实施例还提供一种基于上述视频编码方法的装置。其中名词的含义与上述视频编码方法中相同,具体实现细节可以参考方法实施例中的说明。
请参阅图9,图9为本申请实施例提供的视频编码装置的结构示意图,该视频编码装置集成于本申请的计算机设备,其中该视频编码装置可以包括第一获取单元401、编码单元402、第一确定单元403、第二确定单元404和调整单元405。
获取单元401,用于获取视频编码器当前的编码码率;
编码单元402,用于获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率对待编码帧序列中的首个视频帧进行编码;
第一确定单元403,用于确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;
第二确定单元404,用于当第一图像纹理值标识的纹理复杂度大于第二图像纹理值标识的纹理复杂度时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;
调整单元405,用于根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
在一些实施方式中,视频编码装置还包括第三确定单元,用于:
确定第一视频帧与第二视频帧之间的相似度;
则第一确定单元403,还用于:
当相似度小于预设相似度阈值时,确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值。
在一些实施方式中,相似度包括色彩相似度,第三确定单元,还用于:
获取第一视频帧中每个第一像素点的第一像素值,并根据不同的第一像素值的统计数量,生成针对第一视频帧的第一直方图;
获取第二视频帧中每个第二像素点的第二像素值,并根据不同的第二像素值的统计数量,生成针对第二视频帧的第二直方图;
基于第一直方图和第二直方图之间的差异,确定第一视频帧与第二视频帧之间的色彩相似度。
在一些实施方式中,第三确定单元,还用于:
根据第一直方图确定第一视频帧在每个像素值维度上的第一统计数,以及根据第二直方图确定第二视频帧在每个像素值维度上的第二统计数;
根据每个像素值维度上的第一统计数和第二统计数,确定第一视频帧与第二视频帧在每个像素值维度上的像素数量差值;
基于每个像素值维度上的像素数量差值,确定第一视频帧与第二视频帧之间的色彩相似度。
在一些实施方式中,第二确定单元404,还用于:
获取第一图像纹理值与第二图像纹理值的图像纹理差值;
当图像纹理差值大于预设纹理差阈值时,计算第一图像纹理值和第二图像纹理值的图像纹理比值。
在一些实施方式中,第一确定单元403,还用于:
获取第一视频帧中每个第一像素点的灰度值;
根据每个第一像素点的灰度值确定第一视频帧的第一图像纹理值。
在一些实施方式中,第一确定单元403,还用于:
获取目标局部纹理窗口;
按照目标局部纹理窗口,对第一视频帧中的第一像素点进行划分,得到划分后的多个目标局部区域;
基于每个目标局部区域内包含的第一像素点的灰度值,确定第一视频帧中每个目标局部区域对应的第一局部纹理值;
基于每个目标局部区域对应的第一局部纹理值,确定第一视频帧的第一图像纹理值。
在一些实施方式中,第一确定单元403,还用于:
确定每个目标局部区域内的中心第一像素点以及中心第一像素点周围的边缘第一像素点;
针对每个目标局部区域,将每个边缘第一像素点的灰度值与中心第一像素点的灰度值进行大小对比,得到每个目标局部区域的多个对比结果;
将每个目标局部区域的多个对比结果分别进行二值化处理,得到每个目标局部区域对应的第一局部纹理值。
在一些实施方式中,第一确定单元403,还用于:
获取候选局部纹理窗口,并确定候选局部纹理窗口的候选窗口范围值;
获取图像算力资源的目标可用资源量,并根据目标可用资源量查询窗口范围列表,得到目标窗口范围值,窗口范围列表包括不同的可用资源量与窗口范围值之间的关联关系;
当候选窗口范围值小于目标窗口范围值时,根据目标窗口范围值调整候选局部纹理窗口,得到目标局部纹理窗口;
当候选窗口范围值大于或等于目标窗口范围值时,将候选局部纹理窗口确定为目标局部纹理窗口。
在一些实施方式中,视频编码装置还包括处理单元,用于:
获取待编码帧序列中当前预备编码的第一视频帧对应的图像分辨率信息;
基于图像分辨率信息,对第一视频帧进行下采样处理,得到下采样处理后的第一视频帧;
则第一确定单元,还用于:获取下采样处理后的第一视频帧中每个第一像素点的灰度值。
在一些实施方式中,调整单元405,还用于:
获取针对视频编码器的编码码率上限值;
根据图像纹理比值对编码码率进行加权处理,得到候选编码码率;
当编码码率上限值大于候选编码码率时,按照候选编码码率对视频编码器的编码码率进行调整,得到目标编码码率;
当编码码率上限值小于候选编码码率时,按照编码码率上限值对视频编码器的编码码率进行调整,得到目标编码码率。
在一些实施方式中,调整单元405,还用于:
获取待编码帧序列中位于第一视频帧之后且相邻的第三视频帧的第三图像纹理值;
当检测到第三图像纹理值标识的纹理复杂度大于第一图像纹理值标识的纹理复杂度时,确定第三视频帧与第一视频帧之间的目标图像纹理比值;
根据目标图像纹理比值调整视频编码器的目标编码码率,得到调整后的目标编码码率,并按照调整后的目标编码码率对第三视频帧进行编码;
当检测到第三图像纹理值标识的纹理复杂度小于或等于第一图像纹理值标识的纹理复杂度时,按照目标编码码率对第三视频帧进行编码。
在一些实施方式中,获取单元401,还用于:
获取目标视频源当前的视频源码率;
根据视频源码率同步更新视频编码器的编码码率。
由上述可知,本申请实施例可实时获取视频编码器当前的编码码率,然后,按照该编码码率对目标视频源当前的待编码帧序列中的视频帧进行编码处理,进一步的,在编码过程中,实时对比当前预备编码的第一视频帧与前一相邻的第二视频帧之间的纹理复杂度,通过纹理复杂度来表示视频帧的画面内容丰富度,以评估所需的编码码率,如果当前第一视频帧相较于前一帧的纹理较为复杂,根据第一图像纹理值和第二图像纹理值确定第一视频帧与第二视频帧之间的图像纹理比值,最后,按照图像纹理比值将视频编码器的编码码率调整为目标编码码率,以实现视频编码器按照调整得到的目标编码码率对第一视频帧进行编码;以此,相较于相关技术中视频编码器按照固定时长统计的视频源码率进行视频帧编码的方案而言,本申请可在对目标视频源的待编码帧序列的编码过程中,对比前后视频帧之间的纹理复杂度,当在后的视频帧的纹理相较复杂于前视频帧时,按照前后视频帧的纹理比例来调整视频编码器的编码码率,如此,可实现按照帧级别灵活、精细地调整视频编码器的编码码率,以确保视频编码器对在后的视频帧的编码质量,保证视频编码的视频帧画质。
以上各个单元的具体实施可参见前面的实施例,在此不再赘述。
参见图10,图10为本申请实施例提供的终端的结构示意图,其包含了实现本申请实施例的终端140的部分的结构框,该终端140包括:射频(Radio Frequency,简称RF)电路510、存储器515、输入单元520、显示单元540、传感器550、音频电路560、无线保真(wireless fidelity,简称WiFi)模块570、处理器580、以及电源590等部件。本领域技术人员可以理解,图11示出的终端140结构并不构成对手机或电脑的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
RF电路510可用于收发信息或通话过程中,信号的接收和发送,特别地,将基站的下行信息接收后,给处理器580处理;另外,将设计上行的数据发送给基站。
存储器515可用于存储软件程序以及模块,处理器580通过运行存储在存储器515的软件程序以及模块,从而执行终端的各种功能应用以及视频编码。
输入单元520可用于接收输入的数字或字符信息,以及产生与终端的设置以及功能控制有关的键信号输入。具体地,输入单元520可包括触控面板531以及其他输入装置532。
显示单元540可用于显示输入的信息或提供的信息以及终端的各种菜单。显示单元540可包括显示面板541。
音频电路560、扬声器561,传声器562可提供音频接口。
在本实施例中,该终端140所包括的处理器580可以执行前面实施例的视频编码方法。
本申请实施例的终端140包括但不限于手机、电脑、智能语音交互设备、智能家电、车载终端、飞行器等。本发明实施例可应用于各种场景,包括但不限于云技术、人工智能、智慧交通、辅助驾驶等。
图11为本申请实施例提供的服务器的结构示意图,其包含了实施本申请实施例的服务器110的部分的结构框。服务器110可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(Central Processing Units,简称CPU)622(例如,一个或一个以上处理器)和存储器632,一个或一个以上存储应用程序642或数据644的存储介质630(例如一个或一个以上海量存储装置)。其中,存储器632和存储介质630可以是短暂存储或持久存储。存储在存储介质630的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对服务器600中的一系列指令操作。更进一步地,中央处理器622可以设置为与存储介质630通信,在服务器600上执行存储介质630中的一系列指令操作。
服务器600还可以包括一个或一个以上电源626,一个或一个以上有线或无线网络接口650,一个或一个以上输入输出接口658,和/或,一个或一个以上操作系统641,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
服务器600中的中央处理器622可以用于执行本申请实施例的视频编码方法,具体如下:
获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值标识的纹理复杂度大于第二图像纹理值标识的纹理复杂度时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质用于存储程序代码,程序代码用于执行前述各个实施例的视频编码方法,具体如下:
获取视频编码器当前的编码码率;获取目标视频源的待编码帧序列,并通过视频编码器按照编码码率开始对待编码帧序列中的首个视频帧进行编码;确定待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于第一视频帧之前相邻的第二视频帧的第二图像纹理值,第一视频帧为首个视频帧之后的任意视频帧;当第一图像纹理值标识的纹理复杂度大于第二图像纹理值标识的纹理复杂度时,根据第一图像纹理值和第二图像纹理值确定图像纹理比值;根据图像纹理比值调整视频编码器的编码码率,得到目标编码码率,并按照目标编码码率对第一视频帧进行编码。
本申请实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序。计算机设备的处理器读取该计算机程序并执行,使得该计算机设备执行实现上述的视频编码方法。
此外,术语“包括”和“包含”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或装置不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或装置固有的其它步骤或单元。
应当理解,在本申请中,“至少一个(项)”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系,例如,“A和/或B”可以表示:只存在A,只存在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b或c中的至少一项(个),可以表示:a,b,c,“a和b”,“a和c”,“b和c”,或“a和b和c”,其中a,b,c可以是单个,也可以是多个。
应了解,在本申请实施例的描述中,多个(或多项)的含义是两个以上,大于、小于、超过等理解为不包括本数,以上、以下、以内等理解为包括本数。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对相关技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机装置(可以是个人计算机,服务器,或者网络装置等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
还应了解,本申请实施例提供的各种实施方式可以任意进行组合,以实现不同的技术效果。
本申请实施例中,术语“模块”或“单元”是指有预定功能的计算机程序或计算机程序的一部分,并与其他相关部分一起工作以实现预定目标,并且可以通过使用软件、硬件(如处理电路或存储器)或其组合来全部或部分实现。同样的,一个处理器(或多个处理器或存储器)可以用来实现一个或多个模块或单元。此外,每个模块或单元都可以是包含该模块或单元功能的整体模块或单元的一部分。
以上是对本申请的实施方式的具体说明,但本申请并不局限于上述实施方式,熟悉本领域的技术人员在不违背本申请精神的条件下还可作出种种等同的变形或替换,这些等同的变形或替换均包括在本申请权利要求所限定的范围内。

Claims (17)

  1. 一种视频编码方法,所述方法由计算机设备执行,所述方法包括:
    获取视频编码器当前的编码码率;
    获取目标视频源的待编码帧序列,并通过所述视频编码器按照所述编码码率对所述待编码帧序列中的首个视频帧进行编码;
    确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于所述第一视频帧之前相邻的第二视频帧的第二图像纹理值,所述第一视频帧为所述首个视频帧之后的任意视频帧;
    当所述第一图像纹理值标识的纹理复杂度大于所述第二图像纹理值标识的纹理复杂度时,根据所述第一图像纹理值和所述第二图像纹理值确定图像纹理比值;
    根据所述图像纹理比值调整所述视频编码器的编码码率,得到目标编码码率,并按照所述目标编码码率对所述第一视频帧进行编码。
  2. 根据权利要求1所述的方法,所述确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值之前,还包括:
    确定所述第一视频帧与所述第二视频帧之间的相似度;
    则所述确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,包括:
    当所述相似度小于预设相似度阈值时,确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值。
  3. 根据权利要求2所述的方法,所述相似度包括色彩相似度,所述确定所述第一视频帧与所述第二视频帧之间的相似度,包括:
    获取所述第一视频帧中每个第一像素点的第一像素值,并根据不同的所述第一像素值的统计数量,生成针对所述第一视频帧的第一直方图;
    获取所述第二视频帧中每个第二像素点的第二像素值,并根据不同的所述第二像素值的统计数量,生成针对所述第二视频帧的第二直方图;
    基于所述第一直方图和所述第二直方图之间的差异,确定所述第一视频帧与所述第二视频帧之间的色彩相似度。
  4. 根据权利要求3所述的方法,所述基于所述第一直方图和所述第二直方图之间的差异,确定所述第一视频帧与所述第二视频帧之间的所述色彩相似度,包括:
    根据所述第一直方图确定所述第一视频帧在每个像素值维度上的第一统计数,以及根据所述第二直方图确定所述第二视频帧在每个像素值维度上的第二统计数;
    根据每个像素值维度上的第一统计数和第二统计数,确定所述第一视频帧与所述第二视频帧在每个像素值维度上的像素数量差值;
    基于每个像素值维度上的像素数量差值,确定所述第一视频帧与所述第二视频帧之间的所述色彩相似度。
  5. 根据权利要求1所述的方法,所述根据所述第一图像纹理值和所述第二图像纹理值确定图像纹理比值,包括:
    获取第一图像纹理值与所述第二图像纹理值的图像纹理差值;
    当所述图像纹理差值大于预设纹理差阈值时,计算所述第一图像纹理值和所述第二图像纹理值的图像纹理比值。
  6. 根据权利要求1-5任意一项所述的方法,所述确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,包括:
    获取所述第一视频帧中每个第一像素点的灰度值;
    根据每个所述第一像素点的灰度值确定所述第一视频帧的第一图像纹理值。
  7. 根据权利要求6所述的方法,所述根据每个所述第一像素点的灰度值确定所述第一视频帧的第一图像纹理值,包括:
    获取目标局部纹理窗口;
    按照所述目标局部纹理窗口,对所述第一视频帧中的第一像素点进行划分,得到划分后的多个目标局部区域;
    基于每个目标局部区域内包含的第一像素点的灰度值,确定所述第一视频帧中每个目标局部区域对应的第一局部纹理值;
    基于每个目标局部区域对应的第一局部纹理值,确定所述第一视频帧的第一图像纹理值。
  8. 根据权利要求7所述的方法,所述基于每个目标局部区域内包含的第一像素点的灰度值,确定所述第一视频帧中每个目标局部区域对应的第一局部纹理值,包括:
    确定每个目标局部区域内的中心第一像素点以及所述中心第一像素点周围的边缘第一像素点;
    针对每个目标局部区域,将每个所述边缘第一像素点的灰度值与所述中心第一像素点的灰度值进行大小对比,得到每个目标局部区域的多个对比结果;
    将每个目标局部区域的多个对比结果分别进行二值化处理,得到每个目标局部区域对应的第一局部纹理值。
  9. 根据权利要求8所述的方法,所述获取目标局部纹理窗口,包括:
    获取候选局部纹理窗口,并确定所述候选局部纹理窗口的候选窗口范围值;
    获取图像算力资源的目标可用资源量,并根据所述目标可用资源量查询窗口范围列表,得到目标窗口范围值,所述窗口范围列表包括不同的可用资源量与窗口范围值之间的关联关系;
    当所述候选窗口范围值小于所述目标窗口范围值时,根据所述目标窗口范围值调整所述候选局部纹理窗口,得到目标局部纹理窗口;
    当所述候选窗口范围值大于或等于所述目标窗口范围值时,将所述候选局部纹理窗口确定为目标局部纹理窗口。
  10. 根据权利要求6至9任一项所述的方法,所述获取所述待编码帧序列中当前预备编码的第一视频帧中每个第一像素点的灰度值之前,还包括:
    获取所述待编码帧序列中当前预备编码的第一视频帧对应的图像分辨率信息;
    基于所述图像分辨率信息,对所述第一视频帧进行下采样处理,得到下采样处理后的第一视频帧;
    则所述获取所述待编码帧序列中当前预备编码的第一视频帧中每个第一像素点的灰度值,包括:
    获取所述下采样处理后的第一视频帧中每个第一像素点的灰度值。
  11. 根据权利要求1所述的方法,所述根据所述图像纹理比值调整所述视频编码器的编码码率,得到目标编码码率,包括:
    获取针对所述视频编码器的编码码率上限值;
    根据所述图像纹理比值对所述编码码率进行加权处理,得到候选编码码率;
    当所述编码码率上限值大于所述候选编码码率时,按照所述候选编码码率对所述视频编码器的编码码率进行调整,得到目标编码码率;
    当所述编码码率上限值小于所述候选编码码率时,按照所述编码码率上限值对所述视频编码器的编码码率进行调整,得到目标编码码率。
  12. 根据权利要求1-11任意一项所述的方法,所述按照所述目标编码码率对所述第一视频帧进行编码之后,还包括:
    获取所述待编码帧序列中位于所述第一视频帧之后且相邻的第三视频帧的第三图像纹理值;
    当检测到所述第三图像纹理值标识的纹理复杂度大于所述第一图像纹理值标识的纹理复杂度时,确定所述第三视频帧与所述第一视频帧之间的目标图像纹理比值;
    根据所述目标图像纹理比值调整所述视频编码器的所述目标编码码率,得到调整后的目标编码码率,并按照所述调整后的目标编码码率对所述第三视频帧进行编码;
    当检测到所述第三图像纹理值标识的纹理复杂度小于或等于所述第一图像纹理值标识的纹理复杂度时,按照所述目标编码码率对所述第三视频帧进行编码。
  13. 根据权利要求1-12任意一项所述的方法,所述获取视频编码器当前的编码码率,包括:
    获取目标视频源当前的视频源码率;
    根据所述视频源码率同步更新视频编码器的编码码率。
  14. 一种视频编码装置,包括:
    获取单元,用于获取视频编码器当前的编码码率;
    编码单元,用于获取目标视频源的待编码帧序列,并通过所述视频编码器按照所述编码码率对所述待编码帧序列中的首个视频帧进行编码;
    第一确定单元,用于确定所述待编码帧序列中当前预备编码的第一视频帧的第一图像纹理值,以及确定位于所述第一视频帧之前相邻的第二视频帧的第二图像纹理值,所述第一视频帧为所述首个视频帧之后的任意视频帧;
    第二确定单元,用于当所述第一图像纹理值大于所述第二图像纹理值时,根据所述第一图像纹理值和所述第二图像纹理值确定图像纹理比值;
    调整单元,用于根据所述图像纹理比值调整所述视频编码器的编码码率,得到目标编码码率,并按照所述目标编码码率对所述第一视频帧进行编码。
  15. 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可以在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现权利要求1至13任一项所述的视频编码方法。
  16. 一种存储介质,所述存储介质用于存储计算机程序,所述计算机程序用于执行权利要求1-12任意一项所述的方法。
  17. 一种包括计算机程序的计算机程序产品,当其在计算机上运行时,使得所述计算机执行权利要求1-12任意一项所述的方法。
PCT/CN2025/095634 2024-07-09 2025-05-19 视频编码方法、装置、设备以及可读存储介质 Pending WO2026011968A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202410913458.XA CN121309819A (zh) 2024-07-09 2024-07-09 视频编码方法、装置、设备以及可读存储介质
CN202410913458.X 2024-07-09

Publications (1)

Publication Number Publication Date
WO2026011968A1 true WO2026011968A1 (zh) 2026-01-15

Family

ID=98288608

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2025/095634 Pending WO2026011968A1 (zh) 2024-07-09 2025-05-19 视频编码方法、装置、设备以及可读存储介质

Country Status (2)

Country Link
CN (1) CN121309819A (zh)
WO (1) WO2026011968A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121842337A (zh) * 2026-03-12 2026-04-10 宁波博海深衡科技有限公司 一种基于深海探测声呐的远程数据传输方法及系统
CN122160511A (zh) * 2026-05-09 2026-06-05 国网浙江省电力有限公司宁波供电公司 计及并行多通道视频编码的动态比特率分配方法及系统

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150199996A1 (en) * 2010-07-07 2015-07-16 Adobe Systems Incorporated Method and apparatus for indexing a video stream
CN110166781A (zh) * 2018-06-22 2019-08-23 腾讯科技(深圳)有限公司 一种视频编码方法、装置和可读介质
CN111385576A (zh) * 2018-12-28 2020-07-07 北京字节跳动网络技术有限公司 视频编码方法、装置、移动终端及存储介质
US20220394283A1 (en) * 2021-06-02 2022-12-08 Black Sesame Technologies Inc. Video encoding and decoding method, apparatus and computer device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150199996A1 (en) * 2010-07-07 2015-07-16 Adobe Systems Incorporated Method and apparatus for indexing a video stream
CN110166781A (zh) * 2018-06-22 2019-08-23 腾讯科技(深圳)有限公司 一种视频编码方法、装置和可读介质
CN111385576A (zh) * 2018-12-28 2020-07-07 北京字节跳动网络技术有限公司 视频编码方法、装置、移动终端及存储介质
US20220394283A1 (en) * 2021-06-02 2022-12-08 Black Sesame Technologies Inc. Video encoding and decoding method, apparatus and computer device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121842337A (zh) * 2026-03-12 2026-04-10 宁波博海深衡科技有限公司 一种基于深海探测声呐的远程数据传输方法及系统
CN122160511A (zh) * 2026-05-09 2026-06-05 国网浙江省电力有限公司宁波供电公司 计及并行多通道视频编码的动态比特率分配方法及系统

Also Published As

Publication number Publication date
CN121309819A (zh) 2026-01-09

Similar Documents

Publication Publication Date Title
CN113766226B (zh) 图像编码方法、装置、设备及存储介质
US12125171B2 (en) Video denoising method and apparatus, and storage medium
US20220030244A1 (en) Content adaptation for streaming
CN108737825B (zh) 视频数据编码方法、装置、计算机设备和存储介质
US20180063549A1 (en) System and method for dynamically changing resolution based on content
CN109688465B (zh) 视频增强控制方法、装置以及电子设备
US11575894B2 (en) Viewport-based transcoding for immersive visual streams
WO2011014637A1 (en) System and method of compressing video content
CN110662114B (zh) 视频处理方法、装置、电子设备及存储介质
US11496738B1 (en) Optimized reduced bitrate encoding for titles and credits in video content
US20220321923A1 (en) Pixel filtering for content
US20180184089A1 (en) Target bit allocation for video coding
CN107820095B (zh) 一种长期参考图像选择方法及装置
US20240291995A1 (en) Video processing method and related apparatus
US20260046415A1 (en) Methods and systems for providing variable bitrate content
CN121309819A (zh) 视频编码方法、装置、设备以及可读存储介质
CN116634151A (zh) 视频处理方法、装置、计算机设备、存储介质及程序产品
CN117176955A (zh) 视频编码方法、视频解码方法、计算机设备及存储介质
WO2018161867A1 (zh) 码率分配方法、设备及存储介质
US20240348797A1 (en) Selective frames processing in shot-based encoding pipeline
CN117676266A (zh) 视频流的处理方法及装置、存储介质、电子设备
CN117478881B (zh) 视频信息处理方法、系统、设备和存储介质
US20250024048A1 (en) Video decoder guided region aware film grain synthesis
WO2012154157A1 (en) Apparatus and method for dynamically changing encoding scheme based on resource utilization
CN117255177A (zh) 客户端自适应的视频播放及请求方法、设备、系统及介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 25835871

Country of ref document: EP

Kind code of ref document: A1