Image compression method and device, electronic equipment and computer storage medium

Through the extraction and synthesis of dynamic images, the problem of excessive size and loss of clarity of dynamic image files is solved, and the effect of reducing file volume without affecting image quality is achieved.

CN118945375APending Publication Date: 2024-11-12BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411212374.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

The dynamic image file is large in size, and the existing compression method leads to loss of image clarity, and there is no effective solution.

Method used

By obtaining the original frame sequence and compression ratio of the dynamic image, the frame extraction process is performed, the keyframes are retained and the compressed dynamic image is synthesized to reduce the file size without affecting the image clarity.

Benefits of technology

Without changing the image size and pixels, the volume of dynamic image files is effectively reduced, solving the problem of excessive volume of dynamic image files while maintaining image clarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118945375A_ABST
    Figure CN118945375A_ABST
Patent Text Reader

Abstract

The invention discloses an image compression method and device, electronic equipment and a computer storage medium, and belongs to the technical field of image processing. The method comprises the following steps: acquiring an original frame sequence of an original dynamic image, and acquiring a compression ratio corresponding to the original dynamic image; according to the compression ratio, performing frame extraction processing on the original frame sequence to obtain remaining reserved frames in the original frame sequence after frame extraction; and synthesizing the reserved frames to generate a first compressed dynamic image. Through the method and the device, part of the image is extracted from the high-frame-rate dynamic image, the file size of the dynamic image is reduced under the condition that parameters, such as the size and the pixel of the image, influencing the image definition are not changed, and the technical problem that the file size of the current dynamic image is too large is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image compression method, device, electronic device and computer storage medium. Background Art

[0002] With the development of the Internet, the application of dynamic images in mobile applications and front-end web pages is becoming more and more widespread, bringing users a richer and more diverse visual experience.

[0003] However, the production of dynamic images often originates from video transcoding synthesis, which inevitably leads to the problem of large dynamic image file size. Although current image formats such as webp provide lossy compression and lossless compression methods to reduce file size, due to the high frame rate characteristics of dynamic images, their file size remains at a high level. In addition, excessive lossy compression will also lose image clarity, thereby damaging the user experience.

[0004] With respect to the above-mentioned problems existing in the related technologies, no effective solutions have been found so far. Summary of the invention

[0005] The present application provides an image compression method, device, electronic device and computer storage medium to solve the above-mentioned technical problems existing in the related art.

[0006] According to one embodiment of the present application, an image compression method is provided, including: obtaining an original frame sequence of an original dynamic image, and obtaining a compression ratio corresponding to the original dynamic image; performing frame extraction processing on the original frame sequence according to the compression ratio to obtain remaining retained frames in the original frame sequence after frame extraction; and synthesizing the retained frames to generate a first compressed dynamic image.

[0007] According to another embodiment of the present application, an image compression device is provided, including: an acquisition module, used to acquire an original frame sequence of an original dynamic image, and acquire a compression ratio corresponding to the original dynamic image; a frame extraction module, used to extract frames from the original frame sequence according to the compression ratio, and obtain the remaining retained frames in the original frame sequence after frame extraction; and a synthesis module, used to synthesize the retained frames to generate a first compressed dynamic image.

[0008] Optionally, the following frame extraction steps are performed starting from the first frame of the original frame sequence until the last frame of the original frame sequence is extracted, so as to obtain the remaining retained frames in the original frame sequence after frame extraction: the frame extraction module includes a first acquisition unit, used to obtain a first sequence number of the current original frame in the original frame sequence; a conversion unit, used to multiply the first sequence number by the compression ratio, and round up the obtained product to obtain a second sequence number, wherein the second sequence number is the sequence number of the current original frame as a retained frame in the retained frame sequence; a first judgment unit, used to judge whether there is a sequence number that repeats the second sequence number in the retained frame sequence; a first extraction unit, used to remove the current original frame if there is a sequence number that repeats the second sequence number in the retained frame sequence; if there is no sequence number that repeats the second sequence number in the retained frame sequence, retain the current original frame as a retained frame.

[0009] Optionally, the synthesis module includes a second acquisition unit, used to obtain the total number of original frames, the original inter-frame delay and the number of animation loops of the original dynamic image, and obtain the first total number of retained frames of the retained frames; a first calculation unit, used to calculate the retained inter-frame delay of the retained frames based on the total number of original frames, the original inter-frame delay and the first total number of retained frames; and a first synthesis unit, used to synthesize the retained frames based on the retained inter-frame delay and the number of animation loops to generate a first compressed dynamic image.

[0010] Optionally, the frame extraction module includes a second calculation unit, used to calculate the total number of pre-reserved second retained frames according to the compression ratio; a segmentation unit, used to obtain a first total time length of the original dynamic image, and divide the first total time length according to the second total number of retained frames to obtain multiple unit time lengths; a search unit, used to traverse the unit time length, and for each of the several original frames in the unit time length, search for the target original frame whose inter-frame delay accounts for the largest proportion of the unit time length, and retain the target original frame as a reserved frame.

[0011] Optionally, the synthesis module includes a third acquisition unit, used to obtain the second total duration of the original dynamic image and calculate the third total duration of the retained frames; a third calculation unit, used to calculate the difference between the second total duration and the third total duration to obtain the remaining duration; calculate the proportion of each retained frame in the third total duration; an allocation unit, used to allocate the remaining duration to each retained frame according to the proportion; and a second synthesis unit, used to synthesize the retained frames according to the duration of each retained frame to generate a first compressed dynamic image.

[0012] Optionally, the frame extraction module includes a fourth acquisition unit, used to obtain the total number of original frames of the original frame sequence; a fourth calculation unit, used to multiply the total number of original frames by the compression ratio to obtain the pre-reserved total number of third retained frames; a second judgment unit, used to calculate the ratio of the total number of original frames to the third total number of retained frames, and judge whether the ratio is an integer; and a second extraction unit, used to, if the ratio is an integer, perform frame extraction processing on the original frame sequence with the ratio as a fixed frame spacing, to obtain the remaining reserved frames in the original frame sequence after frame extraction.

[0013] Optionally, the image compression device further includes a compression module for obtaining an image quality compression ratio; based on the image quality compression ratio, performing quality compression on a single frame image in the first compressed dynamic image, and outputting a second compressed dynamic image.

[0014] According to another embodiment of the present application, a computer storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned device embodiments when running.

[0015] According to another embodiment of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: the memory is used to store computer programs; the processor is used to execute the steps in the above method by running the program stored in the memory.

[0016] According to yet another embodiment of the present application, a computer program product comprising instructions is also provided, which enables the computer to execute the steps in the above method when the computer program product is executed on the computer.

[0017] In the embodiment of the present application, an original frame sequence of an original dynamic image is obtained, and a compression ratio corresponding to the original dynamic image is obtained; according to the compression ratio, the original frame sequence is subjected to frame extraction processing to obtain the remaining retained frames in the original frame sequence after frame extraction; the retained frames are synthesized to generate a first compressed dynamic image. Through the present application, a part of the image is extracted from a dynamic image with a high frame rate, and the size of the image itself, pixels and other parameters that affect the clarity of the image are not changed, thereby reducing the file size of the dynamic image and solving the technical problem of the current large file size of the dynamic image. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present application;

[0020] Figure 2 is a flow chart of an image compression method according to an embodiment of the present application;

[0021] Figure 3 is a preprocessing flow chart of an embodiment of the present application;

[0022] Figure 4 This is the first frame extraction flow chart of the embodiment of the present application;

[0023] Figure 5 This is a first frame synthesis flow chart of an embodiment of the present application;

[0024] Figure 6 It is an overall flow chart of the scheme of the embodiment of the present application;

[0025] Figure 7 This is a second frame extraction flow chart of an embodiment of the present application;

[0026] Figure 8 This is a second frame synthesis flow chart of an embodiment of the present application;

[0027] Fig. 9 It is a structural block diagram of an image compression device according to an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] Example 1

[0031] The method embodiment provided in the first embodiment of the present application can be executed in a mobile phone, a computer, a tablet or a similar computing device. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer in an embodiment of the present application. Figure 1 As shown, the computer may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the computer may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0032] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to an image compression method in an embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0033] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0034] In this embodiment, an image compression method is provided. Figure 2 is a flowchart of an image compression method according to an embodiment of the present application. Figure 2 As shown, the process includes the following steps:

[0035] Step S10, obtaining an original frame sequence of an original dynamic image, and obtaining a compression ratio corresponding to the original dynamic image;

[0036] Step S20, performing frame extraction processing on the original frame sequence according to the compression ratio to obtain remaining reserved frames in the original frame sequence after frame extraction;

[0037] Step S30, synthesizing the retained frames to generate a first compressed dynamic image.

[0038] Dynamic image formats include gif (Graphics Interchange Format, which can be translated as graphics exchange format), webp (Web Picture Format, a picture compression format developed by Google), apng (Animated Portable Network Graphics, a bitmap animation format based on PNG (Portable Network Graphics)), avif (AV1 Image File Format, a network image format based on AV1 codec developed by AOM (Alliance for Open Media)), etc. In this embodiment, the webp format is taken as an example for explanation.

[0039] The user inputs the expected compression ratio for the original dynamic image, and the value range of the compression ratio is [0, 1]. The original frame sequence of the original dynamic image is obtained, and according to the compression ratio input by the user, a corresponding number of frames are extracted from the original frame sequence to obtain the remaining frames in the original frame sequence after the extraction, and the retained frames are synthesized into a new dynamic image as the first compressed dynamic image after the original dynamic image is compressed by extraction.

[0040] Through this embodiment, partial images are extracted from high-frame-rate dynamic images without changing the size of the image itself, pixels and other parameters that affect the image clarity, thereby reducing the file size of the dynamic image and solving the current technical problem of excessively large dynamic image file size.

[0041] In one implementation of this embodiment, the original frame sequence is subjected to frame extraction processing according to the compression ratio, and the remaining retained frames in the original frame sequence after frame extraction include:

[0042] A21, starting from the first frame of the original frame sequence, performing the following frame extraction steps until the last frame of the original frame sequence is finished extracting the frame, to obtain the remaining reserved frames in the original frame sequence after the frame extraction:

[0043] A22, obtaining the first sequence number of the current original frame in the original frame sequence;

[0044] A23, multiplying the first sequence number by the compression ratio, and rounding up the obtained product to obtain a second sequence number, wherein the second sequence number is a sequence number of the current original frame as a retained frame in the retained frame sequence;

[0045] A24, determining whether there is a sequence number in the reserved frame sequence that is repeated with the second sequence number;

[0046] A25, if there is a sequence number in the reserved frame sequence that repeats the second sequence number, remove the current original frame; if there is no sequence number in the reserved frame sequence that repeats the second sequence number, retain the current original frame as a reserved frame.

[0047] Starting from the first frame of the original frame sequence, the webpmux tool can be used to extract the original frame data, obtain the position of the current original frame in the original frame sequence, that is, the first sequence number (sequence number subscript 1), multiply the first sequence number by the compression ratio, and round up the obtained product to obtain the second sequence number of the current original frame as the reserved frame in the reserved frame sequence. For example, if the compression ratio is 0.7, the subscript of the first frame of the original frame sequence is multiplied by the compression ratio: 1*0.7=0.7, rounded up to 1, and the second sequence number is 1, and the first frame of the original frame sequence is used as the first frame of the reserved frame sequence. Among them, the reserved frame sequence is a frame sequence converted from each original frame sequence number to a reserved frame sequence number and retained.

[0048] Determine whether there is a reserved frame number that repeats the second sequence number in the reserved frame. When the reserved frame subscript is repeated, skip the current original frame. When the current original frame is the first frame, no original frame has been reserved in the reserved frame sequence, so there will be no situation where the reserved frame number is repeated with the first frame, so the original first frame is directly reserved as the first frame in the reserved frame sequence. When the current original frame is not the first frame, obtain the third sequence number of the previous reserved frame to determine whether the second sequence number and the third sequence number of the current original frame are repeated; if the second sequence number and the third sequence number are repeated, remove the current original frame; if the second sequence number and the third sequence number are different, retain the current original frame as the reserved frame. For example, the second sequence number 3*0.7=2.1 calculated for the third frame of the original frame sequence is rounded up to 3, and the second sequence number 4*0.7=2.8 calculated for the fourth frame of the original frame sequence is also rounded up to 3. At this time, the fourth frame of the original frame sequence is discarded, and the third frame of the original frame sequence is retained as the third frame of the reserved frame sequence.

[0049] For specific frame extraction algorithm, please refer to Figure 4 , input the webp original dynamic image and the compression ratio r, starting from the first frame of the original dynamic image (sequence number subscript 1), recorded as index = 1, the webpmux tool can be used to extract and retain the current original frame index, obtain the position of the current original frame in the original frame sequence, that is, the first sequence number (for example, index = 1), multiply the first sequence number by the compression ratio, and round up the product to obtain the second sequence number index_a of the current original frame as the retained frame in the retained frame sequence. Sequentially traverse the original dynamic image frame data, that is, extract the next original frame index = index + 1 of the current original frame index, calculate the retained frame sequence number index_b corresponding to the next original frame, and determine whether index_b is consistent with the current retained frame sequence number index_a. If the sequence numbers are consistent, it means that the retained frame sequence number has been occupied by the previous original frame, then skip the "next original frame", and continue to traverse the next new original frame in sequence; if the sequence numbers are inconsistent, retain the "next original frame". When the frame extraction exceeds the original frame data range, that is, the frame extraction fails when traversing to the last frame, and all the required frames have been retained, the frame extraction is terminated.

[0050] This implementation converts the original frame number and the retained frame number through a compression ratio, so that the discrete process of frame extraction is converted into a continuous process, and frames are extracted evenly within a certain interval range to achieve smooth frame output and ensure the animation effect after frame extraction and compression.

[0051] In another mode of this embodiment, synthesizing the retained frames to generate a first compressed dynamic image includes:

[0052] A31, obtaining the total number of original frames, the delay between original frames and the number of animation cycles of the original dynamic image, and obtaining the first total number of retained frames of the retained frames;

[0053] A32, calculating a reserved inter-frame delay of the reserved frames according to the total number of original frames, the original inter-frame delay and the total number of the first reserved frames;

[0054] A33, synthesizing the reserved frames according to the reserved inter-frame delay and the number of animation loops to generate a first compressed dynamic image.

[0055] Since the number of retained frames is reduced compared to the original frames, if the original inter-frame delay is maintained unchanged, the total duration of the dynamic image will be shortened directly. This phenomenon is visually manifested as a faster animation playback speed. For example, the animation effect originally designed for slow walking may be transformed into fast running, thus changing the original animation's intention and performance style. Therefore, in this embodiment, in order to ensure that the animation can still be displayed smoothly at the original speed after reducing the number of frames, the inter-frame delay is adjusted accordingly.

[0056] Reference Figure 5 , in advance during the image preprocessing stage, the webpinfo tool can be used to obtain the total number of original frames s, the original inter-frame delay d, and the number of animation cycles of the original dynamic image, and these data can be temporarily stored through global variables. The first total number of retained frames s_new is obtained, and the retained inter-frame delay d_new of the retained frames is calculated by the following formula = d*s / s_new, so as to keep the total duration unchanged. Finally, according to the inter-frame delay of the retained frames and the number of animation cycles, the webpmux tool can be used to generate a new webp dynamic image, that is, the first compressed dynamic image.

[0057] Optionally, after the frame extraction and compression of the dynamic image, image quality compression may be performed, such as adjusting the image size, pixels, cropping the image, etc. The cwebp tool may be used for quality compression: obtaining an image quality compression ratio; based on the image quality compression ratio, performing quality compression on a single frame image in the first compressed dynamic image, and outputting a second compressed dynamic image.

[0058] The synthesis method in this embodiment is suitable for scenarios where the inter-frame delay of the original dynamic image is fixed. By increasing the display time between each frame (i.e., the inter-frame delay) to compensate for the total duration shortened due to the reduction in the number of frames, it can be ensured that the overall playback speed of the animation remains unchanged while the number of frames is reduced, thereby maintaining the original performance effect and rhythm of the animation.

[0059] In another implementation of this embodiment, the original frame sequence is subjected to frame extraction processing according to the compression ratio, and the remaining retained frames in the original frame sequence after frame extraction include:

[0060] B21, calculating the total number of pre-reserved second reserved frames according to the compression ratio;

[0061] B22, obtaining a first total duration of the original dynamic image, and dividing the first total duration according to the second total number of retained frames to obtain a plurality of unit durations;

[0062] B23, traverse the unit time length, and for each of the several original frames in the unit time length, find the target original frame whose inter-frame delay accounts for the largest proportion of the unit time length, and retain the target original frame as the second retained frame.

[0063] According to the compression ratio, the number of remaining frames after the extraction is calculated, that is, the total number of the second reserved frames to be reserved. For example, the total number of frames of the original dynamic image is 60, the first total duration t_total is 600ms, and the compression ratio is 0.5, then the total number of the second reserved frames to be reserved s_remain is calculated to be 60*0.5=30 frames. In this embodiment, considering the inconsistent delay between frames of the original dynamic image, the first total duration is divided according to the remaining frames to obtain multiple unit durations (i.e., time windows) t_window of t_total / s_remain; that is, 600ms is divided into 30 parts of 20ms (600ms / 30=20ms), and the window is traversed according to 20ms to find the frame that occupies the largest proportion in the 20ms window as the reserved frame. For example, the delay between frames of the first three frames of the original dynamic image are 5ms, 10ms, and 30ms respectively. Then, when taking the first reserved frame, the three frames occupy 5ms, 10ms, and 5ms of the first 20ms window respectively, so the original second frame is selected as the first reserved frame. In the second 20ms window, the third frame occupies the entire 20ms, so the original third frame is kept as the second frame. And so on, the sequence number is kept after the 600ms traversal record is completed.

[0064] In view of the different delays between original frames, this embodiment effectively realizes intelligent frame extraction processing of the original frame sequence by dividing the total duration of the original dynamic image into multiple unit durations, and then selecting the frame with the largest proportion of inter-frame delay in each unit duration as the retained frame. This not only reduces the number of frames, but also makes the extracted frames more evenly distributed in the entire frame sequence, keeping the final animation effect smoother.

[0065] In another implementation of this embodiment, synthesizing the retained frames to generate a first compressed dynamic image includes:

[0066] B31, obtaining a second total duration of the original dynamic image, and calculating a third total duration of the retained frame;

[0067] B32, calculating the difference between the second total duration and the third total duration to obtain a remaining duration;

[0068] B33, calculating the ratio of each retained frame to the third total duration;

[0069] B34, allocating the remaining duration to each reserved frame according to the ratio;

[0070] B35, synthesizing the retained frames according to the duration of each retained frame to generate a first compressed dynamic image.

[0071] In this embodiment, considering the inconsistent inter-frame delay of the original dynamic image, the following synthesis method is adopted: obtain the second total duration t_total of the original dynamic image; calculate the third total duration of the retained frames, including: traversing the reserved frame sequence number array, obtaining the frame delay t of each retained frame, and accumulating and calculating the total duration t_remain of the retained frames; traversing the array, obtaining the frame delay t, and calculating the proportion of the retained frames in the total duration r_t=t / t_remain; calculating the difference between the second total duration t_total and the third total duration t_remain, and obtaining the remaining duration t_gap=t_total-t_remain; according to the duration ratio, the remaining duration is distributed to each retained frame: calculate the final duration t_add=t_gap*r_t+t for each retained frame, and finally synthesize a new webp dynamic image, i.e., the first compressed dynamic image, based on the inter-frame delay of the retained frames and the number of animation loops.

[0072] In another implementation of this embodiment, the original frame sequence is subjected to frame extraction processing according to the compression ratio, and the remaining retained frames in the original frame sequence after frame extraction include:

[0073] C21, obtaining the total number of original frames of the original frame sequence;

[0074] C22, multiplying the total number of original frames by the compression ratio to obtain a total number of pre-reserved third reserved frames;

[0075] C23, calculating a ratio of the total number of original frames to the total number of third retained frames, and determining whether the ratio is an integer;

[0076] C24: If the ratio is an integer, the original frame sequence is subjected to frame extraction processing with the ratio as a fixed frame spacing to obtain the remaining reserved frames in the original frame sequence after frame extraction.

[0077] In an example of this embodiment, if the total number of original frames is 60 frames, the total number of original frames is multiplied by the compression ratio (such as 0.5) to obtain the third total number of reserved frames 60*0.5=30 frames; then, the ratio of the total number of original frames to the third total number of reserved frames is calculated as 60*30=2. If the ratio of the total number of original frames to the total number of reserved frames is an integer, it means that the original frame sequence can be evenly divided into several equal parts, each containing the same number of frames, and the first frame in each part (or a frame selected according to a specific rule) is reserved. In this way, the frame spacing between the reserved frames can be equal.

[0078] For example, if a dynamic image has a total of 60 frames and is expected to be compressed 0.5 times, the total number of frames after compression is 60*0.5=30 frames. This involves which 30 frames of the 60 frames should be retained. From the perspective of maintaining the smoothness of the animation effect, the more even the better, that is, the frame spacing between the retained frames is equal, 60 / 30=2, so the 30 frames 1, 3, 5...59 can be retained. For another example, if it is expected to compress 60 frames 0.1 times, the total number of frames after compression is 60*0.1=6 frames, 60 / 6=10, so the 6 frames 1, 11, 21...51 can be retained. In this way, the intervals between the retained frames are equal, maintaining the smoothness of the animation effect.

[0079] The overall flow chart of the solution of this embodiment is as follows Figure 6 , mainly includes three parts. The first part is the preprocessing of dynamic images. This part can uniformly transcode dynamic images in non-webp format into webp format, and obtain image metadata such as frame rate, inter-frame delay, and number of loops of dynamic images.

[0080] In the first part of the preprocessing stage, refer to Figure 3 , mainly records the metadata of dynamic images for subsequent calculations, and converts the image format to facilitate subsequent unified frame extraction and synthesis. Considering that webp is widely supported and has a higher degree of compression among the current mainstream formats of dynamic images, the gif2webp tool is chosen to transcode non-webp format gif images into webp. After the transcoding is completed, the total number of frames, single frame delay, and number of loops of the dynamic image are obtained through the webpinfo tool, and the data is temporarily stored in global variables.

[0081] The second part decodes the dynamic image and completes frame extraction, traverses all the frames of the dynamic image, retains the corresponding frames in a temporary folder according to the frame rate compression ratio, and records the total number of frames left.

[0082] The third part adjusts the single-frame delay according to the ratio between the total number of frames and the number of retained frames, then synthesizes the dynamic image and compresses the dynamic image according to the set quality compression ratio.

[0083] In order to solve the problem of large file size caused by high frame rate of dynamic images, this embodiment proposes a tool for compressing dynamic images based on frame extraction. According to the compression ratio set by the user, by reducing the frame rate of the dynamic image, the file size of the dynamic image is greatly reduced without affecting the image clarity. At the same time, the tool still supports the quality compression capability provided by the dynamic image itself, and the lossless compression or lossy compression of the image itself can be used in conjunction with the frame extraction tool of this embodiment.

[0084] The dynamic image is compressed in the form of frame extraction. Since dynamic images are basically produced by video transcoding, they contain too many frames. Extracting some frames can compress the size while maintaining the visual effect of the image. This is very helpful for reducing the size of mobile app packages and reducing the image network request traffic overhead. Using the frame extraction algorithm in this embodiment, the discrete process of frame extraction is converted into a continuous compression ratio, which can make it easier for users to control the degree of image compression and the quality of the compressed image.

[0085] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0086] Example 2

[0087] In this embodiment, an image compression device is also provided to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0088] Fig. 9 is a structural block diagram of an image compression device according to an embodiment of the present application, such as Fig. 9 As shown, the device comprises:

[0089] An acquisition module 90 is used to acquire an original frame sequence of an original dynamic image and to acquire a compression ratio corresponding to the original dynamic image;

[0090] A frame extraction module 92, configured to perform frame extraction processing on the original frame sequence according to the compression ratio to obtain remaining reserved frames in the original frame sequence after frame extraction;

[0091] The synthesis module 94 is used to synthesize the retained frames to generate a first compressed dynamic image.

[0092] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0093] Example 3

[0094] An embodiment of the present application further provides a computer storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0095] Optionally, in this embodiment, the computer storage medium may be configured to store a computer program for performing the following steps:

[0096] S1, obtaining an original frame sequence of an original dynamic image, and obtaining a compression ratio corresponding to the original dynamic image;

[0097] S2, performing frame extraction processing on the original frame sequence according to the compression ratio to obtain remaining reserved frames in the original frame sequence after frame extraction;

[0098] S3, synthesizing the retained frames to generate a first compressed dynamic image.

[0099] Optionally, in this embodiment, the above-mentioned computer storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0100] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0101] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0102] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0103] S1, obtaining an original frame sequence of an original dynamic image, and obtaining a compression ratio corresponding to the original dynamic image;

[0104] S2, performing frame extraction processing on the original frame sequence according to the compression ratio to obtain remaining reserved frames in the original frame sequence after frame extraction;

[0105] S3, synthesizing the retained frames to generate a first compressed dynamic image.

[0106] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0107] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0108] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0109] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0110] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0111] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0112] 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 this understanding, the technical solution of the present application is essentially 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, and the computer software product is stored in a computer storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned computer storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.

[0113] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. An image compression method, characterized in that: The method comprises: Obtaining an original frame sequence of an original dynamic image, and obtaining a compression ratio corresponding to the original dynamic image; According to the compression ratio, the original frame sequence is subjected to frame extraction processing to obtain the remaining reserved frames in the original frame sequence after frame extraction; The retained frames are synthesized to generate a first compressed dynamic image.

2. The method according to claim 1, characterized in that: According to the compression ratio, the original frame sequence is subjected to frame extraction processing, and the remaining retained frames in the original frame sequence after frame extraction include: The following frame extraction steps are performed starting from the first frame of the original frame sequence until the last frame of the original frame sequence is finished extracting the frames, thereby obtaining the remaining reserved frames in the original frame sequence after the frame extraction: Obtaining the first sequence number of the current original frame in the original frame sequence; Multiplying the first sequence number by the compression ratio, and rounding up the obtained product to obtain a second sequence number, wherein the second sequence number is the sequence number of the current original frame as a reserved frame in the reserved frame sequence; Determine whether there is a sequence number in the reserved frame sequence that repeats the second sequence number; If there is a sequence number that repeats the second sequence number in the reserved frame sequence, the current original frame is removed; if there is no sequence number that repeats the second sequence number in the reserved frame sequence, the current original frame is retained as a reserved frame.

3. The method according to claim 1, characterized in that Synthesizing the retained frames to generate a first compressed dynamic image includes: Obtaining the total number of original frames, the delay between original frames and the number of animation cycles of the original dynamic image, and obtaining the first total number of retained frames of the retained frames; Calculating a reserved inter-frame delay of the reserved frames according to the total number of original frames, the original inter-frame delay and the first total number of reserved frames; The reserved frames are synthesized according to the reserved inter-frame delay and the animation cycle number to generate a first compressed dynamic image.

4. The method according to claim 1, characterized in that: According to the compression ratio, the original frame sequence is subjected to frame extraction processing, and the remaining retained frames in the original frame sequence after frame extraction include: Calculating the total number of pre-reserved second reserved frames according to the compression ratio; Acquire a first total duration of the original dynamic image, and divide the first total duration according to the second total number of retained frames to obtain a plurality of unit durations; The unit time length is traversed, and for each of the plurality of original frames in the unit time length, a target original frame whose inter-frame delay accounts for the largest proportion of the unit time length is searched, and the target original frame is retained as a retained frame.

5. The method according to claim 1, characterized in that Synthesizing the retained frames to generate a first compressed dynamic image includes: Acquire a second total duration of the original dynamic image, and calculate a third total duration of the retained frames; Calculate the difference between the second total duration and the third total duration to obtain a remaining duration; Calculate the ratio of each retained frame to the third total duration; Allocating the remaining duration to each reserved frame according to the ratio; The retained frames are synthesized according to the duration of each retained frame to generate a first compressed dynamic image.

6. The method according to claim 1, characterized in that According to the compression ratio, the original frame sequence is subjected to frame extraction processing, and the remaining retained frames in the original frame sequence after frame extraction include: Obtaining the total number of original frames of the original frame sequence; Multiplying the total number of original frames by the compression ratio to obtain a total number of pre-reserved third reserved frames; Calculating a ratio of the total number of original frames to the total number of third retained frames, and determining whether the ratio is an integer; If the ratio is an integer, the original frame sequence is subjected to frame extraction processing with the ratio as a fixed frame spacing to obtain the remaining reserved frames in the original frame sequence after frame extraction.

7. The method according to claim 1, characterized in that After synthesizing the retained frames to generate the first compressed dynamic image, the method further includes: Get the image quality compression ratio; Based on the image quality compression ratio, quality compression is performed on a single frame image in the first compressed dynamic image to output a second compressed dynamic image.

8. An image compression device, characterized in that: include: An acquisition module, used to acquire an original frame sequence of an original dynamic image, and to acquire a compression ratio corresponding to the original dynamic image; A frame extraction module, used for performing frame extraction processing on the original frame sequence according to the compression ratio to obtain the remaining reserved frames in the original frame sequence after frame extraction; The synthesis module is used to synthesize the retained frames to generate a first compressed dynamic image.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; wherein: Memory, used to store computer programs; A processor, configured to execute the image compression method according to any one of claims 1 to 7 by running a program stored in a memory.

10. A computer storage medium, characterized in that: The computer storage medium includes a stored program, wherein the program executes the image compression method according to any one of claims 1 to 7 when executed.