Video compression method and device and storage medium

By performing event recognition and segmentation of video files, the compression rate is calculated based on the attributes of event video clips and ordinary video clips, and the compression and splicing are performed separately, the problem of fixed and rigid video encoding methods in the prior art is solved, and more efficient video compression and storage space saving is achieved.

CN120075452APending Publication Date: 2025-05-30ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510073723.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-16
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The existing video encoding technology is relatively fixed and rigid in compression, and cannot meet users' storage efficiency and space saving needs in actual scenarios.

Method used

By dividing the specified event video clips and ordinary video clips in the original video file, the clip properties of the event video clip are extracted, the compression rate of the event video clip is determined based on these properties, and the compression rate of the ordinary video clips is calculated based on the expected compression rate of the original video file, and the compression rate of the ordinary video clips is performed separately.

Benefits of technology

It effectively balances the amount of key information and file size in the compressed video file, improves the efficiency and quality of video compression, and saves storage space while ensuring image quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120075452A_ABST
    Figure CN120075452A_ABST
Patent Text Reader

Abstract

The invention discloses a video compression method and device and a storage medium, and the method comprises the steps: extracting the segment attribute of an event video segment, determining the compression ratio of the event video segment based on the segment attribute of the event video segment, and obtaining a first compression ratio; on the basis of the expected compression ratio of the original video file and the first compression ratio corresponding to the event video clip, the compression ratio corresponding to the common video clip is obtained through calculation, and a second compression ratio is obtained; compressing the event video clip according to a first compression ratio to obtain an event compressed clip, and compressing the common video clip according to a second compression ratio to obtain a common compressed clip; and splicing the event compression fragment and the common compression fragment to obtain a compressed video file corresponding to the original video file. According to the technical scheme, the key information amount contained in the compressed video file and the file size of the compressed video file can be effectively balanced, the video compression efficiency and quality are improved, and the storage space is saved on the premise that the image quality of the compressed video file is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of file compression, and particularly to a video compression method, device, and storage medium. Background Art

[0002] Video encoding refers to a way of converting a file in the original video format into a file in another video format through specific compression techniques. Common video encoding standards include H.264, H.265, AVS, etc. Different encoding standards have different definitions, but they all have a common goal of compressing image information to a specific resolution and bit rate.

[0003] Currently, video encoding usually selects a fixed resolution according to the target bit rate of encoding, and then adjusts it in combination with different encoding standards and encoders. Although it can compress files, the compression method is relatively fixed and rigid, and the application effect in actual scenarios cannot meet the user's needs.

[0004] Therefore, how to optimize the storage strategy of video files, improve storage efficiency, and save storage space has become a major challenge. Summary of the Invention

[0005] To solve the above technical problems, this application provides at least one video compression method, device, and storage medium.

[0006] In a first aspect of this application, a video compression method is provided. The method includes: dividing video segments containing specified events in the original video file to be compressed to obtain event video segments, and using other video segments in the original video file as ordinary video segments; extracting the segment attributes of the event video segments, and determining the compression ratio of the event video segments based on the segment attributes of the event video segments to obtain a first compression ratio; where the compression ratio refers to the ratio of the file size after compression to the file size before compression; obtaining the expected compression ratio of the original video file, and calculating the compression ratio corresponding to the ordinary video segments based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segments to obtain a second compression ratio; where the first compression ratio is greater than the second compression ratio, the first compression ratio is inversely correlated with the second compression ratio, and the expected compression ratio is positively correlated with the second compression ratio; compressing the event video segments according to the first compression ratio to obtain event compressed segments, and compressing the ordinary video segments according to the second compression ratio to obtain ordinary compressed segments; splicing the event compressed segments and the ordinary compressed segments to obtain a compressed video file corresponding to the original video file.

[0007] In one embodiment, the segment attributes of the event video segment are extracted, including: identifying the event type to which the specified event corresponding to the event video segment belongs, and / or counting the duration of the event video segment; and using the event type and / or the duration corresponding to the event video segment as the segment attributes of the event video segment.

[0008] In one embodiment, the segment attributes include the event type to which the specified event corresponding to the event video segment belongs; determining the compression ratio of the event video segment based on the segment attributes of the event video segment to obtain a first compression ratio, including: obtaining the importance level of the event type corresponding to each event video segment; calculating the first compression ratio of each event video segment respectively based on the importance level of each event type; wherein, the importance level of the event type is inversely correlated with the first compression ratio.

[0009] In one embodiment, the segment attributes include the duration of the event video segment; determining the compression ratio of the event video segment based on the segment attributes of the event video segment to obtain a first compression ratio, including: counting the duration corresponding to each event video segment in the original video file; performing a summation calculation on the duration corresponding to each event video segment to obtain the total duration of the event segments; calculating the ratio between the total duration of the event segments and the total video duration of the original video file to obtain the proportion of the event segments; calculating the first compression ratio of the event video segment based on the proportion of the event segments; wherein, the proportion of the event segments is positively correlated with the first compression ratio.

[0010] In one embodiment, the segment attributes further include the event type to which the specified event corresponding to the event video segment belongs; calculating the first compression ratio of the event video segment based on the proportion of the event segments, including: calculating the initial compression ratio of the event video segment based on the proportion of the event segments; wherein, the proportion of the event segments is positively correlated with the initial compression ratio of the event video segment; obtaining the importance level of the event type corresponding to each event video segment; adjusting the initial compression ratio of each event video segment respectively based on the importance level of each event type to obtain the first compression ratio of each event video segment; wherein, the importance level of the event type is inversely correlated with the first compression ratio.

[0011] In one embodiment, the segment attributes include the event type to which the specified event corresponding to the event video segment belongs and the duration of the event video segment; determining the compression ratio of the event video segment based on the segment attributes of the event video segment to obtain a first compression ratio, including: selecting, from a set of duration relationship functions, the duration relationship functions that respectively match the event types corresponding to each event video segment to obtain target relationship functions; wherein, the duration relationship function is used to define the numerical change relationship between the first compression ratio of the event video segment and the duration; respectively counting the durations corresponding to each event video segment; and calculating the first compression ratio of each event video segment respectively based on the target relationship function and the duration of the event video segment.

[0012] In one embodiment, determining the compression ratio of the event video segment based on the segment attributes of the event video segment to obtain a first compression ratio, including: calculating the time interval between the storage start time and the current time of the original video file to obtain the storage duration of the original video file; calculating the compression ratio of the event video segment based on the storage duration of the original video file and the segment attributes of the event video segment to obtain a first compression ratio; wherein, the storage duration of the original video file is positively correlated with the first compression ratio; and / or, calculating the compression ratio of the ordinary video segment corresponding to obtain a second compression ratio based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment, including: calculating the expected file size after compression of the original video file based on the file size and the expected compression ratio of the original video file; compressing each event video segment according to the first compression ratio corresponding to each event video segment in the original video file to obtain the actual file size of each event compressed segment; calculating the difference between the expected file size after compression of the original video file and the actual file size of each event video segment after compression to obtain the reserved file size; and calculating the second compression ratio based on the file size corresponding to each ordinary video segment and the reserved file size.

[0013] In one embodiment, calculating the compression ratio of the ordinary video segment corresponding to obtain a second compression ratio based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment, including: calculating the expected file size after compression of the original video file based on the file size corresponding to the original video file and the expected compression ratio; compressing each event video segment according to the first compression ratio corresponding to each event video segment in the original video file to obtain the actual file size of each event compressed segment; calculating the difference between the expected file size after compression of the original video file and the actual file size of each event video segment after compression to obtain the reserved file size; and calculating the second compression ratio based on the file size corresponding to each ordinary video segment and the reserved file size.

[0014] The second aspect of the present application provides a video compression device, which includes: a segment division module for dividing video segments containing specified events in the original video file to be compressed to obtain event video segments, and taking other video segments in the original video file as ordinary video segments; a first compression ratio calculation module for extracting the segment attributes of the event video segments and determining the compression ratio of the event video segments based on the segment attributes of the event video segments to obtain a first compression ratio; where the compression ratio refers to the ratio of the size of the compressed file to the size of the file before compression; a second compression ratio calculation module for obtaining the expected compression ratio of the original video file and calculating the compression ratio corresponding to the ordinary video segments based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segments to obtain a second compression ratio; where the first compression ratio is greater than the second compression ratio, the first compression ratio is inversely correlated with the second compression ratio, and the expected compression ratio is positively correlated with the second compression ratio; a video compression module for compressing the event video segments according to the first compression ratio to obtain event compressed segments, and compressing the ordinary video segments according to the second compression ratio to obtain ordinary compressed segments; a segment splicing module for splicing the event compressed segments and the ordinary compressed segments to obtain a compressed video file corresponding to the original video file.

[0015] The third aspect of the present application provides an electronic device, including a memory and a processor, and the processor is configured to execute program instructions stored in the memory to implement the above video compression method.

[0016] The fourth aspect of the present application provides a computer-readable storage medium, on which program instructions are stored, and when the program instructions are executed by a processor, the above video compression method is implemented.

[0017] In the above solution, by dividing video segments containing specified events in the original video file to be compressed to obtain event video segments, and taking other video segments in the original video file as ordinary video segments; extracting the segment attributes of the event video segments and determining the compression ratio of the event video segments based on the segment attributes of the event video segments to obtain a first compression ratio; calculating the compression ratio corresponding to the ordinary video segments based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segments to obtain a second compression ratio; compressing the event video segments according to the first compression ratio to obtain event compressed segments, and compressing the ordinary video segments according to the second compression ratio to obtain ordinary compressed segments; splicing the event compressed segments and the ordinary compressed segments to obtain a compressed video file corresponding to the original video file, it can effectively balance the key information content in the compressed video file and the file size of the compressed video file, improve the video compression efficiency and quality, and save storage space on the premise of ensuring the image quality of the compressed video file.

[0018] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and do not limit this application. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The drawings herein are incorporated into and constitute a part of this specification. These drawings illustrate embodiments consistent with this application and, together with the specification, are used to explain the technical solutions of this application.

[0020] Figure 1 is a schematic diagram of the solution implementation environment provided by an embodiment of this application;

[0021] Figure 2 is a flowchart of a video compression method shown in an exemplary embodiment of this application;

[0022] Figure 3 is a schematic diagram of dividing video segments shown in an exemplary embodiment of this application;

[0023] Figure 4 is a schematic diagram of video compression shown in an exemplary embodiment of this application;

[0024] Figure 5 is a flowchart of a video compression method shown in another exemplary embodiment of this application;

[0025] Figure 6 is a block diagram of a video compression device shown in an exemplary embodiment of this application;

[0026] Figure 7 is a schematic diagram of the structure of an electronic device shown in an exemplary embodiment of this application;

[0027] Figure 8 is a schematic diagram of the structure of a computer-readable storage medium shown in an exemplary embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0028] The solutions of the embodiments of this application will be described in detail below with reference to the drawings in the specification.

[0029] In the following description, specific details such as specific system architectures, interfaces, and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand this application.

[0030] As used in this text, the term "and / or" is merely an associative information describing associated objects, indicating that there can be three relationships. For example, A and / or B can represent three cases: A exists alone, A and B exist simultaneously, and B exists alone. Additionally, in this text, the character " / " generally indicates that the associated objects before and after are in an "or" relationship. Furthermore, "plurality" in this text means two or more than two. Additionally, the term "at least one" in this text means any one of a plurality or any combination of at least two of a plurality. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set composed of A, B, and C.

[0031] The video compression method provided by the embodiments of the present application will be described below.

[0032] Please refer to Figure 1 , which shows a schematic diagram of the solution implementation environment provided by an embodiment of the present application. The solution implementation environment may include a terminal 110 and a server 120, and the terminal 110 and the server 120 are communicatively connected to each other.

[0033] The number of terminals 110 can be one or more. The terminal 110 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.

[0034] The server 120 can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers. It can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms.

[0035] In one example, the server 120 can perform compression processing on the original video file obtained from the terminal 110 to obtain a compressed video file. Of course, the server 120 can store the compressed video file locally, return it to the terminal 110, or transmit it to other terminals.

[0036] In one example, a client of a target application is installed and run in the terminal 110. For example, the target application can be an application providing video compression functions, and the original video file stored in the terminal 110 is compressed through the target application to obtain a compressed video file. The server 120 can be the background server of the target application, used to provide background services for the client of the target application.

[0037] In the video compression method provided by the embodiments of the present application, the execution subject of each step may be the terminal 110, such as the client of the target application installed and running in the terminal 110, or the server 120, or the execution may be cooperatively performed by the interaction between the terminal 110 and the server 120, that is, a part of the steps of the method are executed by the terminal 110 and another part of the steps are executed by the server 120.

[0038] Please refer to Figure 2 , Figure 2 which is a flowchart of the video compression method shown in an exemplary embodiment of the present application. This video compression method can be applied to Figure 1 the implementation environment shown in , and is specifically executed by the server in this implementation environment. It should be understood that this method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment applicable to this method.

[0039] As Figure 2 shown, the video compression method at least includes steps S210 to S250, which are introduced in detail as follows:

[0040] Step S210: Divide the video segments containing a specified event in the original video file to be compressed to obtain event video segments, and use the other video segments in the original video file as ordinary video segments.

[0041] Perform event recognition on the original video file to determine the video segments containing the specified event in the original video file, divide the video segments containing the specified event to obtain event video segments, and then use the other video segments in the original video file as ordinary video segments.

[0042] Exemplarily, input the original video file into a pre-trained event recognition neural network model. The event recognition neural network model recognizes the video frames with the specified event in the original video file, and performs statistical segmentation on the video frames with the specified event in the original video file to obtain the video segments containing the specified event; perform statistical segmentation on the video frames without the specified event in the original video file to obtain ordinary video segments.

[0043] Exemplarily, after performing event recognition on the video frames of the original video file, perform event marking on the video frames with the specified event at the frame header of the video frames, and then store them in the database. Subsequently, in response to a compression request for the original video file, read the original video file from the database, parse the frame headers of each video frame of the original video file, determine whether there is an event mark for the video frame, perform statistical segmentation on the video frames with event marks in the original video file to obtain the video segments containing the specified event; perform statistical segmentation on the video frames without event marks in the original video file to obtain ordinary video segments.

[0044] Among them, the number of event video segments and ordinary video segments is one or more.

[0045] For example, please refer to Figure 3 , Figure 3 which is a schematic diagram of dividing video segments shown in an exemplary embodiment of the present application. As Figure 3 shown, after event recognition of the original video file, a plurality of event video segments and ordinary video segments are obtained.

[0046] It should be noted that if the source of the original video file is different, the video content is different, and the application scenario is different, the specified events to be recognized are different. For example, if the original video file is a perimeter protection video file, by performing event recognition processing on video frames in the perimeter protection video file, such as specified area intrusion events, and / or fence climbing events, and / or fence damage events, etc., the present application does not limit the specified events to be recognized.

[0047] Step S220: Extract the segment attributes of the event video segments, and determine the compression ratio of the event video segments based on the segment attributes of the event video segments to obtain the first compression ratio.

[0048] Among them, the compression ratio refers to the ratio of the difference between the file size after compression and the file size before compression to the file size before compression. The larger the compression ratio, the larger the difference between the file size after compression and the file size before compression, the greater the loss of video frame image quality, and the greater the distortion; conversely, the smaller the compression ratio, the smaller the difference between the file size after compression and the file size before compression, the smaller the loss of video frame image quality, and the smaller the distortion.

[0049] Extract the attribute information of the event video segments to obtain the segment attributes of the event video segments.

[0050] For example, the segment attributes include the event type to which the specified event corresponding to the event video segment belongs, and / or the duration of the event video segment. Then, identify the event type to which the specified event corresponding to the event video segment belongs, and / or count the duration of the event video segment to obtain the attribute information of the event video segment.

[0051] Classify the specified events corresponding to the event video segments to obtain the event types to which the specified events belong. For example, if the original video file is a perimeter protection video file, the event types of the specified events include specified area intrusion events, and / or fence climbing events, and / or fence damage events, etc.

[0052] The duration of the event video segment refers to the length of the time interval between the start time and the end time of the event video segment.

[0053] Extract the segment attributes of the event video segment to flexibly determine the compression ratio of the event video segment according to the segment attributes of the event video segment.

[0054] For example, different compression ratios corresponding to different event types are pre-stored. By querying the compression ratio corresponding to the event type of the event video segment, a first compression ratio is obtained. Or, according to the duration of the event video segment, the compression ratio corresponding to the event video segment is calculated to obtain a first compression ratio. The longer the duration of the event video segment, the larger the first compression ratio corresponding to the event video segment. This application does not limit this.

[0055] Exemplarily, according to the segment attributes of all event video segments, the compression ratio of each event video segment can be determined, that is, the compression ratio of each event video segment is the same; or the compression ratio of each event video segment can be determined separately according to the segment attributes of each event video segment, that is, the compression ratio of each event video segment is different. This application does not limit this.

[0056] Of course, other segment attributes of the event video segment can also be extracted to comprehensively determine the compression ratio of the event video segment. For example, the image clarity, comment information, etc. of the event video segment are extracted as segment attributes. This application does not limit this.

[0057] Step S230: Obtain the expected compression ratio of the original video file, and calculate the compression ratio corresponding to the ordinary video segment based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment to obtain a second compression ratio; where the first compression ratio is less than the second compression ratio, the first compression ratio is inversely related to the second compression ratio, and the expected compression ratio is positively related to the second compression ratio.

[0058] The expected compression ratio of the original video file can be a preset empirical value or a value flexibly calculated.

[0059] Illustrate with examples. According to the time interval between the storage start time and the current time of the original video file, and / or the video source of the original video file, and / or the number of playbacks of the original video file, etc., the expected compression ratio of the original video file is flexibly calculated; for example, the longer the time interval between the storage start time and the current time of the original video file, the larger the expected compression ratio; different video sources of the original video file correspond to different preset expected compression ratios; the fewer the number of playbacks of the original video file, the larger the expected compression ratio.

[0060] Calculate the compression ratio corresponding to the ordinary video segment based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment to obtain a second compression ratio.

[0061] For example, based on the anti-correlation between the first compression ratio and the second compression ratio, and the positive correlation between the expected compression ratio and the second compression ratio, a relational expression is established: expected compression ratio * original video file duration = first compression ratio * event video segment duration + second compression ratio * ordinary video segment duration. Since the first compression ratio, expected compression ratio, original video file duration, event video segment duration, and ordinary video segment duration are known, the second compression ratio can be calculated.

[0062] Of course, other methods can also be used to determine the second compression ratio, and the present application does not limit this.

[0063] It should be noted that the compression ratios of each ordinary video segment can be the same or different.

[0064] For example, according to the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment, the initial compression ratio of each ordinary video segment is calculated. Then, the event video segments adjacent to the ordinary video segment before and after are determined, and according to the segment attributes of the adjacent event video segments before and after, the importance degree of this ordinary video segment is evaluated. For example, the more important the event type of the adjacent event video segments before and after, and / or the longer the duration of the adjacent event video segments before and after, the higher the importance degree of this ordinary video segment; the initial compression ratio is adjusted according to the importance degree of the ordinary video segment to obtain the final compression ratio of this ordinary video segment, and the second compression ratio is obtained. For example, if the importance degree of the ordinary video segment is greater than the preset threshold, the initial compression ratio is adjusted downward, and if the importance degree of the ordinary video segment is not greater than the preset threshold, the initial compression ratio is adjusted upward.

[0065] Of course, other methods can also be used to calculate the second compression ratio of each ordinary video segment differently, such as combining segment attributes such as the duration of the ordinary video segment, the image clarity of the ordinary video segment, and comment information to flexibly calculate the second compression ratio of the ordinary video segment, improving the video compression efficiency and quality.

[0066] It should be noted that the first compression ratio is less than the second compression ratio to ensure the video image quality of the event video segment, so that the compressed video file contains more key information.

[0067] In addition, first determining the compression ratio of the event video segment according to the segment attributes of the event video segment, and then determining the compression ratio of the ordinary video segment according to the compression ratio of the event video segment can effectively balance the key information amount contained in the compressed video file and the file size of the compressed video file, improving the video compression efficiency and quality.

[0068] Step S240: Compress the event video segment at the first compression ratio to obtain an event compressed segment, and compress the ordinary video segment at the second compression ratio to obtain an ordinary compressed segment.

[0069] After obtaining the compression ratios of each event video segment and ordinary video segment, based on the compression ratios corresponding to each event video segment and ordinary video segment respectively, video coding parameters are generated to obtain corresponding video coding strategies, so as to perform encoding and compression processing on each event video segment and ordinary video segment according to the video coding strategies, and obtain event compressed segments and ordinary compressed segments.

[0070] Among them, the video coding parameters include but are not limited to quantization parameter (Quantization Parameter, QP), coding format, bit rate, frame rate, etc., and the present application does not limit this.

[0071] The quantization parameter reflects the spatial detail compression situation. The smaller the value of the quantization parameter, the finer the quantization, the higher the image quality, the longer the generated bitstream, and most of the details of the image will be retained; the larger the value of the quantization parameter, some image details are lost, the bit rate is reduced, but the image distortion is enhanced and the quality is decreased. Taking the quantization parameter as an example for illustration:

[0072] Taking the video frames in the event video segment as event frames, according to the first compression ratio corresponding to the event video segment, determine the initial quantization parameter corresponding to each event frame in the event video segment, where the first compression ratio is positively correlated with the initial quantization parameter; perform image region division on the event frame, and analyze the importance of the image content contained in each image region obtained by dividing the event frame; adjust the initial quantization parameter of the event frame based on the importance of the image content to obtain the quantization parameters corresponding to each image region in the event frame; compress the event frame according to the quantization parameters corresponding to each image region in the event frame, and combine all the compressed event frames to obtain an event compressed segment.

[0073] For example, among each image region, the importance of the dynamic foreground object is higher than that of the static background object. Therefore, the initial quantization parameter of the dynamic foreground object is adjusted downward to retain more image details; the initial quantization parameter of the static background object is adjusted upward to reduce the file size of the compressed video frame.

[0074] Encode and compress the event frame according to the quantization parameters corresponding to each image region in the event frame to obtain the compressed event frame, and combine all the compressed event frames to obtain an event compressed segment.

[0075] Similarly, taking the video frames in the ordinary video segment as ordinary frames, according to the second compression ratio corresponding to the ordinary video segment, determining the initial quantization parameter corresponding to each ordinary frame in the ordinary video segment, where the second compression ratio is positively correlated with the initial quantization parameter; dividing the ordinary frame into image regions, analyzing the importance degree of the image content contained in each image region obtained by dividing the ordinary frame; adjusting the initial quantization parameter of the ordinary frame based on the importance degree of the image content to obtain the quantization parameter corresponding to each image region in the ordinary frame; compressing the ordinary frame according to the quantization parameter corresponding to each image region in the ordinary frame, and combining all the compressed ordinary frames to obtain an ordinary compressed segment.

[0076] Step S250: Concatenate the event compressed segment and the ordinary compressed segment to obtain a compressed video file corresponding to the original video file.

[0077] Concatenate the event compressed segment and the ordinary compressed segment according to the sequence of each event video segment and ordinary video segment in the original video file to obtain a compressed video file corresponding to the original video file.

[0078] For example, please refer to Figure 4 , Figure 4 which is a schematic diagram of video compression shown in an exemplary embodiment of the present application. As Figure 4 shown, divide the video segment containing the specified event in the original video file to obtain an event video segment, divide the video segment in the original video file that does not contain the specified event to obtain an ordinary video segment, and then compress each event video segment and each ordinary video segment respectively according to the first compression ratio corresponding to each event video segment and the second compression ratio corresponding to each ordinary video segment to obtain an event compressed segment and an ordinary compressed segment. Then, concatenate the event compressed segment and the ordinary compressed segment according to the sequence in the original video file to obtain a compressed video file, saving storage space while ensuring the image quality of the compressed video file.

[0079] Next, some embodiments of the present application will be illustrated by examples:

[0080] In some embodiments, the segment attribute includes the event type to which the specified event corresponding to the event video segment belongs; in step S220, determining the compression ratio of the event video segment based on the segment attribute of the event video segment to obtain the first compression ratio includes:

[0081] Step S2211: Obtain the importance degree of the event type corresponding to each event video segment.

[0082] Exemplarily, the importance level corresponding to each event type can be preset in advance. After obtaining the importance level of the event type corresponding to the event video segment, the importance level matching the event type can be directly queried. For example, the importance level of the fence climbing event is higher than that of the specified area intrusion event.

[0083] Exemplarily, the importance level of the event type can be calculated flexibly.

[0084] For example, analyze the event video segment to identify the triggering object that triggers the specified event. According to the number and / or object type of the triggering object, determine the importance level of the event type. For example, the more the number of triggering objects and / or the object type of the triggering object belongs to the preset type, the higher the importance level of the event type.

[0085] Also for example, collect the video playback data within a preset time period to count the number of times the video segments corresponding to each event type are played within the preset time period. Determine the importance level of the event type according to the number of times played. Among them, the more the number of times played, the higher the importance level of the corresponding event type.

[0086] Of course, other methods can also be used to determine the importance level of the event type corresponding to the event video segment, and the present application does not limit this.

[0087] Step S2212: Based on the importance level of each event type, calculate the first compression ratio of each event video segment respectively.

[0088] Taking the inverse correlation between the importance level of the event type and the first compression ratio as the calculation basis, calculate the first compression ratio of each event video segment respectively according to the importance level of each event type.

[0089] In some embodiments, the segment attribute includes the duration of the event video segment; in step S220, determining the compression ratio of the event video segment based on the segment attribute of the event video segment to obtain the first compression ratio includes:

[0090] Step S2221: Count the duration corresponding to each event video segment in the original video file.

[0091] Calculate the duration corresponding to each event video segment respectively according to the start time and end time of each event video segment.

[0092] Step S2222: Perform a summation calculation on the duration corresponding to each event video segment to obtain the total duration of the event segments.

[0093] For example, the duration of event video clip 1 in the original video file is 1 minute, the duration of event video clip 2 is 3 minutes, and the duration of event video clip 3 is 30 seconds. Then the total duration of the event clips is 4 minutes and 30 seconds.

[0094] Step S2223: Calculate the ratio between the total duration of the event clips and the total video duration of the original video file to obtain the proportion of the event clips.

[0095] When calculating the ratio between the total duration of the event clips and the total video duration of the original video file, the larger the total duration of the event clips, the larger the proportion of the event clips; the smaller the total duration of the event clips, the smaller the proportion of the event clips.

[0096] Step S2224: Calculate the first compression ratio of the event video clip based on the proportion of the event clips.

[0097] Based on the positive correlation between the proportion of the event clips and the first compression ratio, calculate the first compression ratio of the event video clip according to the proportion of the event clips.

[0098] In some embodiments, the clip attribute includes the event type to which the specified event corresponding to the event video clip belongs and the duration of the event video clip; determining the compression ratio of the event video clip based on the clip attribute of the event video clip in step S220 to obtain the first compression ratio includes:

[0099] Step S2231: Count the duration corresponding to each event video clip in the original video file.

[0100] Step S2232: Sum up the durations corresponding to each event video clip to obtain the total duration of the event clips.

[0101] Step S2233: Calculate the ratio between the total duration of the event clips and the total video duration of the original video file to obtain the proportion of the event clips.

[0102] Step S2234: Calculate the initial compression ratio of the event video clip based on the proportion of the event clips; wherein, the proportion of the event clips is positively correlated with the initial compression ratio of the event video clip.

[0103] For the specific implementation manners of steps S2231 to S2234, please refer to the specific implementation manners of steps S2221 to S2224, which will not be elaborated here.

[0104] Step S2235: Obtain the importance degree of the event type corresponding to each event video clip.

[0105] For the specific implementation manner of step S2235, please refer to the specific implementation manner of step S2211, which will not be elaborated here.

[0106] Step S2236: Based on the importance level of each event type, adjust the initial compression ratio of each event video segment respectively to obtain the first compression ratio of each event video segment; wherein, the importance level of the event type is inversely correlated with the first compression ratio.

[0107] For example, a preset threshold is set. If the importance level of the event type is higher than the preset threshold, then lower the initial compression ratio of the event video segment to obtain the first compression ratio; if the importance level of the event type is lower than the preset threshold, then increase the initial compression ratio of the event video segment to obtain the first compression ratio.

[0108] In some embodiments, the segment attribute includes the event type to which the specified event corresponding to the event video segment belongs and the duration of the event video segment; determining the compression ratio of the event video segment based on the segment attribute of the event video segment in step S220 to obtain the first compression ratio includes:

[0109] Step S2241: Select the duration relationship functions respectively matching the event types corresponding to each event video segment from the set of duration relationship functions to obtain the target relationship function.

[0110] Wherein, the duration relationship function is used to define the numerical change relationship between the first compression ratio of the event video segment and the duration.

[0111] By analyzing the video segments of different event types, determine the correlation relationship between the duration and the importance level of the video, and then obtain the correlation relationship between the duration and the video compression ratio, and construct the corresponding duration relationship function. One duration relationship function corresponds to and is associated with one or more event types.

[0112] According to the event type corresponding to the event video segment, select the matching duration relationship function from the set of duration relationship functions to obtain the target relationship function.

[0113] Step S2242: Statistically calculate the duration corresponding to each event video segment respectively.

[0114] Step S2243: Based on the target relationship function and the duration of the event video segment, calculate and obtain the first compression ratio of each event video segment respectively.

[0115] The duration relationship function defines the numerical change relationship between the first compression ratio of the event video segment and the duration. Therefore, substitute the duration of the event video segment into the target relationship function to obtain the first compression ratio of the event video segment.

[0116] In some embodiments, in step S230, based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment, calculating the compression ratio corresponding to the normal video segment to obtain the second compression ratio includes:

[0117] Step S231: Based on the file size of the original video file and the expected compression ratio, calculate the expected file size after compressing the original video file;

[0118] The smaller the expected compression ratio of the original video file, the smaller the expected file size after compressing the original video file.

[0119] Step S232: Compress each event video segment according to the first compression ratio corresponding to each event video segment in the original video file to obtain the actual file size of each event compressed segment;

[0120] According to the first compression ratio, each event video segment is preferentially compressed to obtain the actual file size of the event compressed segment after the compression process of the event video segment.

[0121] Optionally, for the fixed bitrate encoding method, the file size after compressing the event video segment can be estimated according to the first compression ratio.

[0122] Step S233: Calculate the difference between the expected file size after compressing the original video file and the actual file size after compressing each event video segment to obtain the reserved file size.

[0123] Subtract the expected file size after compressing each event video segment from the expected file size after compressing the original video file respectively to obtain the reserved file size.

[0124] Step S234: Based on the file size of each normal video segment and the reserved file size, calculate the obtained second compression ratio.

[0125] Exemplarily, calculate the sum of the file sizes of each normal video segment to obtain the total size of the normal segment files, and calculate the ratio of the difference between the total size of the normal segment files and the reserved file size to the total size of the normal segment files to obtain the second compression ratio.

[0126] Exemplarily, it is also possible to calculate the ratio of the difference between the total size of the normal segment files and the reserved file size to the total size of the normal segment files to obtain the initial compression ratio, and then adjust the initial compression ratio according to the event video segments adjacent to the front and back of the normal video segment, the duration of the normal video segment, the image clarity of the normal video segment, the comment information, etc. to obtain the second compression ratio.

[0127] Exemplarily, the compression level of the ordinary segment file can also be selected according to the size relationship, difference size, etc. between the total size of the ordinary segment file and the reserved file size. Different compression levels correspond to different compression ratios. For example, the compression levels from low to high successively include "picture quality priority", "balanced mode", and "bit rate priority". The higher the compression level, the smaller the compression ratio.

[0128] In some embodiments, in addition to calculating the second compression ratio by the above method of calculating the reserved file size, other methods can also be used to calculate the second compression ratio, which is not limited in this application. For example, first obtain the template compression ratio corresponding to the ordinary video segment. The template compression ratio can be preset according to experience or flexibly calculated according to the storage duration of the original video file (for example, the longer the storage duration of the original video file, the larger the template compression ratio). Then, adjust the template compression ratio according to the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment to obtain the second compression ratio. For example, if the difference between one or more of the mean, maximum, or minimum of the first compression ratios of each event video segment and the expected compression ratio is greater than the preset threshold, the second compression ratio is adjusted downward; if the difference between one or more of the mean, maximum, or minimum of the first compression ratios of each event video segment and the expected compression ratio is not greater than the preset threshold, the template compression ratio is adjusted upward.

[0129] In some embodiments, calculate the time interval between the storage start time and the current time of the original video file to obtain the storage duration of the original video file; determining the compression ratio of the event video segment based on the segment attributes of the event video segment in step S220 to obtain the first compression ratio includes: calculating the compression ratio of the event video segment based on the storage duration of the original video file and the segment attributes of the event video segment to obtain the first compression ratio; wherein, the storage duration of the original video file is positively correlated with the first compression ratio; and / or, calculating the compression ratio corresponding to the ordinary video segment based on the expected compression ratio of the original video file and the first compression ratio corresponding to the event video segment in step S230 to obtain the second compression ratio includes: calculating the compression ratio of the ordinary video segment based on the storage duration of the original video file, the expected compression ratio of the original video file, and the first compression ratio corresponding to the event video segment to obtain the second compression ratio; wherein, the storage duration of the original video file is positively correlated with the compression ratio of the ordinary video segment.

[0130] For example, please refer to Figure 5 , Figure 5 which is a flowchart of the video compression method shown in another exemplary embodiment of this application. As Figure 5 shown, it includes:

[0131] Step S501: Traverse the video files in the database, and use the currently traversed video file as the original video file;

[0132] Step S502: Calculate the time interval between the storage start time of the original video file and the current time to obtain the storage duration of the original video file;

[0133] Step S503: Determine whether the storage duration of the original video file is within a preset time limit range. If so, execute Step S504; if not, execute Step S501;

[0134] Step S504: Obtain the compression level that matches the preset time limit range;

[0135] For example, assume that the storage duration of the original video file is T, and the compression levels from small to large include L0, L1, L2, and L3. Then, the compression level that matches the preset time limit range can be obtained according to Table 1 below:

[0136] Preset time limit range (days) Compression level 0<T<=90 L0 90<T<=180 L1 180<T<=270 L2 270<T L3

[0137] Table 1

[0138] Among them, Table 1 stores the mapping relationship between the preset time limit range and the compression level.

[0139] Step S505: Calculate the compression ratio of the event video segment according to the compression level that matches the preset time limit range and the segment attributes of the event video segment to obtain the first compression ratio;

[0140] Step S506: Calculate the compression ratio of the ordinary video segment according to the compression level that matches the preset time limit range, the expected compression ratio of the original video file, and the first compression ratio corresponding to the event video segment to obtain the second compression ratio;

[0141] The storage duration of the original video file is positively correlated with the first compression ratio and the second compression ratio. That is, the longer the storage duration of the original video file, the higher the compression level, and the larger the first compression ratio and the second compression ratio, and the smaller the compressed file.

[0142] Step S507: Generate a video encoding strategy for the event video segment according to the first compression ratio; generate a video encoding strategy for the ordinary video segment according to the second compression ratio;

[0143] Step S508: Compress the event video segment according to the video encoding strategy of the event video segment to obtain an event compressed segment, and compress the ordinary video segment according to the video encoding strategy of the ordinary video segment to obtain an ordinary compressed segment;

[0144] Step S509: Concatenate the event compressed segment and the normal compressed segment to obtain the compressed video file corresponding to the original video file, delete the original video file, and write the compressed video file into the database.

[0145] The video compression method provided by this application divides the video segments containing specified events in the original video file to be compressed to obtain event video segments, and regards the other video segments in the original video file as normal video segments; extracts the segment attributes of the event video segments, determines the compression rate of the event video segments based on the segment attributes of the event video segments to obtain the first compression rate; calculates the compression rate corresponding to the normal video segments based on the expected compression rate of the original video file and the first compression rate corresponding to the event video segments to obtain the second compression rate; compresses the event video segments according to the first compression rate to obtain event compressed segments, and compresses the normal video segments according to the second compression rate to obtain normal compressed segments; concatenates the event compressed segments and the normal compressed segments to obtain the compressed video file corresponding to the original video file, which can effectively balance the key information content in the compressed video file and the file size of the compressed video file, improve the video compression efficiency and quality, and save storage space on the premise of ensuring the image quality of the compressed video file.

[0146] Figure 6 It is a block diagram of a video compression device shown in an exemplary embodiment of this application. As Figure 6 shown, the exemplary video compression device 600 includes:

[0147] A segment division module 610, configured to divide the video segments containing specified events in the original video file to be compressed to obtain event video segments, and regard the other video segments in the original video file as normal video segments;

[0148] A first compression rate calculation module 620, configured to extract the segment attributes of the event video segments, determine the compression rate of the event video segments based on the segment attributes of the event video segments to obtain the first compression rate; wherein, the compression rate refers to the ratio of the difference between the file size after compression and the file size before compression to the file size before compression;

[0149] A second compression rate calculation module 630, configured to obtain the expected compression rate of the original video file, and calculate the compression rate corresponding to the normal video segments based on the expected compression rate of the original video file and the first compression rate corresponding to the event video segments to obtain the second compression rate; wherein, the first compression rate is less than the second compression rate, the first compression rate is inversely related to the second compression rate, and the expected compression rate is positively related to the second compression rate;

[0150] A video compression module 640 is configured to compress an event video segment at a first compression rate to obtain an event compressed segment, and compress a normal video segment at a second compression rate to obtain a normal compressed segment.

[0151] A segment splicing module 650 is configured to splice the event compressed segment and the normal compressed segment to obtain a compressed video file corresponding to the original video file.

[0152] It should be noted that the video compression device provided in the above embodiment and the video compression method provided in the above embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated here. In practical applications, the video compression device provided in the above embodiment may, according to needs, allocate the above functions to different functional modules, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above. This is not limited herein.

[0153] Please refer to Figure 7 , Figure 7 , which is a schematic structural diagram of an embodiment of an electronic device of the present application. The electronic device 700 includes a memory 701 and a processor 702. The processor 702 is configured to execute program instructions stored in the memory 701 to implement the steps in any of the above video compression method embodiments. In a specific implementation scenario, the electronic device 700 may include, but is not limited to: a microcomputer, a server. In addition, the electronic device 700 may also include mobile devices such as a laptop computer, a tablet computer, etc., which are not limited herein.

[0154] Specifically, the processor 702 is configured to control itself and the memory 701 to implement the steps in any of the above video compression method embodiments. The processor 702 may also be referred to as a Central Processing Unit (CPU). The processor 702 may be an integrated circuit chip with signal processing capabilities. The processor 702 may also be a general-purpose processor, a Digital Signal Processor (DSP), an Application-Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. Additionally, the processor 702 may be implemented jointly by integrated circuit chips.

[0155] Please refer to Figure 8 ,Figure 8 FIG. Figure 8 is a schematic structural diagram of an embodiment of a computer-readable storage medium of the present application. The computer-readable storage medium 800 stores program instructions 810 that can be run by a processor. The program instructions 810 are used to implement the steps in any of the above-described embodiments of the video compression method.

[0156] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the methods described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.

[0157] The above descriptions of the various embodiments tend to emphasize the differences between the various embodiments. Their similarities or similarities can be referred to each other. For the sake of brevity, they will not be repeated here.

[0158] In several embodiments provided by the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the above-described device embodiments are merely illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0159] In addition, each functional unit in the various embodiments of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in the various embodiments of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

Claims

1. A video compression method, characterized in that: The method comprises: Dividing the video segments containing the specified event in the original video file to be compressed to obtain the event video segments, and treating the other video segments in the original video file as common video segments; Extracting the segment attributes of the event video segment, determining the compression ratio of the event video segment based on the segment attributes of the event video segment, and obtaining a first compression ratio; wherein the compression ratio refers to the ratio of the difference between the size of the file after compression and the size of the file before compression to the size of the file before compression; Obtaining an expected compression rate of the original video file, and calculating a compression rate corresponding to the common video clip based on the expected compression rate of the original video file and a first compression rate corresponding to the event video clip, to obtain a second compression rate; wherein the first compression rate is less than the second compression rate, the first compression rate is inversely correlated with the second compression rate, and the expected compression rate is positively correlated with the second compression rate; compressing the event video segment according to the first compression rate to obtain an event compressed segment, and compressing the ordinary video segment according to the second compression rate to obtain an ordinary compressed segment; The event compressed segment and the common compressed segment are spliced ​​to obtain a compressed video file corresponding to the original video file.

2. The method according to claim 1, characterized in that: The extracting the segment attributes of the event video segment includes: Identify the event type to which the designated event corresponding to the event video clip belongs, and / or count the duration of the event video clip; The event type and / or duration corresponding to the event video segment is used as the segment attribute of the event video segment.

3. The method according to claim 2, characterized in that The segment attribute includes an event type to which a specified event corresponding to the event video segment belongs; and determining the compression rate of the event video segment based on the segment attribute of the event video segment to obtain a first compression rate includes: Obtaining the importance of the event type corresponding to each of the event video clips; Based on the importance of each event type, a first compression rate of each event video clip is calculated respectively; wherein the importance of the event type is inversely correlated with the first compression rate.

4. The method according to claim 2, characterized in that: The segment attributes include the duration of the event video segment; The step of determining the compression rate of the event video segment based on the segment attribute of the event video segment to obtain a first compression rate includes: Counting the duration of each event video clip in the original video file; Summing up the duration of each event video clip to obtain the total duration of the event clip; Calculate the ratio of the total duration of the event segments to the total duration of the original video file to obtain the event segment ratio; Based on the proportion of event clips, a first compression rate of the event video clips is calculated; wherein the proportion of event clips is positively correlated with the first compression rate.

5. The method according to claim 4, characterized in that The segment attribute also includes an event type to which the specified event corresponding to the event video segment belongs; and the first compression rate of the event video segment is calculated based on the event segment proportion, including: Based on the proportion of the event segments, the initial compression rate of the event video segments is calculated; wherein the proportion of the event segments is positively correlated with the initial compression rate of the event video segments; Obtaining the importance of the event type corresponding to each of the event video clips; Based on the importance of each event type, the initial compression rate of each event video clip is adjusted to obtain a first compression rate of each event video clip; wherein the importance of the event type is inversely correlated with the first compression rate.

6. The method according to claim 2, characterized in that The segment attributes include the event type to which the specified event corresponding to the event video segment belongs and the duration of the event video segment; The step of determining the compression rate of the event video segment based on the segment attribute of the event video segment to obtain a first compression rate includes: Selecting a duration relationship function that matches the event type corresponding to each event video clip from the duration relationship function set to obtain a target relationship function; wherein the duration relationship function is used to define a numerical change relationship between a first compression rate and a duration of the event video clip; Counting the duration of each video clip of the event respectively; Based on the target relationship function and the duration of the event video clip, a first compression rate of each event video clip is calculated respectively.

7. The method according to any one of claims 1 to 6, characterized in that: The step of determining the compression rate of the event video segment based on the segment attribute of the event video segment to obtain a first compression rate includes: Calculate the time interval between the storage start time of the original video file and the current time to obtain the storage duration of the original video file; Based on the storage duration of the original video file and the segment attribute of the event video segment, a compression rate of the event video segment is calculated to obtain a first compression rate; wherein the storage duration of the original video file is positively correlated with the first compression rate; And / or, the step of calculating the compression rate corresponding to the common video clip based on the expected compression rate of the original video file and the first compression rate corresponding to the event video clip to obtain the second compression rate includes: Based on the storage duration of the original video file, the expected compression rate of the original video file and the first compression rate corresponding to the event video clip, the compression rate of the ordinary video clip is calculated to obtain a second compression rate; wherein, the storage duration of the original video file and the compression rate of the ordinary video clip are positively correlated.

8. The method according to claim 1, characterized in that The step of calculating the compression rate corresponding to the common video clip based on the expected compression rate of the original video file and the first compression rate corresponding to the event video clip to obtain the second compression rate includes: Calculating the expected file size of the original video file after compression based on the file size corresponding to the original video file and the expected compression ratio; Compressing each of the event video segments according to a first compression ratio corresponding to each of the event video segments in the original video file to obtain an actual file size of each event compressed segment; Calculate the difference between the expected file size after compression of the original video file and the actual file size after compression of each event video clip to obtain a reserved file size; A second compression ratio is calculated based on the file size corresponding to each of the common video clips and the reserved file size.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the steps in the method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and the program instructions can be executed by a processor to implement the steps in the method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Method and device for optimizing program based on user video data and medium

    CN121037639A