File format conversion method and device and storage medium

By obtaining the information and content of the target file, and using the file format inheritance tree and characteristic bytes to determine the source file format, the problem of conversion failure caused by missing file extensions is solved, and efficient file format conversion and circulation are achieved.

CN121807775APending Publication Date: 2026-04-07ZHUHAI KINGSOFT OFFICE SOFTWARE +2
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-01
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing technologies, when transferring files across systems or storing them long-term, may result in missing file extensions due to operational errors, making it impossible to determine the original format and conversion logic, thus affecting usage and circulation efficiency.

Method used

By obtaining the information and content of the target file, using the file format inheritance tree and characteristic bytes, the source file format of the target file is determined, and it is previewed or converted in the current application. A suitable conversion path is selected to ensure that the file format conversion is successful.

Benefits of technology

Ensuring successful file format conversion improves file usage and circulation efficiency and avoids conversion failures caused by missing format identifiers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807775A_ABST
    Figure CN121807775A_ABST
Patent Text Reader

Abstract

The invention relates to a file format conversion method and device and a storage medium. The method comprises the steps of obtaining a target file; determining a source file format of the target file according to the information of the target file; and in response to a file format conversion request, converting the target file from the source file format to a target file format. The source file format of the target file is determined through the information of the target file, so that the file format of the target file can be successfully converted, and the use and circulation efficiency of the target file is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and in particular to a file format conversion method and device and storage medium. BACKGROUND

[0002] In the field of office and file processing, file format conversion is frequently and critically required. File types are diverse, which can be image files, document files, and video files, etc. Format conversion (e.g., PNG image to JPEG image, DOC document to PDF document) of these files needs to be accurately switched through technical means. The current mainstream way is to analyze the file source format, determine its data structure and coding rules, and then create a new file according to the target format and write the content. This way can support file flow processing in the conventional scene.

[0003] However, as the file flow scene becomes more complex, the limitations of the existing conversion method gradually appear. When files are transmitted across systems or stored for a long time, they may be missing format identifiers (e.g., file suffixes) due to operational errors, such as DOC documents, MP4 videos, etc. The existing technology relies on format identifiers to determine file formats, and the system cannot determine the original format and conversion logic when the format identifier is missing, ultimately resulting in conversion failure, affecting use and flow efficiency. SUMMARY

[0004] To solve the above technical problem that files may be missing format identifiers (e.g., file suffixes) due to operational errors when they are transmitted across systems or stored for a long time, such as DOC documents, MP4 videos, etc. The existing technology relies on format identifiers to determine file formats, and the system cannot determine the original format and conversion logic when the format identifier is missing, ultimately resulting in conversion failure, affecting use and flow efficiency, the present application provides a file format conversion method, device, electronic equipment and storage medium. The specific technical solutions are as follows: In the first aspect of the present application, a file format conversion method is first provided, which comprises: obtaining a target file; determining the source file format of the target file according to the information of the target file; in response to a file format conversion request, converting the target file from the source file format to a target file format.

[0005] In an optional implementation, the determining the source file format of the target file according to the information of the target file comprises: obtaining file information and file content of the target file; determining the source file format of the target file according to the file information and the file content.

[0006] In an optional implementation, the determining the source file format of the target file according to the file information and the file content comprises: determining a base file format of the target file according to a signature byte in the file information; determining the source file format of the target file according to the base file format and the file content based on a file format inheritance tree.

[0007] In an optional implementation, the determining the source file format of the target file according to the base file format and the file content based on the file format inheritance tree comprises: determining at least one candidate file format according to the base file format based on the file format inheritance tree, wherein the base file format is compatible with the candidate file format; determining the source file format of the target file from the at least one candidate file format according to the file content.

[0008] In an optional implementation, the determining the at least one candidate file format according to the base file format based on the file format inheritance tree comprises: obtaining a file format inheritance tree; finding a first node corresponding to the base file format and at least one child node under the first node in the file format inheritance tree, and determining a candidate file format corresponding to the at least one child node.

[0009] In an optional implementation, the determining the source file format of the target file from the at least one candidate file format according to the file content comprises: determining a format specification corresponding to the candidate file format for any candidate file format; determining the candidate file format as the source file format of the target file in a case where the file content satisfies the format specification.

[0010] In an optional implementation, after the determining the source file format of the target file, the method further comprises: in response to a file preview request, detecting whether a previewable file format supported by a current application contains the source file format; in a case where the previewable file format contains the source file format, displaying the target file in the source file format in the current application.

[0011] In an optional implementation, the method further comprises: In a case that the previewable file format does not contain the source file format, a file format inheritance tree is acquired, a second node corresponding to the source file format is searched in the file format inheritance tree; A parent node on the second node is searched in the file format inheritance tree, and a compatible file format corresponding to the parent node is determined; In a case that the previewable file format contains the compatible file format, the target file is displayed in the compatible file format by a current application; Or, the target file is converted from the source file format to the compatible file format, and the target file is displayed in the compatible file format by the current application.

[0012] In an optional embodiment, the method further comprises: In a case that the previewable file format does not contain the compatible file format, the target file is converted from the source file format to any previewable file format; The target file is displayed in any previewable file format by the current application.

[0013] In an optional embodiment, the conversion of the target file from the source file format to the target file format comprises: At least one candidate conversion path from the source file format to the target file format is determined; A target conversion path from the source file format to the target file format is determined from at least one candidate conversion path; The target file is converted from the source file format to the target file format through the target conversion path.

[0014] In an optional embodiment, the determination of at least one candidate conversion path from the source file format to the target file format comprises: A converter set is acquired, converters in the converter set are used to convert one file format to another file format, and file format conversion capabilities are different; At least one candidate conversion path from the source file format to the target file format is determined by using a recursive traversal method according to the converter set.

[0015] In an optional embodiment, the determination of a target conversion path from the source file format to the target file format from at least one candidate conversion path comprises: For any candidate conversion path, a path cost corresponding to the candidate conversion path is determined; According to the path cost, at least one of the candidate conversion paths is sorted to obtain a candidate conversion path sorting sequence; According to the candidate conversion path sorting sequence, a target conversion path is determined for converting the target file from the source file format to the target file format.

[0016] In an optional embodiment, the determining of the path cost corresponding to the candidate conversion path comprises: At least one third converter involved in the candidate conversion path is determined, and a corresponding historical cost is obtained from the third converter; The historical cost is a historical ratio of time spent by the third converter for completing file format conversion to file size after the file format conversion is completed; The respective costs of the at least one third converter are summed to obtain the path cost corresponding to the candidate conversion path.

[0017] In an optional embodiment, after the target file is converted from the source file format to the target file format by the target conversion path, the method further comprises: The file size of the target file in the target file format is determined, and at least one fourth converter involved in the target conversion path is determined; For any fourth converter, a current ratio between time spent by the fourth converter for completing file format conversion and the file size of the target file in the target file format is determined, and the current ratio is stored in the fourth converter as a current cost.

[0018] In a second aspect of the embodiments of the present application, a file format conversion device is further provided, and the device comprises: A file acquisition module is configured to acquire a target file; A format determination module is configured to determine a source file format of the target file according to information of the target file; A file format conversion module is configured to convert the target file from the source file format to a target file format in response to a file format conversion request.

[0019] In an optional embodiment, the format determination module specifically comprises: An information and content acquisition submodule is configured to acquire file information and file content of the target file; A format determination submodule is configured to determine the source file format of the target file according to the file information and the file content.

[0020] In an optional embodiment, the format determination submodule specifically comprises: The basic file format determining unit is configured to determine a basic file format of the target file according to a characteristic byte in the file information. The source file format determining unit is configured to determine a source file format of the target file according to the basic file format and the file content based on the file format inheritance tree.

[0021] In an optional embodiment, the source file format determining unit specifically comprises: The candidate file format determining subunit is configured to determine at least one candidate file format according to the basic file format based on the file format inheritance tree. The source file format determining subunit is configured to determine the source file format of the target file from the at least one candidate file format according to the file content.

[0022] In an optional embodiment, the candidate file format determining subunit is specifically configured to: Obtain a file format inheritance tree. Find a first node corresponding to the basic file format and at least one child node under the first node in the file format inheritance tree, and determine a candidate file format corresponding to the at least one child node.

[0023] In an optional embodiment, the source file format determining subunit is specifically configured to: Determine a format specification corresponding to any candidate file format. In a case where the file content satisfies the format specification, determine the candidate file format as the source file format of the target file.

[0024] In an optional embodiment, the apparatus further comprises a file preview module configured to, in response to a file preview request, detect whether a previewable file format supported by a current application contains the source file format; and in a case where the previewable file format contains the source file format, display the target file in the source file format in the current application.

[0025] In an optional embodiment, the file preview module is further configured to, in a case where the previewable file format does not contain the source file format, obtain a file format inheritance tree, find a second node corresponding to the source file format in the file format inheritance tree, find a parent node on the second node in the file format inheritance tree, determine a compatible file format corresponding to the parent node, and in a case where the previewable file format contains the compatible file format, display the target file in the compatible file format in the current application, or convert the target file from the source file format to the compatible file format, and display the target file in the compatible file format in the current application.

[0026] In an optional implementation, the file preview module is further configured to, in the case that the compatible file format is not included in the previewable file format, convert the target file from the source file format to any of the previewable file format; and display the target file in the current application in any of the previewable file format.

[0027] In an optional implementation, the file format conversion module specifically includes: a path determination sub-module, configured to determine at least one candidate conversion path from the source file format to the target file format; a path screening sub-module, configured to determine a target conversion path from the source file format to the target file format from the at least one candidate conversion path; a file format conversion sub-module, configured to convert the target file from the source file format to the target file format through the target conversion path.

[0028] In an optional implementation, the path determination sub-module specifically includes: a converter set acquisition unit, configured to acquire a converter set, converters in the converter set being configured to convert one file format into another file format and having different file format conversion capabilities; a path determination unit, configured to determine at least one candidate conversion path from the source file format to the target file format by using a recursive traversal method according to the converter set.

[0029] In an optional implementation, the path screening sub-module specifically includes: a cost determination unit, configured to determine a path cost corresponding to any of the candidate conversion paths; a path sorting unit, configured to sort the at least one candidate conversion path according to the path cost to obtain a candidate conversion path sorting sequence; a path screening unit, configured to determine a target conversion path from the source file format to the target file format according to the candidate conversion path sorting sequence.

[0030] In an optional implementation, the cost determination unit is specifically configured to: determine at least one third converter involved in the candidate conversion path, acquire a corresponding historical cost from the third converter; wherein the historical cost is a historical ratio of time spent by the third converter in completing file format conversion and file size after the file format conversion is completed; The path cost corresponding to each of the at least one third converter is summed to obtain the path cost corresponding to the candidate conversion path.

[0031] In an optional implementation, the apparatus further includes: a cost update module, configured to determine the file size of the target file in the target file format, and to determine at least one fourth converter involved in the target conversion path; for any fourth converter, to determine the current ratio between the time spent by the fourth converter to complete the file format conversion and the file size of the target file in the target file format, and to store the current ratio as the current cost in the fourth converter.

[0032] In a third aspect of the embodiments of this application, an electronic device is also provided, 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 through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it implements any of the file format conversion methods described in the first aspect above.

[0033] In a fourth aspect of the embodiments of this application, a storage medium is also provided, wherein the storage medium stores instructions that, when run on a computer, cause the computer to execute any of the file format conversion methods described in the first aspect above.

[0034] In a fifth aspect of the embodiments of this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform any of the file format conversion methods described above.

[0035] The technical solution provided in this application embodiment obtains a target file, determines the source file format of the target file based on the information of the target file, and converts the target file from the source file format to the target file format in response to a file format conversion request.

[0036] By identifying the source file format of the target file through its information, we can ensure successful conversion of the target file format and avoid compromising the efficiency of its use and circulation. Attached Figure Description

[0037] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0038] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0039] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0040] Figure 1 This is a schematic diagram illustrating the implementation process of a file format conversion method in an embodiment of this application; Figure 2 This is a schematic diagram illustrating the implementation process of another file format conversion method shown in the embodiments of this application; Figure 3 This is a schematic diagram illustrating the implementation process of another file format conversion method shown in the embodiments of this application; Figure 4 This is a schematic diagram illustrating the implementation process of another file format conversion method shown in the embodiments of this application; Figure 5 This is a schematic diagram of the structure of a file format conversion device shown in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device shown in an embodiment of this application. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0042] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.

[0043] like Figure 1The diagram shown is a schematic representation of the implementation process of a file format conversion method provided in this application embodiment. This method is applied to electronic devices and may specifically include the following steps: S101, Obtain the target file.

[0044] In this embodiment, a target file is obtained. For the target file, an address pointing to the target file can be obtained, and the target file can be obtained based on that address. The address pointing to the target file can be, for example, a file path or an IP address; this embodiment does not limit this. There is at least one target file, and multiple target files can be obtained simultaneously. In this embodiment, multiple target files can be processed and their file format converted within the same processing event. During the conversion process, the same target file format can be output, or different target file formats can be converted according to the design.

[0045] S102, Determine the source file format of the target file based on the information of the target file.

[0046] In this embodiment, information about the target file is obtained, and the source file format of the target file is determined based on this information. The target file information includes file information (e.g., file header information) and file content. This file information can be all the file information of the target file, or a portion thereof; it can be all or part of the file information of a single target file, or all or part of the file information of multiple target files. Similarly, the file content of the target file can be all the file content of the target file, or a portion thereof; it can be all or part of the file content of a single target file, or all or part of the file content of multiple target files. The file content of a single target file can contain different source file formats or the same source file format. The file content of multiple target files can contain different source file formats or the same source file format.

[0047] S103, in response to the file format conversion request, convert the target file from the source file format to the target file format.

[0048] In this embodiment, after the above steps, the source file format of the target file can be determined. If the user needs to convert the file format, they can set the target file format themselves, thereby determining the target file format. In response to the file format conversion request, the target file is converted from the source file format to the target file format. The user can trigger the file format conversion request by, for example, clicking a format conversion button; this embodiment does not limit this method.

[0049] It should be noted that the target file format refers to the file format after the target file has undergone file format conversion, which can be set by the user or determined by the system. The source file format refers to the current file format of the target file, which is not limited in this embodiment of the application.

[0050] Additionally, for target files, users can select the target file as a whole for format conversion. When there is only one target file, the entire target file is considered as one target file. When there are at least two target files, all target files in the at least two target files are considered as a whole. Users can also select a portion of the target file for format conversion. When there is only one target file, a portion of the target file can be converted. When there are at least two target files, a portion of the target file can be selected for format conversion. For example, users can select the entirety of any number of target files and a portion of the content of any number of other target files for format conversion, or select a portion of the content of any target file for format conversion, or select the entirety of any target file for format conversion.

[0051] Additionally, for the target file, if the user only wants to preview it, then there's no need to specify the target file format. Consequently, no file format conversion will be performed; only a file preview will be available. To do this, the user can trigger a file preview request by clicking a file preview button, and the application will respond to the request by displaying the target file in its original file format within the current application. For details on the target file preview process, please refer to the subsequent section on target file preview procedures.

[0052] Furthermore, users may need to preview the target file before converting its format. To address this, a file preview request is triggered, for example, by clicking a file preview button. In response, the application displays the target file in its source file format. Users can then set the target file format, thus determining its format. A format conversion request can then be triggered, for example, by clicking a format conversion button. In response, the target file is converted from its source file format to the target file format. For details on the target file preview process, please refer to the subsequent section on target file preview procedures.

[0053] Furthermore, users may need to convert the file format before previewing the target file. To address this, users can set the target file format, thus determining the target file's format. Then, by clicking a format conversion button, a file format conversion request is triggered. In response to this request, the target file is converted from its source format to the target format. Finally, by clicking a file preview button, a file preview request is triggered, and the target file is displayed in the target file format within the current application. For details on the target file preview process, please refer to the subsequent section on target file preview procedures.

[0054] It should be noted that the above-mentioned requirements for file preview and file format conversion can be performed separately (e.g., only file preview or file format conversion) or in combination (e.g., file preview first and then file format conversion). The specifics can be adjusted according to user needs, and this application embodiment does not limit this.

[0055] Based on the above description of the technical solutions provided in the embodiments of this application, a target file is obtained, the source file format of the target file is determined according to the information of the target file, and in response to a file format conversion request, the target file is converted from the source file format to the target file format.

[0056] By identifying the source file format of the target file through its information, we can ensure successful conversion of the target file format and avoid compromising the efficiency of its use and circulation.

[0057] like Figure 2 The diagram shown illustrates the implementation flow of another file format conversion method provided in this application embodiment. This method is applied to electronic devices and may specifically include the following steps: S201, obtain the target file, and obtain the file information and file content of the target file.

[0058] In this embodiment, a target file is obtained, along with its file information (e.g., header information) and content. The source file format of the target file can then be determined based on this information and content.

[0059] For the target file, the address pointing to the target file can be obtained, and the target file can be retrieved based on that address. The address pointing to the target file can be, for example, a file path or an IP address; this embodiment of the application does not limit this.

[0060] The file information (such as file header information) of the target file refers to the characteristic bytes written at a specific position in the file (such as the file header), which can generally characterize the file format of the target file; the file content of the target file refers to the specific content in the target file, such as text, images, icons and other specific content.

[0061] S202, Determine the source file format of the target file based on the file information and file content.

[0062] In this embodiment, the source file format of the target file is determined based on file information (e.g., file header information) and file content. This determination of the source file format essentially involves performing two file format matching operations based on the file information (e.g., file header information) and file content to ultimately obtain the source file format of the target file.

[0063] S203, in response to a file format conversion request, converts the target file from the source file format to the target file format.

[0064] In this embodiment of the application, this step is similar to step S103 above, and will not be described in detail here.

[0065] Based on the above description of the technical solutions provided in the embodiments of this application, a target file is obtained, along with its file information and content. The source file format of the target file is determined based on the file information and content. In response to a file format conversion request, the target file is converted from its source file format to its target file format.

[0066] By identifying the source file format of the target file through its file information and content, we can ensure successful conversion of the target file format and avoid compromising the efficiency of its use and circulation.

[0067] In determining the source file format of the target file, a file format match can be performed first based on the characteristic bytes written at a specific position in the file (e.g., the file header). Then, based on the result of the first file format match, a second file format match can be performed based on the file content to finally determine the source file format of the target file.

[0068] Based on this, such as Figure 3 The diagram shown illustrates the implementation flow of another file format conversion method provided in this application embodiment. This method is applied to electronic devices and may specifically include the following steps: S301, obtain the target file, and obtain the characteristic bytes and file content from the file information of the target file.

[0069] In this embodiment of the application, this step is similar to step S201 above, and will not be described in detail here.

[0070] S302, determine the basic file format of the target file based on the characteristic bytes in the file information.

[0071] In this application embodiment, the characteristic bytes written at a specific position in the file information (e.g., file header information) can characterize the file format of the file. Therefore, the basic file format of the target file can be determined based on the characteristic bytes written at a specific position in the file information (e.g., file header information), for example, the basic file format is txt.

[0072] S303, based on the file format inheritance tree, determines the source file format of the target file according to the base file format and file content.

[0073] In this embodiment of the application, the basic file format of the target file can be determined through the above steps. Based on the file format inheritance tree, the source file format of the target file is determined according to the basic file format and the file content. That is, based on the file format inheritance tree, the source file format of the target file is determined according to the file content on the basis of the basic file format.

[0074] Specifically, based on the file format inheritance tree, at least one candidate file format is determined according to the base file format, wherein the base file format is compatible with the candidate file format, and the source file format of the target file is determined from the at least one candidate file format according to the file content.

[0075] A file format inheritance tree is pre-constructed, which can be used to determine at least one candidate file format that is compatible with the base file format. Each node in the file format inheritance tree represents a file format and is backward compatible with other file formats.

[0076] For example, file formats can be abstractly represented using a tree structure, resulting in a file format inheritance tree. In this tree, Markdown files, from largest to smallest, belong to "File," "Binary File," "Text File," and finally, "Markdown File." Since the "Text File" format is the parent node of the "Markdown File" format, the "Text File" format is compatible with the "Markdown File" format.

[0077] Based on this, a file format inheritance tree is obtained. The first node corresponding to the basic file format and at least one child node under the first node are found in the file format inheritance tree. The candidate file format corresponding to at least one child node is determined. The basic file format is compatible with the candidate file format.

[0078] For example, obtain the file format inheritance tree, find the first node corresponding to the "text file" format and at least one child node under the first node in the file format inheritance tree, and determine the candidate file format "Markdown file" corresponding to at least one child node.

[0079] It should be noted that for at least one child node under the first node, it includes the child node immediately adjacent to the first node, and of course it may also include the child node of the child node immediately adjacent to the first node. This application embodiment does not limit this.

[0080] Furthermore, there are specific formatting standards for file formats and their contents. For example, if a target file contains a Manifest.xml file in its unzipped directory, and the content of this file defines the Android mobile application (APK), then the file format can be considered as an APK.

[0081] Based on this, for any candidate file format, the format specification corresponding to the candidate file format is determined; if the file content meets the format specification, the candidate file format is determined as the source file format of the target file.

[0082] It should be noted that performing two file format matching operations based on file information (such as file header information) and file content is because the closer to the root node in the file format inheritance tree, the less accurate the format; the closer to the leaf node, the more accurate the format.

[0083] For example, a JSON file is based on the text format TXT and meets certain specification requirements, so it must belong to the TXT format. However, we should "try our best" to find a more matching format, such as whether the content meets the JSON specification. If it does, then the format can be identified as JSON.

[0084] For example, an APK file is organized according to certain requirements based on a compressed package, so it is primarily a zip file. In the unzipped directory, there is a Manifest.xml file, which contains the definition of an Android mobile application (APK), so the format can be identified as APK.

[0085] S304, in response to a file preview request, checks whether the currently supported previewable file formats include the source file format.

[0086] S305, if the previewable file format includes the source file format, display the target file in the source file format in the current application.

[0087] In this embodiment of the application, the source file format of the target file can be determined through the above steps. If the user has a need for file preview, a file preview request can be triggered by clicking the file preview button, and in response to the file preview request, the application can detect whether the currently supported previewable file formats include the source file format.

[0088] If the current application supports previewable file formats that include the source file format, it means that the target file can be previewed in the current application. In this case, the target file will be previewed directly, that is, displayed in the current application in the source file format.

[0089] Furthermore, if the source file format is not included in the currently supported previewable file formats, it means that the target file cannot be previewed within the current application. However, if it has a parent node format that can be previewed, then a compatible preview (previewing in the parent node format) or a converted preview can be performed.

[0090] Based on this, if the currently supported previewable file formats do not include the source file format, the file format inheritance tree is obtained. The second node corresponding to the source file format is found in the file format inheritance tree, and the parent node of the second node is located to determine the compatible file format corresponding to the parent node. If the previewable file formats include the compatible file format, the target file is displayed in the compatible file format in the current application (without involving file format conversion). Alternatively, the target file is converted from the source file format to the compatible file format, and then displayed in the compatible file format in the current application. For details on converting the target file from the source file format to the compatible file format, please refer to the subsequent file format conversion process.

[0091] For example, if the file format inheritance tree is bin→txt→markdown, then bin is compatible with txt and markdown, and txt is compatible with markdown. Therefore, for a source file in markdown format, the inheritance tree can find compatible formats bin and txt. The application can then display the target file in bin or txt format, or convert the target file from markdown to bin or txt format and display it in bin or txt format.

[0092] It should be noted that when the current application displays the target file in a compatible file format, some features of the source file format will inevitably be lost. For example, if the current application displays a Markdown target file in the bin format, the file content will not be visible; instead, it will be displayed in binary form.

[0093] Therefore, if the user does not meet the requirements for compatible preview, or if the parent node format cannot be previewed, the target file can be converted from the source file format to any previewable file format supported by the current application, and then the file can be previewed.

[0094] Therefore, if the previewable file format does not include a compatible file format, or if the user does not meet the requirements for compatible previews, the target file is converted from the source file format to any previewable file format; the target file is then displayed in the current application in any previewable file format. The file format conversion process can be referred to in subsequent processing.

[0095] Additionally, after previewing the target file, the user can set the target file format. This determines the target file's format, and the user can trigger a file format conversion request by clicking a format conversion button, etc. In response to the file format conversion request, the target file is converted from its source file format to the target file format. Then, the user can trigger a file preview request again by clicking a file preview button, etc., and in response to the file preview request, the target file is displayed in the target file format in the current application. The preview process for the target file can be described in the parameters above.

[0096] S306, in response to a file format conversion request, converts the target file from the source file format to the target file format.

[0097] In this embodiment, after the above steps, the source file format of the target file can be determined. If the user needs to convert the file format, they can set the target file format themselves, thereby determining the target file format. In response to the file format conversion request, the target file is converted from the source file format to the target file format. The user can trigger the file format conversion request by, for example, clicking a format conversion button; this embodiment does not limit this method.

[0098] Specifically, there may be multiple paths for converting a source file format to a target file format. You can choose one of them as the target path and then convert the target file from the source file format to the target file format according to the target path.

[0099] Based on this, such as Figure 4 The diagram shown illustrates the implementation flow of another file format conversion method provided in this application embodiment. This method is applied to electronic devices and may specifically include the following steps: S401, determine at least one candidate conversion path for converting from the source file format to the target file format.

[0100] In this embodiment of the application, at least one candidate conversion path is determined for converting a source file format to a target file format. For example, if the source file format is format A and the target file format is format C, then the at least one candidate conversion path for converting a source file format to a target file format could be, for example, A→C or A→B→C.

[0101] In this embodiment of the application, a converter set can be composed of converters. The converters in the converter set are used to convert one file format to another file format, and the file format conversion capabilities are different.

[0102] Among them, the converter can be, for example, a single-unit converter, which is a commonly used converter that is gradually implemented and supplemented into the converter set. For example, the single-unit converter can be T(features(image)-features(pdf)), where features represents the storage location, image or pdf represents the actual format, and features(image) or features(pdf) is defined as the file format in the embodiments of this application.

[0103] It should be noted that the file formats in the embodiments of the present invention (such as the source file format and target file format mentioned above) are all combinations of the file's storage location and actual format. For example, a PDF file stored on a computer's hard drive can be defined as "local disk (PDF)" or local(pdf), and a PDF file read into the memory of a computer or mobile phone can be defined as "memory (PDF)" or memory(pdf). The embodiments of this application do not limit this.

[0104] In addition, for converters, there can be universal converters such as T(local(markdown)-local(txt)), where markdown files are a more advanced use of txt files, but they can be mutually recognized and opened for viewing.

[0105] Furthermore, for converters, there can be, for example, general business converters: they are general in terms of business capabilities. For example, if the server provides the ability to convert one format to another, the conversion capability formed by calling a specific interface can be considered a general capability because it can achieve conversion between multiple formats. This conversion depends on the additional capabilities of the server.

[0106] For the aforementioned converter set, at least one candidate conversion path for converting the source file format to the target file format can be determined using a recursive traversal method based on the converter set. An example is provided to illustrate the determination of the candidate conversion path, taking a source file format of f1(A) and a target file format of f2(B).

[0107] The "conversion path calculation algorithm" is as follows: Given a converter set DT, a source file format f1(A), a target file format f2(B), and a set of target formats Igf.

[0108] 1. Construct the path set DP.

[0109] 2. Traverse DT. For converter T, if its pre-conversion format is f1(A) and its post-conversion format is not empty, add converter T to set CT.

[0110] 3. Insert f1(A) into Igf.

[0111] 4. Traverse the set CT. For each converter Ti, the converted format is fx(X): 4a. If Igf contains fx(X), iterate through the next one; 4b. If the format after conversion by converter Ti is f2(B), construct path P(Ti) based on converter Ti and add P(Ti) to DP; 4c. Otherwise, use DTi=DT-Ti as the new converter set, source file format fx(X), target file format f2(B), and the set of achieved formats Igf, and execute the "conversion path calculation algorithm" to obtain the converter DPi; 4ci, if DPi is empty, iterate to the next one; 4cii, otherwise construct the path P(Ti) = Ti + DPi, and add P(Ti) to DP; 5. Return to DP.

[0112] S402, determine the target conversion path from at least one candidate conversion path to convert the source file format to the target file format.

[0113] In this embodiment of the application, for at least one candidate conversion path determined in the above steps, a target conversion path for converting the source file format to the target file format is determined from the at least one candidate conversion path.

[0114] Specifically, for any candidate conversion path, the path cost corresponding to the candidate conversion path is determined. At least one candidate conversion path is then sorted according to the path cost (e.g., sorted from smallest to largest) to obtain a candidate conversion path sorting sequence. Based on the candidate conversion path sorting sequence, the target conversion path for converting the source file format to the target file format is determined. The candidate conversion path with the lowest path cost can be determined as the target conversion path.

[0115] In cases where multiple target files or multiple file contents are being format-converted in the same conversion event, at least one candidate conversion path can be output. These candidate conversion paths integrate the branch candidate conversion paths of multiple target files or the branch candidate conversion paths of multiple file contents.

[0116] Specifically, determining the path cost can involve identifying at least one third converter involved in the candidate conversion path and obtaining the corresponding historical cost from the third converter; wherein the historical cost is the historical ratio of the time spent by the third converter to complete the file format conversion to the file size after the file format conversion is completed; the path cost corresponding to each of the at least one third converter is summed to obtain the path cost corresponding to the candidate conversion path.

[0117] It should be noted that the above-mentioned method for calculating historical costs is only one of them, and it can vary depending on the characteristics of the business. For example, bandwidth can also be used as an influencing factor for historical costs. This application does not limit this.

[0118] S403 converts the target file from the source file format to the target file format by using the target conversion path.

[0119] In this embodiment, for the target conversion path determined above, the target file can be converted from the source file format to the target file format via the target conversion path. Furthermore, after converting the target file from the source file format to the target file format via the target conversion path, the file size of the target file in the target file format can be determined, as well as at least one fourth converter involved in the target conversion path. For any fourth converter, the current ratio between the time spent by the fourth converter to complete the file format conversion and the file size of the target file in the target file format is determined, and this current ratio is stored as the current cost in the fourth converter for future path cost calculations.

[0120] It should be noted that the above-mentioned calculation method for the current cost is only one of them, and it can vary depending on the characteristics of the business. For example, bandwidth can also be used as an influencing factor for the current cost. This application does not limit this.

[0121] Thus, this invention significantly increases the likelihood of file previews by accurately judging and ensuring compatibility with file formats, enhancing file preview capabilities. Furthermore, through a converter set, a path from format A to format B can be established. As the number of converters gradually increases, the connection between multiple "paths" leads to a conversion from format A to format C, although a direct conversion from format A to format C is not yet implemented, thus doubling the conversion capability. Moreover, only adding converters is required, reducing coupling and adapting to different devices (each device has different local capabilities; for example, some devices' local conversion is not as good as server-side conversion, so the system can automatically calculate the network conversion path to achieve the best user experience).

[0122] Corresponding to the above method embodiments, this application also provides a file format conversion device, such as... Figure 5 As shown, the device may include: a file acquisition module 510, a format determination module 520, and a file format conversion module 530.

[0123] File acquisition module 510 is used to acquire target files; The format determination module 520 is used to determine the source file format of the target file based on the information of the target file; The file format conversion module 530 is used to convert the target file from the source file format to the target file format in response to a file format conversion request.

[0124] In an optional implementation, the format determination module specifically includes: The information and content acquisition submodule is used to acquire the file information and file content of the target file; The format determination submodule is used to determine the source file format of the target file based on the file information and the file content.

[0125] In one optional implementation, the format determination submodule specifically includes: The basic file format determination unit is used to determine the basic file format of the target file based on the characteristic bytes in the file information; The source file format determination unit is used to determine the source file format of the target file based on the file format inheritance tree, the basic file format, and the file content.

[0126] In an optional implementation, the source file format determination unit specifically includes: The candidate file format determination subunit is used to determine at least one candidate file format based on the file format inheritance tree and the base file format. The source file format determination subunit is used to determine the source file format of the target file from at least one of the candidate file formats based on the file content.

[0127] In an optional implementation, the candidate file format determination subunit is specifically used for: Get the file format inheritance tree; In the file format inheritance tree, find the first node corresponding to the basic file format and at least one child node under the first node, and determine the candidate file format corresponding to at least one child node.

[0128] In one optional implementation, the source file format determination subunit is specifically used for: For any of the candidate file formats, determine the format specification corresponding to the candidate file format; If the file content meets the format specification, the candidate file format is determined as the source file format of the target file.

[0129] In an optional implementation, the apparatus further includes a file preview module, configured to, in response to a file preview request, detect whether the currently supported previewable file formats include the source file format; and if the previewable file formats include the source file format, display the target file in the source file format in the current application.

[0130] In an optional implementation, the file preview module is further configured to, when the previewable file format does not include the source file format, obtain a file format inheritance tree, find the second node corresponding to the source file format in the file format inheritance tree; find the parent node on the second node in the file format inheritance tree, and determine the compatible file format corresponding to the parent node; when the previewable file format includes the compatible file format, display the target file in the current application using the compatible file format; or, convert the target file from the source file format to the compatible file format, and display the target file in the current application using the compatible file format.

[0131] In an optional implementation, the file preview module is further configured to, when the previewable file format does not include the compatible file format, convert the target file from the source file format to any of the previewable file formats; and display the target file in any of the previewable file formats in the current application.

[0132] In an optional implementation, the file format conversion module specifically includes: The path determination submodule is used to determine at least one candidate conversion path from the source file format to the target file format; The path filtering submodule is used to determine, from at least one of the candidate conversion paths, the target conversion path for converting the source file format to the target file format; The file format conversion submodule is used to convert the target file from the source file format to the target file format through the target conversion path.

[0133] In one optional implementation, the path determination submodule specifically includes: A converter set acquisition unit is used to acquire a converter set, wherein the converters in the converter set are used to convert one file format to another file format, and the file format conversion capabilities are different; The path determination unit is used to determine at least one candidate conversion path from the source file format to the target file format by using a recursive traversal method based on the converter set.

[0134] In an optional implementation, the path filtering submodule specifically includes: The cost determination unit is used to determine the path cost corresponding to any of the candidate conversion paths. A path sorting unit is used to sort at least one of the candidate conversion paths according to the path cost to obtain a candidate conversion path sorting sequence. The path filtering unit is used to determine the target conversion path from the source file format to the target file format based on the candidate conversion path sorting sequence.

[0135] In an optional implementation, the cost determination unit is specifically used for: Identify at least one third converter involved in the candidate conversion path, and obtain the corresponding historical cost from the third converter; Wherein, the historical cost is the ratio of the time spent by the third converter to complete the file format conversion to the historical file size after the file format conversion is completed; The path cost corresponding to each of the at least one third converter is summed to obtain the path cost corresponding to the candidate conversion path.

[0136] In an optional implementation, the apparatus further includes: a cost update module, configured to determine the file size of the target file in the target file format, and to determine at least one fourth converter involved in the target conversion path; for any fourth converter, to determine the current ratio between the time spent by the fourth converter to complete the file format conversion and the file size of the target file in the target file format, and to store the current ratio as the current cost in the fourth converter.

[0137] This application also provides an electronic device, such as... Figure 6 As shown, it includes a processor 61, a communication interface 62, a memory 63, and a communication bus 64, wherein the processor 61, the communication interface 62, and the memory 63 communicate with each other through the communication bus 64. Memory 63 is used to store computer programs; When processor 61 executes the program stored in memory 63, it performs the following steps: Obtain the target file; determine the source file format of the target file based on the information of the target file; in response to a file format conversion request, convert the target file from the source file format to the target file format.

[0138] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.

[0139] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0140] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0141] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0142] In another embodiment provided in this application, a storage medium is also provided, which stores instructions that, when run on a computer, cause the computer to execute any of the file format conversion methods described in the above embodiments.

[0143] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform any of the file format conversion methods described in the above embodiments.

[0144] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium or transmitted from one storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0145] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0146] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0147] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A file format conversion method, characterized in that, The method includes: Obtain the target file; Based on the information of the target file, determine the source file format of the target file; In response to a file format conversion request, the target file is converted from the source file format to the target file format.

2. The method according to claim 1, characterized in that, The step of determining the source file format of the target file based on the information of the target file includes: Obtain the file information and file content of the target file; Based on the file information and the file content, determine the source file format of the target file.

3. The method according to claim 2, characterized in that, Determining the source file format of the target file based on the file information and the file content includes: The basic file format of the target file is determined based on the characteristic bytes in the file information; Based on the file format inheritance tree, the source file format of the target file is determined according to the base file format and the file content.

4. The method according to claim 3, characterized in that, The process of determining the source file format of the target file based on the file format inheritance tree, according to the base file format and the file content, includes: Based on the file format inheritance tree, at least one candidate file format is determined according to the basic file format; Based on the file content, the source file format of the target file is determined from at least one of the candidate file formats.

5. The method according to claim 4, characterized in that, The process of determining at least one candidate file format based on the file format inheritance tree and the base file format includes: Get the file format inheritance tree; In the file format inheritance tree, find the first node corresponding to the basic file format and at least one child node under the first node, and determine the candidate file format corresponding to at least one child node.

6. The method according to claim 4, characterized in that, Determining the source file format of the target file from at least one candidate file format based on the file content includes: For any of the candidate file formats, determine the format specification corresponding to the candidate file format; If the file content meets the format specification, the candidate file format is determined as the source file format of the target file.

7. The method according to claim 1 or 2, characterized in that, After determining the source file format of the target file, the process further includes: In response to a file preview request, check whether the currently supported previewable file formats include the source file format; If the previewable file format includes the source file format, the target file is displayed in the source file format in the current application.

8. The method according to claim 7, characterized in that, The method further includes: If the previewable file format does not include the source file format, obtain the file format inheritance tree and find the second node corresponding to the source file format in the file format inheritance tree; Find the parent node of the second node in the file format inheritance tree, and determine the compatible file format corresponding to the parent node; If the previewable file format includes the compatible file format, the target file is displayed in the compatible file format in the current application; Alternatively, the target file can be converted from the source file format to the compatible file format, and the target file can be displayed in the current application in the compatible file format.

9. The method according to claim 8, characterized in that, The method further includes: If the previewable file format does not include the compatible file format, the target file will be converted from the source file format to any of the previewable file formats. The target file is displayed in the current application in any of the aforementioned previewable file formats.

10. The method according to claim 1 or 2, characterized in that, The step of converting the target file from the source file format to the target file format includes: Determine at least one candidate conversion path from the source file format to the target file format; From at least one of the candidate conversion paths, a target conversion path is determined to convert the source file format to the target file format; The target file is converted from the source file format to the target file format via the target conversion path.

11. The method according to claim 10, characterized in that, Determining at least one candidate conversion path from the source file format to the target file format includes: Obtain a set of converters, wherein the converters in the set are used to convert one file format to another file format, and the file format conversion capabilities are different; Based on the converter set, at least one candidate conversion path is determined by recursive traversal to convert the source file format to the target file format.

12. The method according to claim 10, characterized in that, Determining the target conversion path from at least one of the candidate conversion paths for converting the source file format to the target file format includes: For any of the candidate transformation paths, determine the path cost corresponding to the candidate transformation path; According to the path cost, at least one of the candidate conversion paths is sorted to obtain a candidate conversion path sorting sequence; Based on the candidate conversion path sorting sequence, a target conversion path is determined to convert the source file format to the target file format.

13. The method according to claim 12, characterized in that, Determining the path cost corresponding to the candidate transformation path includes: Identify at least one third converter involved in the candidate conversion path, and obtain the corresponding historical cost from the third converter; Wherein, the historical cost is the ratio of the time spent by the third converter to complete the file format conversion to the historical file size after the file format conversion is completed; The path cost corresponding to each of the at least one third converter is summed to obtain the path cost corresponding to the candidate conversion path.

14. The method according to claim 10, characterized in that, After converting the target file from the source file format to the target file format via the target conversion path, the process further includes: Determine the file size of the target file in the target file format, and determine at least one fourth converter involved in the target conversion path; For any fourth converter, determine the current ratio between the time spent by the fourth converter to complete the file format conversion and the file size of the target file in the target file format, and store the current ratio as the current cost in the fourth converter.

15. A file format conversion device, characterized in that, The device includes: The file acquisition module is used to acquire the target file; The format determination module is used to determine the source file format of the target file based on the information of the target file; The file format conversion module is used to convert the target file from the source file format to the target file format in response to a file format conversion request.

16. A storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-14.