File compression method, electronic device and program product
By performing preliminary compression based on the initial compression quality during the file compression process and adjusting the compression quality using a binary search algorithm, the problem of difficulty in compressing to the preset upper limit of capacity in the prior art while ensuring file quality is solved, and effective control of file capacity in specific application scenarios is achieved.
Patent Information
- Application Number
- CN202411911104.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-11
AI Technical Summary
When performing file compression, it is difficult to compress files to a preset capacity upper limit while ensuring file quality, and the compression ratio is too high, which may lead to blurred images and unrecognizable images.
By obtaining the pending file and the preset capacity upper limit, initial compression is performed based on the initial compression quality, and then adjusting the compression quality based on the capacity of the initial compressed file and the preset capacity upper limit, the binary search algorithm is used to find the adjusted compression quality in the initial adjustment interval of the compression quality, and gradually adjust the compression quality to achieve the target capacity.
On the premise of ensuring the compression quality as much as possible, compress the to-processed files to the preset capacity upper limit to meet the limitations of file capacity in specific application scenarios, and avoid the problem of image blur.
Smart Images

Figure CN119807149A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data compression, and in particular to a file compression method, electronic device and program product. Background Art
[0002] In application scenarios involving data transmission, data storage, data analysis and processing, it is usually necessary to compress data files to reduce the amount of data to reduce storage space and improve the efficiency of transmission, storage and processing. For example, in the course of business processing, image files need to be uploaded to the data receiving platform in a specified encoding format, and the data receiving platform has restrictions on the capacity of uploaded content, and the encoded size cannot exceed the preset capacity limit. However, when performing compression processing, if the compression ratio is small, the compressed file may still exceed the preset capacity limit, or the compression ratio may be too high, resulting in blurred images that cannot be recognized, which makes it difficult to meet the needs of limiting file capacity and ensuring file quality in specific application scenarios. Summary of the invention
[0003] In view of the above problems in the prior art, embodiments of the present disclosure provide a file compression method, an electronic device, and a program product.
[0004] A first aspect of an embodiment of the present disclosure provides a file compression method, including:
[0005] Obtain the file to be processed and the preset upper capacity limit, where the preset upper capacity limit is the file capacity that is specified to be reached after the file to be processed is processed;
[0006] Performing preliminary compression on the file to be processed based on a preset initial compression quality to obtain a preliminary compressed file;
[0007] The compression quality is adjusted according to the capacity of the preliminary compressed file and a preset capacity upper limit, and the preliminary compressed file is compressed based on the adjusted compression quality to obtain a target compressed file corresponding to the file to be processed.
[0008] As a possible implementation of the first aspect, adjusting the compression quality according to the capacity of the preliminary compressed file and a preset capacity upper limit includes:
[0009] Setting an initial adjustment interval of compression quality based on initial compression quality;
[0010] Setting a target capacity corresponding to the to-be-processed file based on a preset capacity upper limit, the target capacity being the capacity of the target compressed file obtained after processing the to-be-processed file;
[0011] Based on the target capacity, the adjusted compression quality is searched in the initial adjustment interval using at least one iteration of a binary search algorithm.
[0012] As a possible implementation manner of the first aspect, setting an initial adjustment interval of compression quality based on the initial compression quality includes:
[0013] The initial compression quality is set as the upper limit value of the initial adjustment interval, and the product of the upper limit value and a preset first ratio is set as the lower limit value of the initial adjustment interval; wherein the preset first ratio is less than 1 and greater than zero.
[0014] As a possible implementation of the first aspect, setting a target capacity corresponding to the to-be-processed file based on a preset capacity upper limit includes:
[0015] The product of the preset capacity upper limit and the preset second ratio is set as the capacity difference; wherein the preset second ratio is less than 1 and greater than zero;
[0016] The difference between the preset capacity upper limit and the capacity difference is set as the target capacity.
[0017] As a possible implementation of the first aspect, an iteration process of the binary search algorithm includes:
[0018] The compression quality corresponding to the middle value of the current adjustment interval corresponding to this iteration process is used as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality;
[0019] If the absolute value of the first difference between the file capacity after the current compression process and the target capacity is less than or equal to the preset first difference threshold, the iterative process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality; or, if the absolute value of the first difference between the file capacity after the current compression process and the target capacity is greater than the preset first difference threshold, the upper limit or lower limit of the current adjustment interval is re-determined based on the binary search algorithm;
[0020] If the number of iterations of this iteration exceeds a preset number threshold, or the time for processing the file to be processed exceeds a preset time threshold, the file to be processed is determined to be in an abnormal state, and the current processing of the file to be processed is stopped.
[0021] As a possible implementation of the first aspect, the method further includes:
[0022] If the second difference between the current compression quality and the lower limit value of the initial adjustment interval is less than or equal to the preset second difference threshold, the initial adjustment interval is readjusted, and based on the adjusted initial adjustment interval, at least one iteration process of the binary search algorithm is performed to search for the adjusted compression quality in the initial adjustment interval.
[0023] As a possible implementation of the first aspect, the method further includes:
[0024] Multiple thread resources are allocated correspondingly to multiple files to be processed, and the multiple thread resources are used to compress the multiple files to be processed in parallel.
[0025] As a possible implementation manner of the first aspect, after obtaining the target compressed file corresponding to the file to be processed, the method further includes:
[0026] Store the target compressed file in the cache;
[0027] After obtaining the file to be processed, searching the cache for the target compressed file corresponding to the file to be processed;
[0028] If the target compressed file exists in the cache, the steps of preliminary compression and compressing the preliminary compressed file are not performed, and the target compressed file is obtained from the cache; or, if the target compressed file does not exist in the cache, the steps of preliminary compression and compressing the preliminary compressed file are performed to process the file to be processed.
[0029] A second aspect of the present disclosure provides a file compression device, including:
[0030] An acquisition unit, used to acquire a file to be processed and a preset upper capacity limit, where the preset upper capacity limit is a file capacity that is specified to be reached after the file to be processed is processed;
[0031] A first processing unit, configured to perform preliminary compression on the file to be processed based on a preset initial compression quality to obtain a preliminary compressed file;
[0032] The second processing unit is used to adjust the compression quality according to the capacity of the preliminary compressed file and a preset capacity upper limit, and compress the preliminary compressed file based on the adjusted compression quality to obtain a target compressed file corresponding to the file to be processed.
[0033] As a possible implementation manner of the second aspect, the second processing unit includes:
[0034] A first setting subunit, configured to set an initial adjustment interval of compression quality based on the initial compression quality;
[0035] A second setting subunit is used to set a target capacity corresponding to the to-be-processed file based on a preset upper capacity limit, where the target capacity is the capacity of the target compressed file obtained after processing the to-be-processed file;
[0036] The search subunit is used to search for the adjusted compression quality in the initial adjustment interval based on the target capacity by using at least one iteration process of the binary search algorithm.
[0037] As a possible implementation manner of the second aspect, the first setting subunit is used to:
[0038] The initial compression quality is set as the upper limit value of the initial adjustment interval, and the product of the upper limit value and a preset first ratio is set as the lower limit value of the initial adjustment interval; wherein the preset first ratio is less than 1 and greater than zero.
[0039] As a possible implementation manner of the second aspect, the second setting subunit is used to:
[0040] The product of the preset capacity upper limit and the preset second ratio is set as the capacity difference; wherein the preset second ratio is less than 1 and greater than zero;
[0041] The difference between the preset capacity upper limit and the capacity difference is set as the target capacity.
[0042] As a possible implementation manner of the second aspect, an iterative process of a binary search algorithm in the search subunit is used to:
[0043] The compression quality corresponding to the middle value of the current adjustment interval corresponding to this iteration process is used as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality;
[0044] If the absolute value of the first difference between the file capacity after the current compression process and the target capacity is less than or equal to the preset first difference threshold, the iterative process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality; or, if the absolute value of the first difference between the file capacity after the current compression process and the target capacity is greater than the preset first difference threshold, the upper limit or lower limit of the current adjustment interval is re-determined based on the binary search algorithm;
[0045] If the number of iterations of this iteration exceeds a preset number threshold, or the time for processing the file to be processed exceeds a preset time threshold, the file to be processed is determined to be in an abnormal state, and the current processing of the file to be processed is stopped.
[0046] As a possible implementation manner of the second aspect, the apparatus further includes a third processing unit, configured to:
[0047] If the second difference between the current compression quality and the lower limit value of the initial adjustment interval is less than or equal to the preset second difference threshold, the initial adjustment interval is readjusted, and based on the adjusted initial adjustment interval, at least one iteration process of the binary search algorithm is performed to search for the adjusted compression quality in the initial adjustment interval.
[0048] As a possible implementation manner of the second aspect, the apparatus further includes a parallel processing unit, configured to:
[0049] Multiple thread resources are allocated correspondingly to multiple files to be processed, and the multiple thread resources are used to compress the multiple files to be processed in parallel.
[0050] As a possible implementation of the second aspect, the apparatus further includes a storage unit, which is used to: after obtaining the target compressed file corresponding to the file to be processed, store the target compressed file in a cache;
[0051] The above device also includes a searching unit, which is used for:
[0052] After obtaining the file to be processed, searching the cache for the target compressed file corresponding to the file to be processed;
[0053] If the target compressed file exists in the cache, the steps of preliminary compression and compressing the preliminary compressed file are not performed, and the target compressed file is obtained from the cache; or, if the target compressed file does not exist in the cache, the steps of preliminary compression and compressing the preliminary compressed file are performed to process the file to be processed.
[0054] A third aspect of the present disclosure provides an electronic device, including:
[0055] a memory for storing a computer program product;
[0056] The processor is used to execute a computer program product stored in the memory, and when the computer program product is executed, the method of any one of the above-mentioned first aspects is implemented.
[0057] A fourth aspect of an embodiment of the present disclosure provides a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the method of any one of the above-mentioned first aspects is implemented.
[0058] A fifth aspect of the present disclosure provides a computer program product, including computer program instructions, which, when executed by a processor, implement any of the methods described in the first aspect.
[0059] Based on the embodiments of the present disclosure, the file to be processed is first preliminarily compressed based on a preset higher initial compression quality, and then the preliminarily compressed file is compressed based on the adjusted compression quality. By gradually adjusting the compression quality through the above steps, the file to be processed can be compressed to a preset capacity limit while ensuring the compression quality as much as possible, which can meet the needs of limiting file capacity and ensuring file quality in specific application scenarios.
[0060] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0062] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0063] Figure 1 A flowchart of an embodiment of the file compression method disclosed herein;
[0064] Figure 2 A flowchart of an embodiment of the file compression method disclosed herein;
[0065] Figure 3 It is a structural schematic diagram of an embodiment of the file compression device disclosed in the present invention;
[0066] Figure 4 It is a structural schematic diagram of an embodiment of the file compression device disclosed in the present invention;
[0067] Figure 5 It is a structural schematic diagram of an embodiment of the file compression device disclosed in the present invention;
[0068] Figure 6 It is a structural schematic diagram of an embodiment of the file compression device disclosed in the present invention;
[0069] Figure 7 A block diagram of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0070] Figure 1 FIG. 1 is a flow chart of an embodiment of the file compression method disclosed in the present invention. Figure 1 As shown, the method may specifically include:
[0071] Step S110, obtaining the to-be-processed file and the preset upper capacity limit, where the preset upper capacity limit is the file capacity that is specified to be reached after the to-be-processed file is processed.
[0072] Among them, the files to be processed may include image files, audio files, video files and other files that need to be compressed. In one example, in the bank's public commission collection project, during the business processing, the user is required to upload various ID photos in the format of Base64 (based on 64 printable characters to represent binary data) encoded strings to the bank's data receiving platform. The bank has a capacity limit for uploaded image files, and the encoded capacity cannot exceed 800K. Normally, the capacity of image files storing ID photos exceeds 800K, so before uploading the image file, the image file needs to be compressed.
[0073] The file compression tool, which is the execution subject of the file compression method disclosed in the present invention, first obtains the file to be processed and its corresponding preset capacity limit. Specifically, the file compression tool can obtain the file to be processed from the storage address specified by the user; and obtain the preset capacity limit indicated by the user through a dialog box or the like. The preset capacity limit is also the file capacity limit required for business processing. In the above example, the file to be processed is an image file storing an ID photo that the user wants to upload, and the preset capacity limit corresponding to the file to be processed is 800K.
[0074] Step S120, performing preliminary compression on the file to be processed based on a preset initial compression quality to obtain a preliminary compressed file.
[0075] Compression quality can be expressed as a percentage, for example, 100% means the best compression, that is, the highest quality. The size and quality of the compressed file can be controlled by adjusting the compression quality parameters. Under the same compression algorithm, the lower the compression quality, the smaller the file capacity after compression, but the more information is lost. For example, specifically, when compressing an image file, the compression quality range is 0 to 100%. Among them, 100% means the highest quality (i.e. lossless compression), and 0 means the lowest quality (i.e. highly compressed). When the compression quality is 100%, there is no obvious quality loss in the compressed file, and the details, color, and clarity of the image remain almost the same. It is usually used to save high-quality images. When the compression quality is 90%, there is a slight quality loss after compression, but this loss is difficult to detect with the naked eye, and the size of the compressed file will be significantly reduced.
[0076] The initial compression quality of the file can be set according to the business requirements of the specific application scenario. For example, to save high-quality images, the initial compression quality can usually be set to 100%. Alternatively, the initial compression quality is set to a higher value. After obtaining the file to be processed, the file to be processed is first preliminarily compressed using a higher initial compression quality to obtain a preliminarily compressed file.
[0077] Step S130, adjusting the compression quality according to the capacity of the preliminary compressed file and a preset capacity upper limit, compressing the preliminary compressed file based on the adjusted compression quality, and obtaining a target compressed file corresponding to the file to be processed.
[0078] Generally, the capacity of the initially compressed file may still exceed the preset capacity limit and cannot meet the file size limit requirements in the business requirements, so the initially compressed file needs to be recompressed. Specifically, the compression quality can be appropriately lowered so that the adjusted compression quality is less than the initial compression quality, and the initially compressed file is recompressed based on the adjusted compression quality so that the target compressed file obtained after recompression can meet the file size limit requirements in the business requirements.
[0079] For example, if the size of the initially compressed file is larger than the preset upper capacity limit, the compression quality is lowered, and the initially compressed file is compressed again using the lowered compression quality. If the file obtained after this compression is still larger than the preset upper capacity limit, the compression quality is further lowered until the file obtained after compression is smaller than the preset upper capacity limit, at which point the target compressed file can meet the file size limit requirements in the business requirements.
[0080] For another example, if the capacity of the initial compressed file is smaller than the preset capacity upper limit and the difference between the two is large, the compression quality is increased to improve the quality of the target compressed file, and the initial compressed file is compressed again using the increased compression quality. If the file obtained after this compression is still smaller than the preset capacity upper limit and the difference between the two is large, the compression quality is further increased until the file obtained after compression is close to the preset capacity upper limit. At this time, the compressed file that is smaller than the preset capacity upper limit and has the highest quality is used as the target compressed file, and the target compressed file can meet the file size limit requirements in the business needs.
[0081] For another example, if the capacity of the initially compressed file is larger than the preset capacity upper limit, the compression quality is lowered, and the initially compressed file is compressed again using the lowered compression quality. If the file obtained after this compression is smaller than the preset capacity upper limit and the difference between the two is large, the compression quality is increased to improve the quality of the target compressed file, and the initially compressed file is compressed again using the increased compression quality. If the file obtained after this compression is smaller than the preset capacity upper limit, it is used as the target compressed file, and the target compressed file can meet the file size limit requirements in the business requirements.
[0082] In summary, in this step, the compression quality is adjusted according to the capacity of the preliminary compressed file and the preset capacity upper limit, so that the capacity of the compressed file is close to the preset capacity upper limit. Then, the preliminary compressed file is recompressed based on the adjusted compression quality to obtain the target compressed file corresponding to the file to be processed.
[0083] Based on the embodiments of the present disclosure, the file to be processed is first preliminarily compressed based on a preset higher initial compression quality, and then the preliminarily compressed file is recompressed based on the adjusted compression quality. By gradually adjusting the compression quality through the above steps, the file to be processed can be compressed to a preset capacity limit while ensuring the compression quality as much as possible, which can meet the needs of limiting file capacity and ensuring file quality in specific application scenarios.
[0084] like Figure 2 As shown, in one embodiment, Figure 1 Step S130 in the embodiment of the present invention is to adjust the compression quality according to the capacity of the preliminary compressed file and the preset capacity upper limit, which may specifically include:
[0085] Step S210: setting an initial adjustment interval of the compression quality based on the initial compression quality.
[0086] For example, the initial compression quality can be used as the upper limit of the initial adjustment interval, and a range of values less than the initial compression quality can be set as the initial adjustment interval. In one example, the initial compression quality is 100%, and the initial adjustment interval is set to an interval from 10% to 100%.
[0087] Step S220, setting a target capacity corresponding to the to-be-processed file based on a preset upper capacity limit, where the target capacity is the capacity of the target compressed file obtained after processing the to-be-processed file.
[0088] In one example, during the business processing, the image file needs to be uploaded to the data receiving platform in a specified encoding format, and the data receiving platform has a capacity limit for the uploaded content, and the encoded size cannot exceed the preset capacity limit. However, when performing compression processing, the image file is only compressed to below the preset capacity limit, and the size may exceed the preset capacity limit after encoding. In view of the above situation, the target capacity corresponding to the processed file can be set to a capacity value less than the preset capacity limit according to actual business needs. In an example, the preset capacity limit corresponding to the file to be processed is 800K, and the target capacity can be set to 600K. Based on the above settings, the capacity of the target compressed file after compression processing is about 600K, which can ensure that the capacity of the file after encoding is less than 800K.
[0089] Step S230 : Based on the target capacity, the adjusted compression quality is searched in the initial adjustment interval using at least one iteration of a binary search algorithm.
[0090] Among them, the binary search algorithm is the process of finding a specific value in ordered data. The basic idea is to divide the search space into two after each comparison, and quickly locate the target value by continuously halving the search range.
[0091] Specifically, in the first iteration, the compression quality corresponding to the middle value of the initial adjustment interval is selected as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality. In the first case, if the file capacity after compression is greater than the target capacity and the absolute value of the difference between the two is large, the first half of the initial adjustment interval is used as the new adjustment interval, that is, the upper limit of the new adjustment interval is set to the middle value of the initial adjustment interval, and the adjusted compression quality is continued to be found in the new adjustment interval in the next iteration; in the second case, if the file capacity after compression is less than the target capacity and the absolute value of the difference between the two is large, the second half of the initial adjustment interval is used as the new adjustment interval, that is, the lower limit of the new adjustment interval is set to the middle value of the initial adjustment interval, and the adjusted compression quality is continued to be found in the new adjustment interval in the next iteration; in the third case, if the file capacity after compression is equal to the target capacity or the absolute value of the difference between the two is not large, that is, the capacity values of the two are close, the current compression quality is used as the adjusted compression quality. Repeat the above iterative process many times until the adjusted compression quality is found, so that the file capacity after compression based on the compression quality is close to the target capacity. Among them, a threshold of the capacity difference can be set according to actual needs. When the difference between the file capacity after compression processing and the target capacity is less than or equal to the above threshold, it is determined that the capacity values of the two are close. At this time, the current compression quality can be used as the adjusted compression quality.
[0092] The above binary search algorithm is a highly efficient search algorithm. By halving the search range each time, it can significantly reduce the search time. Even when the amount of data is large, it can still maintain an efficient search speed. In addition, the algorithm occupies less space and saves system resources. Searching for the adjusted compression quality based on the binary search algorithm can improve the system's operating efficiency and improve the timeliness of file compression processing.
[0093] In one embodiment, Figure 2 Step S210 in the embodiment of the present invention is to set an initial adjustment interval of the compression quality based on the initial compression quality, including:
[0094] The initial compression quality is set as the upper limit value of the initial adjustment interval, and the product of the upper limit value and a preset first ratio is set as the lower limit value of the initial adjustment interval; wherein the preset first ratio is less than 1 and greater than zero.
[0095] In one example, the initial compression quality is 100%, and the first ratio is set to 1 / 10, then the upper limit of the initial adjustment interval is 100% and the lower limit is 10%, that is, in the subsequent process, the adjusted compression quality is found in the interval of 10% to 100%.
[0096] In the disclosed embodiment, the first ratio can be reasonably set according to business needs, so that the file compression tool can search for the adjusted compression quality within a suitable range. By reasonably setting the first ratio, the search efficiency can be improved, thereby improving the timeliness of the system operation.
[0097] In one embodiment, Figure 2 Step S220 in the embodiment of the present invention is to set a target capacity corresponding to the to-be-processed file based on a preset upper capacity limit, including:
[0098] The product of the preset capacity upper limit and the preset second ratio is set as the capacity difference; wherein the preset second ratio is less than 1 and greater than zero;
[0099] The difference between the preset capacity upper limit and the capacity difference is set as the target capacity.
[0100] In one example, the second ratio can be set to a value between 20% and 30%. For example, the preset upper capacity limit corresponding to the to-be-processed file is 800K, and the second ratio is set to 25%. Then the capacity difference between the preset upper capacity limit and the target capacity is 800K*25%=200K, and the target capacity is 600K. Based on the above settings, the final target compressed file is compressed to about 600K in the subsequent process, so that the capacity of the file after encoding can be guaranteed to be less than 800K.
[0101] In the embodiment of the present disclosure, the second ratio can be reasonably set according to business needs so that there is a certain capacity difference between the preset capacity upper limit and the target capacity. By reasonably setting the second ratio, it can be ensured that the capacity of the target compressed file after encoding is less than the preset capacity upper limit, thereby meeting the need to limit file capacity in specific application scenarios.
[0102] In one implementation, an iteration of the binary search algorithm includes:
[0103] The compression quality corresponding to the middle value of the current adjustment interval corresponding to this iteration process is used as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality;
[0104] If the absolute value of the first difference between the file capacity after the current compression process and the target capacity is less than or equal to the preset first difference threshold, the iterative process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality; or, if the absolute value of the first difference between the file capacity after the current compression process and the target capacity is greater than the preset first difference threshold, the upper limit or lower limit of the current adjustment interval is re-determined based on the binary search algorithm;
[0105] If the number of iterations of this iteration exceeds a preset number threshold, or the time for processing the file to be processed exceeds a preset time threshold, the file to be processed is determined to be in an abnormal state, and the current processing of the file to be processed is stopped.
[0106] Specifically, in each iteration process, the compression quality corresponding to the middle value of the current adjustment interval is selected as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality.
[0107] In the first case, if the file capacity after the compression processing is greater than the target capacity and the absolute value of the difference between the two is greater than the first difference threshold, the first half of the current adjustment interval is used as the new adjustment interval, that is, the upper limit value of the new adjustment interval is set to the middle value of the current adjustment interval, and the adjusted compression quality is continued to be searched in the new adjustment interval during the next iteration.
[0108] In the second case, if the file capacity after the above compression processing is smaller than the target capacity and the absolute value of the difference between the two is greater than the first difference threshold, the second half of the current adjustment interval is used as the new adjustment interval, that is, the lower limit value of the new adjustment interval is set to the middle value of the initial current adjustment interval, and the adjusted compression quality is continued to be searched in the new adjustment interval during the next iteration.
[0109] In the third case, if the file capacity after the compression processing is equal to the target capacity or the absolute value of the difference between the two is less than or equal to the first difference threshold, that is, the capacity values of the two are close, then the iteration process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality.
[0110] The above iterative process is repeated multiple times until the adjusted compression quality is found, so that the file capacity after compression based on the compression quality is close to the target capacity. Among them, the first difference threshold can be set according to actual needs. When the difference between the file capacity after compression and the target capacity is less than or equal to the above threshold, it is determined that the capacity values of the two are close, and the current compression quality can be used as the adjusted compression quality.
[0111] In addition, the number of iterations is accumulated during each iteration. Specifically, a number variable can be set, and the number variable is accumulated and calculated after each iteration. In addition, the timing starts from the processing of the file to be processed, and the processing time of the file is recorded. If the number of iterations of this iteration exceeds the preset number threshold, or the time for processing the file to be processed exceeds the preset time threshold, the file to be processed is determined to be in an abnormal state and the abnormality is processed. Specifically, the iteration process is stopped after the abnormality is captured, and corresponding processing is performed for the abnormal state. For example, the abnormality may be caused by the image in the file to be processed being too large. Other tools can be used to adjust the capacity of the file to be processed first, and then perform compression processing.
[0112] In the embodiments of the present disclosure, by using the exception handling mechanism reasonably, it is possible to avoid program crashes or unexpected results, and by capturing and handling exceptions to perform reasonable exit operations or corresponding processing, the robustness and stability of the program can be increased. Specifically, by limiting the processing time of the files to be processed and the number of algorithm iterations, an exception is thrown when the processing time is too long or the number of iterations is too many, thereby effectively controlling the file processing time, avoiding long program execution time, improving system operation efficiency, and meeting the timeliness requirements for file compression processing in specific application scenarios.
[0113] In one embodiment, the above method further comprises:
[0114] If the second difference between the current compression quality and the lower limit value of the initial adjustment interval is less than or equal to the preset second difference threshold, the initial adjustment interval is readjusted, and based on the adjusted initial adjustment interval, at least one iteration process of the binary search algorithm is performed to search for the adjusted compression quality in the initial adjustment interval.
[0115] For example, the upper limit of the initial adjustment interval is 100% and the lower limit is 10%, and the binary search algorithm searches for the adjusted compression quality in the interval from 10% to 100%. During the algorithm iteration process, if the current compression quality is close to 10%, it is necessary to readjust the initial adjustment interval, and re-execute step S230 based on the adjusted initial adjustment interval to continue searching for the adjusted compression quality.
[0116] Specifically, a second difference threshold may be pre-set. If the second difference between the current compression quality and the lower limit of the initial adjustment interval is less than or equal to the threshold, it can be determined that the current compression quality is close to the lower limit of the initial adjustment interval. At this time, the iteration may be stopped and the initial adjustment interval may be readjusted. For example, if the original initial adjustment interval is set to an interval from 10% to 100%, the new initial adjustment interval may be adjusted to an interval from 1% to 10%, and step S230 may be re-executed based on the new initial adjustment interval to continue searching for the adjusted compression quality.
[0117] Taking image file compression as an example, re-adjusting the initial adjustment interval can reduce the resolution of the target compressed file. If the current compression quality is close to the lower limit of the initial adjustment interval and the file size is still not compressed to the target capacity, the image resolution is reduced to further compress the file. Based on the above method, by adjusting the compression quality range and reducing the image resolution, the file can be compressed to the target capacity, meeting the need to limit the file capacity in specific application scenarios.
[0118] In one embodiment, the above method further comprises:
[0119] Multiple thread resources are allocated correspondingly to multiple files to be processed, and the multiple thread resources are used to compress the multiple files to be processed in parallel.
[0120] Among them, multithreading refers to the simultaneous execution of multiple independent tasks or operations in the same program. Each task is executed by a separate thread, and these threads share the program's resources and memory space. The multithreading processing method allows the program to handle multiple concurrent tasks at the same time, thereby improving the program's operating efficiency and response speed.
[0121] In the disclosed embodiment, multiple thread resources are allocated corresponding to multiple files to be processed, so that the program can execute compression tasks for multiple files at the same time, which can fully utilize system resources, improve system operating efficiency and overall processing performance, thereby responding to user operations more quickly and improving user experience.
[0122] In one implementation, after obtaining the target compressed file corresponding to the file to be processed, the method further includes:
[0123] Store the target compressed file in the cache;
[0124] After obtaining the file to be processed, searching the cache for the target compressed file corresponding to the file to be processed;
[0125] If the target compressed file exists in the cache, the steps of preliminary compression and compressing the preliminary compressed file are not performed, and the target compressed file is obtained from the cache; or, if the target compressed file does not exist in the cache, the steps of preliminary compression and compressing the preliminary compressed file are performed to process the file to be processed.
[0126] Caching improves the performance and efficiency of applications by temporarily storing frequently accessed data in a location that can be retrieved faster than the original source. Caching helps reduce the time required to retrieve data and reduces the load on the original data source. In the disclosed embodiment, the target compressed file is stored in the cache. If the user applies to compress the same file to be processed next time, the compression process does not need to be repeated, but the target compressed file corresponding to the file to be processed can be directly obtained from the cache, thereby reducing latency, improving performance, and enhancing user experience.
[0127] After obtaining the file to be processed in step S110, it is possible to first search in the cache whether there is a target compressed file corresponding to the file to be processed. If there is a target compressed file corresponding to the file to be processed in the cache, that is, the file has been compressed and the compressed target compressed file is stored in the cache, so it is only necessary to directly obtain the target compressed file from the cache without performing the steps of performing preliminary compression on the file to be processed (step S120) and compressing the preliminary compressed file (step S130). If there is no target compressed file corresponding to the file to be processed in the cache, the file has not been compressed before, and the steps of performing preliminary compression on the file to be processed and recompressing the preliminary compressed file are performed to process the file to be processed.
[0128] The cache stores data in a temporary storage location so that it can be quickly retrieved when needed, thereby avoiding the need to re-acquire and process the original data, significantly improving the response speed and performance of the application. In the disclosed embodiment, by searching for the target compressed file in the cache, the response speed of the program and the user experience are improved.
[0129] In summary, the embodiments of the present disclosure provide a relatively efficient file compression method, which can compress files to a specified size range in an appropriate time and meet the file size restriction requirements of the data receiving platform while ensuring the file quality.
[0130] In an example of using a JAVA function library to compress an image file, the above file compression method may specifically include the following steps:
[0131] Step 1: Initial Setup
[0132] Input: image file path inputFilePath, target file size targetSizeKB, output file path outputFilePath.
[0133] Operation: Read the image file and convert it to RGB color space. Converting the color space is a preprocessing step for the image file. If the image compression method in the JAVA function library is used for image compression, the image file can be converted to a color space according to the preprocessing requirements of the compression method in the function library.
[0134] Output: BufferedImage object. For the file to be compressed, an object called BufferedImage can be created in advance to execute the method of the class in the JAVA function library. Through this step, an image file converted to RGB color space is output.
[0135] Step 2: Initial compression
[0136] Input: BufferedImage object, initial compression quality maxQuality=1.0f. The initial compression quality 1.0 means the compression quality is 100%, which is lossless compression; "f" represents a floating point number.
[0137] Operation: Use the initial compression quality to preliminarily compress the image. The compression algorithm can use the compression processing function under the JAVA.IO package, and can also call the processing function in the JAVAx.imageio library. Or other file compression algorithms can be used as required.
[0138] Output: compressed byte array fileBytes. Byte data refers to data stored in a continuous area in bytes. When loading an image, it is represented as a byte array, which contains all the pixel values of the image, and each pixel value corresponds to one byte.
[0139] Step 3: Dynamically adjust compression quality
[0140] Input: compressed byte array fileBytes, target file size (i.e. target capacity)
[0141] targetSizeBytes=targetSizeKB*1024, compression quality range is minQuality=0.1f to maxQuality=1.0f.
[0142] Among them, byte conversion is performed through "targetSizeKB*1024", for example, 800KB is converted into 800*1024 bytes; minQuality represents the lower limit value of the interval, and maxQuality represents the upper limit value of the interval; the interval from 0.1f to 1.0f is the initial adjustment interval, which is equivalent to the interval from 10% to 100%.
[0143] operate:
[0144] Use a binary search algorithm to dynamically adjust the compression quality and gradually narrow the range.
[0145] If fileBytes size exceeds targetSizeBytes, then reduce maxQuality.
[0146] If fileBytes size is below targetSizeBytes, increase minQuality.
[0147] The adjustment is repeated until the file size approaches the target file size or the maximum number of iterations MAX_ITERATIONS is reached.
[0148] Typically, the target file size is set to be 20-30% smaller than the required preset capacity limit. For example, if the preset capacity limit is 800KB, the target file size in the program can be set to 600KB.
[0149] Output: compressed byte array fileBytes. The output of this step is still a BufferedImage object, which is the compressed result of the processed file.
[0150] Step 4: Resolution Adjustment
[0151] Input: BufferedImage object, current compression quality range minQuality and maxQuality.
[0152] operate:
[0153] If the compression quality is close to the lower limit of the current compression quality range and the file size still does not reach the target file size, the image resolution is reduced. Reduce the image resolution by rescaling the compression quality range.
[0154] Re-adjust the compression quality range and repeat Step 3. Adjust the upper and lower limits of the current compression quality range according to the specific compression situation, for example, adjust the range to a smaller value of 0.01f to 0.1f.
[0155] Step 5: Time and iteration limits
[0156] Input: current processing time currentTime, maximum processing time
[0157] MAX_PROCESSING_TIME_MS, current number of iterations, maximum number of iterations MAX_ITERATIONS.
[0158] operate:
[0159] Checks whether the current processing time exceeds the maximum processing time.
[0160] Check whether the current iteration number exceeds the maximum iteration number.
[0161] If any of the above conditions are met, the compression process is terminated and an exception is thrown.
[0162] Step 6: Parallel processing (you can choose whether to perform parallel processing based on business needs)
[0163] Input: multiple image file paths inputFilePaths, target file size targetSizeKB, output file path outputFilePaths.
[0164] operate:
[0165] Use multithreading to parallelize the compression task of multiple image files.
[0166] Each thread executes Step 1 to Step 5 independently.
[0167] Step 7: Cache mechanism (you can choose whether to cache based on business needs)
[0168] Input: image file path inputFilePath, cache object cache. The cache object is the BufferedImage object created in Step 1. The compressed image is saved in the cache, so the BufferedImage object is a cache object.
[0169] operate:
[0170] Checks whether there is a compression result for the same file in the cache.
[0171] If it exists, the cached result is used directly and the compression process is skipped.
[0172] If it does not exist, execute Step 1 to Step 5, compress the file, and store the compressed result in the cache.
[0173] Step 8: Save the compression result
[0174] Input: compressed byte array fileBytes, output file path outputFilePath.
[0175] Action: Save the compressed image file to the specified path.
[0176] In summary, based on the above implementation steps, this separate embodiment can achieve the following beneficial technical effects:
[0177] 1. Use multi-stage compression strategies to meet the needs of limiting file capacity and ensuring file quality in specific application scenarios. Specifically include:
[0178] Initial Compression: Performs initial compression using a higher compression quality.
[0179] Gradual Adjustment: Dynamically adjusts the compression quality according to the file size until the compressed file is close to the target file size.
[0180] Resolution Adjustment: When the compression quality approaches the minimum value of the adjustment range, the image resolution is reduced to further reduce the file size.
[0181] 2. Improve the search speed by dynamically adjusting the compression quality, thereby improving the operating efficiency of the system. Specifically, it uses the binary method to dynamically adjust the compression quality to approach the target file size faster.
[0182] 3. Through time and iteration number limits, the file processing time can be effectively controlled to meet the timeliness requirements of file compression processing in specific application scenarios. Specifically include:
[0183] Maximum number of iterations: Prevent the compression process from falling into an infinite loop.
[0184] Time limit: Ensure that each compression operation is completed within a controllable time.
[0185] 4. Improve system operation efficiency and response speed through parallel processing. Specifically, use multi-threading to process multiple files in parallel to improve overall processing efficiency.
[0186] 5. Reduce latency through caching mechanism, improve the response speed of the program and user experience. Specifically, for the same file, use caching mechanism to avoid repeated compression.
[0187] like Figure 3 As shown, the present disclosure also provides a corresponding embodiment of a file compression device. For the beneficial effects or technical problems solved by the device, please refer to the description of the method corresponding to each device, or refer to the description in the invention content, which will not be repeated here.
[0188] In an embodiment of the file compression device, the device comprises:
[0189] An acquisition unit 100 is used to acquire a file to be processed and a preset upper capacity limit, where the preset upper capacity limit is a file capacity that is specified to be reached after the file to be processed is processed;
[0190] The first processing unit 200 is used to perform preliminary compression on the file to be processed based on a preset initial compression quality to obtain a preliminary compressed file;
[0191] The second processing unit 300 is used to adjust the compression quality according to the capacity of the preliminary compressed file and a preset capacity upper limit, and compress the preliminary compressed file based on the adjusted compression quality to obtain a target compressed file corresponding to the file to be processed.
[0192] like Figure 4 As shown, in one embodiment, the second processing unit 300 includes:
[0193] A first setting subunit 310, configured to set an initial adjustment interval of compression quality based on the initial compression quality;
[0194] The second setting subunit 320 is used to set a target capacity corresponding to the to-be-processed file based on a preset upper capacity limit, where the target capacity is the capacity of the target compressed file obtained after processing the to-be-processed file;
[0195] The search subunit 330 is used to search for the adjusted compression quality in the initial adjustment interval based on the target capacity by using at least one iteration process of the binary search algorithm.
[0196] In one implementation, the first setting subunit 310 is used to:
[0197] The initial compression quality is set as the upper limit value of the initial adjustment interval, and the product of the upper limit value and a preset first ratio is set as the lower limit value of the initial adjustment interval; wherein the preset first ratio is less than 1 and greater than zero.
[0198] In one implementation, the second setting subunit 320 is used to:
[0199] The product of the preset capacity upper limit and the preset second ratio is set as the capacity difference; wherein the preset second ratio is less than 1 and greater than zero;
[0200] The difference between the preset capacity upper limit and the capacity difference is set as the target capacity.
[0201] In one embodiment, one iteration of the binary search algorithm in the search subunit 330 is used to:
[0202] The compression quality corresponding to the middle value of the current adjustment interval corresponding to this iteration process is used as the current compression quality, and the preliminary compressed file is compressed based on the current compression quality;
[0203] If the absolute value of the first difference between the file capacity after the current compression process and the target capacity is less than or equal to the preset first difference threshold, the iterative process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality; or, if the absolute value of the first difference between the file capacity after the current compression process and the target capacity is greater than the preset first difference threshold, the upper limit or lower limit of the current adjustment interval is re-determined based on the binary search algorithm;
[0204] If the number of iterations of this iteration exceeds a preset number threshold, or the time for processing the file to be processed exceeds a preset time threshold, the file to be processed is determined to be in an abnormal state, and the current processing of the file to be processed is stopped.
[0205] like Figure 5 As shown, in one embodiment, the above device further includes a third processing unit 400, which is used to:
[0206] If the second difference between the current compression quality and the lower limit value of the initial adjustment interval is less than or equal to the preset second difference threshold, the initial adjustment interval is readjusted, and based on the adjusted initial adjustment interval, at least one iteration process of the binary search algorithm is performed to search for the adjusted compression quality in the initial adjustment interval.
[0207] like Figure 6 As shown, in one embodiment, the above device further includes a parallel processing unit 500, which is used to:
[0208] Multiple thread resources are allocated correspondingly to multiple files to be processed, and the multiple thread resources are used to compress the multiple files to be processed in parallel.
[0209] In one embodiment, the above device further includes a storage unit 600, which is used to:
[0210] After obtaining the target compressed file corresponding to the file to be processed, storing the target compressed file in the cache;
[0211] The above device further includes a searching unit 700, which is used to:
[0212] After obtaining the file to be processed, searching the cache for the target compressed file corresponding to the file to be processed;
[0213] If the target compressed file exists in the cache, the steps of preliminary compression and compressing the preliminary compressed file are not performed, and the target compressed file is obtained from the cache; or, if the target compressed file does not exist in the cache, the steps of preliminary compression and compressing the preliminary compressed file are performed to process the file to be processed.
[0214] The file compression device of the embodiment of the present disclosure corresponds to the above-mentioned file compression method embodiments of the present disclosure in terms of specific implementation and beneficial technical effects. The relevant contents can be referenced to each other and will not be repeated here.
[0215] Below, reference Figure 7 The electronic device according to the embodiment of the present disclosure is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signals from them.
[0216] Figure 7 A block diagram of an electronic device according to an embodiment of the present disclosure is illustrated.
[0217] like Figure 7 As shown, the electronic device includes one or more processors and memory.
[0218] The processor may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0219] The memory may store one or more computer program products, and the memory may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program products may be stored on a computer-readable storage medium, and a processor may run the computer program product to implement the file compression method of each embodiment of the present disclosure and / or other desired functions.
[0220] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0221] In addition, the input device may also include, for example, a keyboard, a mouse, and the like.
[0222] The output device can output various information to the outside, including determined distance information, direction information, etc. The output device can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.
[0223] Of course, to simplify, Figure 7 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.
[0224] In addition to the above methods and devices, embodiments of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the file compression method according to various embodiments of the present disclosure described in the above part of this specification.
[0225] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0226] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, enables the processor to execute the steps of the file compression method according to various embodiments of the present disclosure described in the above part of this specification.
[0227] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0228] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.
[0229] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0230] The block diagrams of the devices, apparatuses, equipment, and systems involved in this disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including," "comprising," "having," and the like are open words, referring to "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or," and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0231] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
[0232] It should also be noted that in the apparatus, device and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0233] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0234] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. A file compression method, characterized in that: include: Obtaining a file to be processed and a preset upper capacity limit, wherein the preset upper capacity limit is a file capacity that is specified to be reached after the file to be processed is processed; Performing preliminary compression on the to-be-processed file based on a preset initial compression quality to obtain a preliminary compressed file; The compression quality is adjusted according to the capacity of the preliminary compressed file and the preset capacity upper limit, and the preliminary compressed file is compressed based on the adjusted compression quality to obtain a target compressed file corresponding to the file to be processed.
2. The method according to claim 1, characterized in that: The adjusting the compression quality according to the capacity of the preliminary compressed file and the preset capacity upper limit includes: Setting an initial adjustment interval of compression quality based on the initial compression quality; Setting a target capacity corresponding to the to-be-processed file based on the preset capacity upper limit, wherein the target capacity is the capacity of the target compressed file obtained after processing the to-be-processed file; Based on the target capacity, the adjusted compression quality is searched in the initial adjustment interval using at least one iteration of a binary search algorithm.
3. The method according to claim 2, characterized in that The step of setting an initial adjustment interval of compression quality based on the initial compression quality includes: The initial compression quality is set as the upper limit value of the initial adjustment interval, and the product of the upper limit value and a preset first ratio is set as the lower limit value of the initial adjustment interval; wherein the preset first ratio is less than 1 and greater than zero.
4. The method according to claim 2, characterized in that: The setting of the target capacity corresponding to the to-be-processed file based on the preset capacity upper limit includes: The product of the preset capacity upper limit and the preset second ratio is set as the capacity difference; wherein the preset second ratio is less than 1 and greater than zero; The difference between the preset capacity upper limit and the capacity difference is set as the target capacity.
5. The method according to claim 2, characterized in that: One iteration of the binary search algorithm includes: The compression quality corresponding to the middle value of the current adjustment interval corresponding to the current iteration process is used as the current compression quality, and the compression process is performed on the preliminary compressed file based on the current compression quality; If the absolute value of the first difference between the file capacity after the current compression process and the target capacity is less than or equal to a preset first difference threshold, the iterative process of the binary search algorithm is terminated and the current compression quality is used as the adjusted compression quality; or, if the absolute value of the first difference between the file capacity after the current compression process and the target capacity is greater than the preset first difference threshold, the upper limit or lower limit of the current adjustment interval is re-determined based on the binary search algorithm; If the number of iterations of this iteration exceeds a preset number threshold, or the time for processing the to-be-processed file exceeds a preset time threshold, it is determined that the to-be-processed file is in an abnormal state, and the current processing of the to-be-processed file is stopped.
6. The method according to claim 5, characterized in that The method further comprises: If the second difference between the current compression quality and the lower limit value of the initial adjustment interval is less than or equal to a preset second difference threshold, the initial adjustment interval is readjusted, and based on the adjusted initial adjustment interval, at least one iteration process of using the binary search algorithm is performed to search for the adjusted compression quality in the initial adjustment interval.
7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: Multiple thread resources are allocated correspondingly to multiple files to be processed, and the multiple thread resources are used to compress the multiple files to be processed in parallel.
8. The method according to any one of claims 1 to 6, characterized in that After obtaining the target compressed file corresponding to the file to be processed, the method further includes: Storing the target compressed file in a cache; After obtaining the file to be processed, searching the cache for a target compressed file corresponding to the file to be processed; If the target compressed file exists in the cache, the preliminary compression and the steps of compressing the preliminary compressed file are not performed, and the target compressed file is obtained from the cache; or, if the target compressed file does not exist in the cache, the preliminary compression and the steps of compressing the preliminary compressed file are performed to process the file to be processed.
9. An electronic device, characterized in that: include: A memory for storing a computer program product; A processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, it implements the method described in any one of claims 1 to 8.
10. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed by a processor, the method described in any one of claims 1 to 8 is implemented.