File repairing method and device, terminal equipment and readable storage medium
By extracting complete audio frames from a damaged MP3 file and creating new tags to generate a repair file, the problem of the inability to repair damaged MP3 files in existing technologies is solved, enabling normal playback of the file.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- AFIRSTSOFT CO LTD
- Filing Date
- 2023-07-24
- Publication Date
- 2026-07-21
AI Technical Summary
Current technology cannot repair damaged MP3 files, rendering them unplayable.
A repair file is generated by extracting all complete audio frames conforming to a preset format from a corrupted MP3 file, creating new header and tail tags.
It has been implemented to repair damaged MP3 files, enabling them to play normally.
Smart Images

Figure CN116778978B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of file restoration technology, and in particular relates to a file restoration method, apparatus, terminal device, and readable storage medium. Background Technology
[0002] MP3 is an audio compression technology, and files stored in MP3 format are called MP3 files. An MP3 file typically includes header tags, audio data, and footer tags. When an MP3 file is corrupted and cannot be played, it's usually because the header or footer tags are damaged, preventing the audio data in the middle from being properly parsed. Currently, related technologies cannot repair corrupted MP3 files to make them playable. Summary of the Invention
[0003] This application provides a method, apparatus, terminal device, and readable storage medium for repairing files, which can solve the problem that related technologies cannot repair damaged MP3 files.
[0004] In a first aspect, embodiments of this application provide a method for repairing files, including:
[0005] Obtain the file to be repaired; the file to be repaired is a corrupted MP3 file.
[0006] Identify all complete audio frames in the file to be repaired that conform to the preset format to obtain a complete audio frame set;
[0007] Create a new header tag based on the tag data in the file to be repaired, and create a new tail tag based on the tag data in the file to be repaired. The tag data is incomplete audio frame data in the file to be repaired.
[0008] A repair file is generated based on the complete audio frame set, a new header tag, and a new tail tag.
[0009] Secondly, embodiments of this application provide a file repair apparatus, comprising:
[0010] The acquisition module is used to acquire the file to be repaired, which is a corrupted MP3 file;
[0011] The determination module is used to identify all complete audio frames in the file to be repaired that conform to a preset format, and obtain a complete set of audio frames.
[0012] A creation module is used to create new header tags and new tail tags based on tag data in the file to be repaired. The tag data is incomplete audio frame data in the file to be repaired.
[0013] The generation module is used to generate a repair file based on the complete audio frame set, a new header tag, and a new tail tag.
[0014] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-mentioned file repair method.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described file repair method.
[0016] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the aforementioned file repair method.
[0017] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment obtains a complete audio frame set by determining all complete audio frames conforming to a preset format in the file to be repaired; and creates new header tags and new tail tags based on the tag data in the file to be repaired. Finally, a repaired file is generated based on the complete audio frame set, the new header tags, and the new tail tags. This application embodiment obtains a repaired file by determining all complete audio frames from a damaged MP3 file, which can repair damaged MP3 files and enable them to play normally. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic diagram illustrating the implementation process of a file repair method provided in an embodiment of this application;
[0020] Figure 2 This is a schematic diagram illustrating the implementation process of obtaining a complete audio frame set provided in an embodiment of this application;
[0021] Figure 3 This is a schematic diagram illustrating the implementation process for determining the length of an audio frame according to an embodiment of this application;
[0022] Figure 4 This is a schematic diagram illustrating the implementation process of creating a new header tag provided in an embodiment of this application;
[0023] Figure 5 This is a schematic diagram illustrating the implementation process of creating a new tail tag provided in an embodiment of this application;
[0024] Figure 6 This is a schematic diagram of the structure of a document repair device provided in an embodiment of this application;
[0025] Figure 7 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are protected by this application.
[0027] It should be noted that the terms "comprising," "including," and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application, are intended to cover non-exclusive inclusion. For example, a process, method, terminal, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. Terms such as "first" and "second" in the claims, specification, and accompanying drawings of this application, as well as relational terms, are used merely to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such immediate relationship or order between these entities / operations / objects.
[0028] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0029] MP3 is an audio compression technology, and files stored in MP3 format are called MP3 files. An MP3 file typically includes header tags, audio data, and footer tags. When an MP3 file is corrupted and cannot be played, it's usually because the header or footer tags are damaged, preventing the audio data in the middle from being properly parsed. Currently, related technologies cannot repair corrupted MP3 files to make them playable.
[0030] In view of this, the embodiments of this application can repair the damaged MP3 file by obtaining all complete audio frames from the damaged MP3 file and obtaining a repair file based on the complete audio frames, new header tags, and new tail tags, so that the damaged MP3 file can be played normally.
[0031] To illustrate the technical solution of this application, specific embodiments are described below.
[0032] Figure 1 This illustration shows a flowchart of a file repair method provided in an embodiment of this application. This method can be applied to terminal devices. Terminal devices can be mobile phones, tablets, laptops, ultra-mobile personal computers (UMPCs), netbooks, etc.
[0033] Specifically, the repair method for the above-mentioned file may include the following steps S101 to S104.
[0034] Step S101: Obtain the file to be repaired.
[0035] The file to be repaired is a corrupted MP3 file. MP3 file corruption is usually caused by damage to the header or footer tag data of the MP3 file.
[0036] In the embodiments of this application, the terminal device can directly obtain the file to be repaired input by the user, or it can directly retrieve the file to be repaired stored in the memory. The embodiments of this application do not limit the method of obtaining the file to be repaired.
[0037] Step S102: Determine all complete audio frames in the file to be repaired that conform to the preset format, and obtain a complete audio frame set.
[0038] Among them, a complete audio frame is a single, complete audio frame, and a complete audio frame set is a collection of all complete audio frames in the file to be repaired that conform to a preset format.
[0039] In the embodiments of this application, the terminal device can extract bytes from the file to be repaired, and then determine whether the extracted bytes conform to a preset format. If they conform to the preset format, complete audio frames can be further determined. After obtaining all complete audio frames in the file to be repaired, all complete audio frames are combined into a complete audio frame set.
[0040] Step S103: Create a new header label based on the label data in the file to be repaired, and create a new tail label based on the label data in the file to be repaired.
[0041] The tag data consists of incomplete audio frame data from the file to be repaired. The header tag (ID3V2) is the tag information recorded at the beginning of the MP3 file. The tag length is variable, typically consisting of a tag header and several tag frames or an extended tag header, with at least one tag frame. Each tag frame records one type of information, such as title length, title, author name length, author name, album name length, and album name. The footer tag (ID3V1) is the tag information recorded at the end of the MP3 file, with a length of 128 bytes, typically recording information such as song title, author name, and album name.
[0042] In the embodiments of this application, since MP3 file corruption is usually caused by the corruption of the header tag data or the tail tag data of the MP3 file, new header tags and new tail tags can be created to replace the corrupt header tags or tail tags for the corrupted MP3 file.
[0043] Step S104: Generate a repair file based on the complete audio frame set, the new head tag, and the new tail tag.
[0044] In the embodiments of this application, after obtaining the complete audio frame set, the new header tag, and the new tail tag, the terminal device can create a new MP3 file and write the new header tag, the complete audio frame set, and the new tail tag into the new MP3 file in sequence, thereby obtaining the repaired file.
[0045] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment obtains a complete audio frame set by determining all complete audio frames conforming to a preset format in the file to be repaired; and creates new header tags and new tail tags based on the tag data in the file to be repaired. Finally, a repaired file is generated based on the complete audio frame set, the new header tags, and the new tail tags. This application embodiment obtains a repaired file by determining all complete audio frames from a damaged MP3 file, which can repair damaged MP3 files and enable them to play normally.
[0046] like Figure 2As shown, in some embodiments of this application, the above-mentioned determination of all complete audio frames conforming to a preset format in the file to be repaired to obtain a complete audio frame set may specifically include the following steps:
[0047] In step S201, the frame header is determined by reading bytes of a preset length from the file to be repaired and determining the frame header of an audio frame that conforms to a preset format based on the bytes of the preset length.
[0048] In MP3 files, the header of an audio frame is usually in a fixed format. Therefore, the format corresponding to the header of an audio frame can be set to a preset format to find the header of the audio frame.
[0049] In the embodiments of this application, the terminal device can scan the byte content of the file to be repaired in binary mode, and read bytes of a preset length sequentially starting from the beginning of the file to be repaired, and determine whether the bytes of the preset length read conform to the preset format. If so, the bytes of the preset length are the frame header of an audio frame; if not, the next segment of bytes of the preset length is read and judged, until the bytes of the preset length read conform to the preset format.
[0050] In some specific embodiments of this application, the above-mentioned preset length is four bytes, and the above-mentioned preset format is as follows: the value of the first byte is 0xFF; the first three bits of the high-order part of the second byte are all 1, and the fifth bit is not 1 when the fourth bit of the high-order part is 0; the first four bits of the high-order part of the third byte are not all 0 or not all 1, and the fifth and sixth bits of the high-order part are not both 1.
[0051] When the four bytes read meet the above preset format, it can be determined that the four bytes read are the frame header of an audio frame.
[0052] In step S202, the length of an audio frame is determined by parsing the header of an audio frame.
[0053] In the embodiments of this application, the frame header of the audio frame contains a lot of information, such as version, layer, number of samples, bit rate, sampling rate, padding size, etc., and the terminal device can determine the length of the audio frame based on this information.
[0054] like Figure 3 As shown, in some specific embodiments of this application, the above-mentioned parsing of the frame header of an audio frame to determine the length of an audio frame may specifically include the following steps:
[0055] Step S301: Parse the frame header of an audio frame and determine the version, layer, number of samples, bit rate, sampling rate, and padding size based on the bytes in the frame header.
[0056] In the embodiments of this application, the terminal device can parse the frame header of an audio frame. Specifically, the 4th and 5th bits of the high-order bytes of the second byte of the frame header can represent the version, where a value of 3 indicates version 1, a value of 2 indicates version 2, and a value of 0 indicates version 2.5. The 6th and 7th bits of the high-order bytes of the second byte of the frame header represent the layer, where a value of 1 indicates layer 3, a value of 2 indicates layer 2, and a value of 3 indicates layer 1. After obtaining the version and layer, the terminal device can determine the number of samples for the frame based on the correspondence between the version, layer, and number of samples. For example, when the version is 1 and the layer is 1, the corresponding number of samples is 384. The 1st and 4th bits of the high-order bytes of the third byte of the frame header can determine the bit rate of the frame, where the bit rate refers to the number of bits transmitted per second. A higher bit rate means more data is transmitted. The 5th and 6th bits of the high-order bytes can determine the sampling rate of the frame, where the sampling rate defines the number of samples extracted from the continuous signal and used to assemble the discrete signal per second. The 7th bit of the high-order bytes can represent the padding size of the frame.
[0057] Step S302: Determine the length of an audio frame based on version, layer, number of samples, bit rate, sampling rate, and padding size.
[0058] In the embodiments of this application, after obtaining the above information, the length of the corresponding audio frame can be determined using a calculation formula. The specific calculation formula is as follows:
[0059] Frame length = number of samples × bit rate of audio frame ÷ sampling rate ÷ 8 + padding size of audio frame.
[0060] Step S203: Determine a complete audio frame based on the frame header and length of an audio frame.
[0061] In the embodiments of this application, after obtaining the frame header and length of an audio frame, the terminal device can read data from the file to be repaired backwards to obtain a complete audio frame.
[0062] In some specific embodiments of this application, the terminal device can read the length of an audio frame backward from the last byte of the frame header in the file to be repaired, thereby obtaining a complete audio frame.
[0063] Repeat step S204, repeating the steps of determining the frame header, determining the audio frame length, and determining the complete audio frame, until all complete audio frames in the file to be repaired that conform to the preset format are determined, thus obtaining a complete audio frame set.
[0064] In the embodiments of this application, the file to be repaired contains many complete audio frames, so it is necessary to extract all of these complete audio frames. After the terminal device executes the above steps S201 to S203 to obtain the first complete audio frame of the file to be repaired, the terminal device can repeat the above steps S201 to S203 to obtain the remaining complete audio frames in the file to be repaired that conform to the preset format, thereby obtaining all complete audio frames in the file to be repaired that conform to the preset format, thus obtaining a complete audio frame set.
[0065] like Figure 4 As shown, in some embodiments of this application, the creation of a new header tag based on the tag data in the file to be repaired may specifically include steps S401 to S404:
[0066] Step S401: Obtain tag data from the file to be repaired.
[0067] In the embodiments of this application, after obtaining all complete audio frames, the data in the file to be repaired other than the complete audio frames is the tag data, and the terminal device can read this tag data in the file to be repaired.
[0068] Step S402: Locate the first preset byte in the tag data.
[0069] The first preset byte is used to determine the header tag information, which includes one or more of the following: title length, title, author name length, author name, album name length, and album name.
[0070] In the embodiments of this application, the terminal device can search for a first preset byte in the tag data. The first preset byte is pre-set and can be multiple different bytes. Specifically, the first preset byte can be "TIT2", "TPE1", "TALB", etc.
[0071] Step S403: If the first preset byte is found, extract the header tag information from the tag data.
[0072] In the embodiments of this application, if the first preset byte is found, the terminal device can extract one or more of the following information from the tag data: title length, title, author name length, author name, album name length, and album name.
[0073] Specifically, if the first preset byte containing "TIT2" is found, the next two bytes represent the length of the title in the header tag. The bytes following the title length are the title in the header tag. If the first preset byte containing "TPE1" is found, the next two bytes represent the length of the author name in the header tag. The bytes following the author name length are the author name in the header tag. If the first preset byte containing "TPE1" is found, the next two bytes represent the length of the album name in the header tag. The bytes following the album name length are the album name in the header tag.
[0074] Step S404: Create a new header label and assign a value to the new header label based on the header label information extracted from the label data.
[0075] In the embodiments of this application, the terminal device can create a new header tag and set the first 3 bytes of the new header tag to a fixed value "ID3"; the 4th byte represents the version number, assigned a value of 0x04; the 5th byte represents the minor version number, assigned a value of 0; the 6th byte represents the flag bit, assigned a value of 0; bytes 11 to 14 are fixed values "TIT2"; bytes 15 to 16 represent the title length X. If the title length in the header tag is found in step S403, then X is assigned the found value; otherwise, X is assigned a value of 6; bytes 17 to 16+X represent the title. If the title in the header tag is found in step S403, then the title is assigned the found value; otherwise, it is assigned a value of "unknown"; bytes 17+X to 20+X are fixed values "TPE1"; bytes 21+X to 22+X represent the author name length Y. If the header tag is found in step S403, then the title is assigned the found value; otherwise, it is assigned a value of "unknown"; bytes 17+X to 20+X are fixed values "TPE1"; bytes 21+X to 22+X represent the author name length Y. If the author's name in the header tag is found in step S403, then Y is assigned the found value; otherwise, Y is assigned the value 6. Bytes 23+X to 22+X+Y represent the author's name. If the author's name in the header tag is found in step S403, then the author's name is assigned the found value; otherwise, the author's name is assigned the value "unknown". Bytes 23+X+Y to 26+X+Y are fixed values "TALB". Bytes 27+X+Y to 28+X+Y represent the album name length Z. If the album name length in the header tag is found in step S403, then Z is assigned the found value; otherwise, Z is assigned the value 6. Bytes 29+X+Y to 28+X+Y+Z represent the album name. If the album name in the header tag is found in step S403, then the album name is assigned the found value; otherwise, the album name is assigned the value "unknown". Finally, bytes 7 to 10 represent the tag length and are assigned the value 28+X+Y+Z.
[0076] like Figure 5As shown, in some embodiments of this application, the creation of a new tail tag based on the tag data in the file to be repaired may specifically include steps S501 to S504:
[0077] Step S501: Obtain tag data from the file to be repaired.
[0078] In the embodiments of this application, after obtaining all complete audio frames, the data in the file to be repaired other than the complete audio frames is the tag data, and the terminal device can read this tag data in the file to be repaired.
[0079] Step S502: Search for the second preset byte in the tag data.
[0080] The second preset byte is used to determine the tail tag information, which includes one or more of the following: song title, author name, and album name.
[0081] In an embodiment of this application, the terminal device can search for a second preset byte in the tag data. The second preset byte is pre-set. Specifically, the second preset byte can be "TAG".
[0082] Step S503: If the second preset byte is found, extract the tail tag information from the tag data.
[0083] In the embodiments of this application, if a second preset byte is found, the terminal device can extract one or more pieces of information from the tag data, such as song title, author name, and album name.
[0084] Specifically, if the second preset byte containing "TAG" is found, the next 30 bytes represent the song title in the tail tag, the next 30 bytes represent the author's name in the tail tag, and the next 30 bytes represent the album name in the tail tag.
[0085] Step S504: Create a new tail label and assign a value to the new tail label based on the tail label information extracted from the label data.
[0086] In the embodiments of this application, the terminal device can create a new tail tag and set the first 3 bytes to the fixed value "TAG"; bytes 4 to 33 represent the song title. If the song title is found in the tail tag in step S503, the song title is assigned the found value; otherwise, the song title is assigned "unknown"; bytes 34 to 63 represent the author name. If the author name is found in the tail tag in step S503, the author name is assigned the found value; otherwise, the author name is assigned "unknown"; bytes 64 to 93 represent the album name. If the album name is found in the tail tag in step S503, the album name is assigned the found value; otherwise, the album name is assigned "unknown"; the remaining bytes can all be assigned the value 0.
[0087] Figure 6 This illustration shows a structural diagram of a file repair device according to an embodiment of this application. The file repair device 6 can be configured on a terminal device. Specifically, the file repair device 6 may include:
[0088] The acquisition module 601 is used to acquire the file to be repaired, which is a corrupted MP3 file;
[0089] The determination module 602 is used to determine all complete audio frames in the file to be repaired that conform to a preset format, and obtain a complete audio frame set.
[0090] Module 603 is used to create a new header tag based on the tag data in the file to be repaired, and to create a new tail tag based on the tag data in the file to be repaired. The tag data is incomplete audio frame data in the file to be repaired.
[0091] Generation module 604 is used to generate a repair file based on the complete audio frame set, a new head tag, and a new tail tag.
[0092] The beneficial effects of this application embodiment compared with the prior art are as follows: This application embodiment obtains a complete audio frame set by determining all complete audio frames conforming to a preset format in the file to be repaired; and creates new header tags and new tail tags based on the tag data in the file to be repaired. Finally, a repaired file is generated based on the complete audio frame set, the new header tags, and the new tail tags. This application embodiment obtains a repaired file by determining all complete audio frames from a damaged MP3 file, which can repair damaged MP3 files and enable them to play normally.
[0093] In some embodiments of this application, the determining module 602 is further configured to perform the following steps: determining the frame header step: reading bytes of a preset length in the file to be repaired, and determining the frame header of an audio frame of a preset format based on the bytes of the preset length; determining the audio frame length step: parsing the frame header of an audio frame to determine the length of the audio frame; determining the complete audio frame step: determining a complete audio frame based on the frame header and the length of the audio frame; repeating the above steps of determining the frame header, determining the audio frame length, and determining the complete audio frame, until all complete audio frames conforming to the preset format in the file to be repaired are determined, thereby obtaining a complete audio frame set.
[0094] In some embodiments of this application, the preset length is four bytes, and the preset format is as follows: the first byte has a value of 0xFF; the first three high-order bits of the second byte are all 1, and the fifth bit is not 1 when the fourth high-order bit is 0; the first four high-order bits of the third byte are not all 0 or not all 1, and the fifth and sixth high-order bits are not both 1.
[0095] In some embodiments of this application, the determining module 602 is further configured to: parse the frame header of an audio frame, and determine the version, layer, number of samples, bit rate, sampling rate, and padding size based on the bytes of the frame header; and determine the length of an audio frame based on the version, layer, number of samples, bit rate, sampling rate, and padding size.
[0096] In some embodiments of this application, the determining module 602 is further configured to: read the length of an audio frame backward from the last byte of the frame header in the file to be repaired, and obtain a complete audio frame.
[0097] In some embodiments of this application, the creation module 603 is further configured to: obtain tag data from the file to be repaired; search for a first preset byte in the tag data, the first preset byte being used to determine header tag information, the header tag information including one or more of title length, title, author name length, author name, album name length, and album name; if the first preset byte is found, extract the header tag information from the tag data; create a new header tag, and assign a value to the new header tag based on the header tag information extracted from the tag data.
[0098] In some embodiments of this application, the creation module 603 is further configured to: obtain tag data from the file to be repaired; search for a second preset byte in the tag data, the second preset byte being used to determine tail tag information, the tail tag information including one or more of song title, author name, and album name; if the second preset byte is found, extract the tail tag information from the tag data; create a new tail tag, and assign a value to the new tail tag based on the tail tag information extracted from the tag data.
[0099] like Figure 7 The diagram shown is a schematic of a terminal device provided in an embodiment of this application. The terminal device 7 may include: a processor 701, a memory 702, and a computer program 703 stored in the memory 702 and executable on the processor 701, such as a file repair program. When the processor 701 executes the computer program 703, it implements the steps in the aforementioned file repair method embodiments, for example... Figure 1 Steps S101 to S104 are shown. Alternatively, when the processor 701 executes the computer program 703, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 6 The module shown is the acquisition module 601, the determination module 602, the creation module 603, and the generation module 604.
[0100] The computer program can be divided into one or more modules / units, which are stored in the memory 702 and executed by the processor 701 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the terminal device.
[0101] The terminal device may include, but is not limited to, a processor 701 and a memory 702. Those skilled in the art will understand that... Figure 7 This is merely an example of a terminal device and does not constitute a limitation on the terminal device. It may include more or fewer components than shown, or combine certain components, or different components. For example, the terminal device may also include input / output devices, network access devices, buses, etc.
[0102] The processor 701 may be a Central Processing Unit (CPU), or other general-purpose processors, 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, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0103] The memory 702 can be an internal storage unit of the terminal device, such as a hard drive or memory. The memory 702 can also be an external storage device of the terminal device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 702 can include both internal and external storage units. The memory 702 is used to store the computer program and other programs and data required by the terminal device. The memory 702 can also be used to temporarily store data that has been output or will be output.
[0104] It should be noted that, for the sake of convenience and brevity, the structure of the terminal device described above can also be referred to the specific description of the structure in the method embodiment, which will not be repeated here.
[0105] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0106] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps in the above-described file repair method.
[0107] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps in the above-mentioned file repair method.
[0108] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0109] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for various specific applications, but such implementations should not be considered beyond the scope of this application.
[0110] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0111] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0112] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0113] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0114] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for repairing files, characterized in that, Includes the following steps: Obtain the file to be repaired, which is a corrupted MP3 file; Identify all complete audio frames in the file to be repaired that conform to a preset format to obtain a complete audio frame set; A new header tag is created based on the tag data in the file to be repaired, and a new tail tag is created based on the tag data in the file to be repaired, wherein the tag data is incomplete audio frame data in the file to be repaired; A repair file is generated based on the complete audio frame set, the new header tag, and the new tail tag; The step of creating new header tags based on the tag data in the file to be repaired includes: Obtain the tag data from the file to be repaired; The first preset byte is searched in the tag data. The first preset byte is used to determine the header tag information. The header tag information includes one or more of the following: title length, title, author name length, author name, album name length, and album name. If the first preset byte is found, the header tag information is extracted from the tag data; The new header tag is created, and based on the header tag information extracted from the tag data, the new header tag is assigned a value. Specifically, a new header tag is created, and the first 3 bytes of the new header tag are set to the fixed value "ID3"; the 4th byte represents the version number and is assigned the value 0x04; the 5th byte represents the minor version number and is assigned the value 0; the 6th byte represents the flag bit and is assigned the value 0; bytes 11 to 14 are the fixed value "TIT2"; bytes 15 to 16 represent the title length X. If the title length in the header tag is found in step S403, X is assigned the found value; otherwise, X is assigned the value 6; bytes 17 to 16+X represent the title. If the title in the header tag is found in step S403, the title is assigned the found value; otherwise, it is assigned "unknown"; bytes 17+X to 20+X are the fixed value "TPE1"; bytes 21+X to 22+X represent the author. The length of the album name is Y. If the length of the author name in the header tag is found in step S403, then Y is assigned the found value; otherwise, Y is assigned the value 6. Bytes 23+X to 22+X+Y represent the author name. If the author name in the header tag is found in step S403, then the author name is assigned the found value; otherwise, the author name is assigned the value "unknown". Bytes 23+X+Y to 26+X+Y are fixed values "TALB". Bytes 27+X+Y to 28+X+Y represent the album name length Z. If the length of the album name in the header tag is found in step S403, then Z is assigned the found value; otherwise, Z is assigned the value 6. Bytes 29+X+Y to 28+X+Y+Z represent the album name. If the album name in the header tag is found in step S403, then the album name is assigned the found value; otherwise, the album name is assigned the value "unknown". Finally, bytes 7 to 10 represent the tag length and are assigned the value 28+X+Y+Z.
2. The file repair method as described in claim 1, characterized in that, The process of determining all complete audio frames in the file to be repaired that conform to a preset format, resulting in a complete audio frame set, includes: The frame header determination step is as follows: Read bytes of a preset length from the file to be repaired, and determine the frame header of an audio frame that conforms to the preset format based on the bytes of the preset length; The steps for determining the length of an audio frame are as follows: the frame header of the audio frame is parsed to determine the length of the audio frame. Steps for determining a complete audio frame: Determine a complete audio frame based on the frame header and the length of the audio frame. Repeat the steps: Repeat the steps of determining the frame header, determining the audio frame length, and determining the complete audio frame until all complete audio frames in the file to be repaired that conform to the preset format are determined, thus obtaining the complete audio frame set.
3. The file repair method as described in claim 2, characterized in that, The preset length is four bytes, and the preset format is: The first byte has a value of 0xFF; The first three high-order bits of the second byte are all 1, and the fifth bit is not 1 when the fourth high-order bit is 0; The first four high-order bits of the third byte are not all 0 or not all 1, and the fifth and sixth high-order bits are not both 1 at the same time.
4. The file repair method as described in claim 2, characterized in that, The step of parsing the header of the audio frame to determine the length of the audio frame includes: The header of the audio frame is parsed, and the version, layer, number of samples, bit rate, sampling rate, and padding size are determined based on the bytes in the header. The length of an audio frame is determined based on the version, the layer, the number of samples, the bit rate, the sampling rate, and the padding size.
5. The file repair method as described in claim 2, characterized in that, Determining a complete audio frame based on the frame header and length of the audio frame includes: At the last byte of the frame header in the file to be repaired, the length of the audio frame is read backward to obtain the complete audio frame.
6. The file repair method as described in claim 1, characterized in that, The step of creating a new tail tag based on the tag data in the file to be repaired includes: Obtain the tag data from the file to be repaired; The second preset byte is searched in the tag data. The second preset byte is used to determine the tail tag information, which includes one or more of the following: song title, author name, and album name. If the second preset byte is found, the tail tag information is extracted from the tag data; The new tail tag is created, and a value is assigned to the new tail tag based on the tail tag information extracted from the tag data.
7. A document repair device, characterized in that, include: The acquisition module is used to acquire the file to be repaired, which is a damaged MP3 file; The determination module is used to determine all complete audio frames in the file to be repaired that conform to a preset format, thereby obtaining a complete audio frame set. A creation module is used to create a new header tag based on the tag data in the file to be repaired, and to create a new tail tag based on the tag data in the file to be repaired, wherein the tag data is incomplete audio frame data in the file to be repaired; The generation module is used to generate a repair file based on the complete audio frame set, the new header tag, and the new tail tag; The step of creating new header tags based on the tag data in the file to be repaired includes: Obtain the tag data from the file to be repaired; The first preset byte is searched in the tag data. The first preset byte is used to determine the header tag information. The header tag information includes one or more of the following: title length, title, author name length, author name, album name length, and album name. If the first preset byte is found, the header tag information is extracted from the tag data; The new header tag is created, and based on the header tag information extracted from the tag data, the new header tag is assigned a value. Specifically, a new header tag is created, and the first 3 bytes of the new header tag are set to the fixed value "ID3"; the 4th byte represents the version number and is assigned the value 0x04; the 5th byte represents the minor version number and is assigned the value 0; the 6th byte represents the flag bit and is assigned the value 0; bytes 11 to 14 are the fixed value "TIT2"; bytes 15 to 16 represent the title length X. If the title length in the header tag is found in step S403, X is assigned the found value; otherwise, X is assigned the value 6; bytes 17 to 16+X represent the title. If the title in the header tag is found in step S403, the title is assigned the found value; otherwise, it is assigned "unknown"; bytes 17+X to 20+X are the fixed value "TPE1"; bytes 21+X to 22+X represent the author. The length of the album name is Y. If the length of the author name in the header tag is found in step S403, then Y is assigned the found value; otherwise, Y is assigned the value 6. Bytes 23+X to 22+X+Y represent the author name. If the author name in the header tag is found in step S403, then the author name is assigned the found value; otherwise, the author name is assigned the value "unknown". Bytes 23+X+Y to 26+X+Y are fixed values "TALB". Bytes 27+X+Y to 28+X+Y represent the album name length Z. If the length of the album name in the header tag is found in step S403, then Z is assigned the found value; otherwise, Z is assigned the value 6. Bytes 29+X+Y to 28+X+Y+Z represent the album name. If the album name in the header tag is found in step S403, then the album name is assigned the found value; otherwise, the album name is assigned the value "unknown". Finally, bytes 7 to 10 represent the tag length and are assigned the value 28+X+Y+Z.
8. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the file repair method as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the file repair method as described in any one of claims 1 to 6.