An MP4 file processing method, apparatus, electronic device, and storage medium

By inserting basic media information and data block extension information during the MP4 file recording process, the problem of incomplete recording of MP4 file is solved, and the file repair and normal playback are achieved.

CN116189721BActive Publication Date: 2025-06-27BEIJING HEXING HONGTU TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211436641.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-16
Publication Date
2025-06-27
Estimated Expiration
2042-11-16

AI Technical Summary

Technical Problem

MP4 files cannot be played normally when recording is incomplete, and the existing technology lacks effective solutions.

Method used

When recording an MP4 file, insert the media basic information into the starting position of the recording data storage space, and insert the extension information in front of each data block to indicate the length of the data block. In this way, when the file recording is incomplete, the player can use this information to determine the actual file length and data block offset position, thereby repairing the MP4 file.

Benefits of technology

In the case of incomplete recording of MP4 files, the file can be repaired and the normal playback is achieved through the combination of basic media information and extended information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116189721B_ABST
    Figure CN116189721B_ABST
Patent Text Reader

Abstract

The present application provides an MP4 file processing method, apparatus, electronic device, and storage medium. The method includes: when recording an MP4 file, inserting media basic information at the starting position of the mdat box, and inserting extension information before each recorded data block, where the extension information indicates the data block length, so that when the MP4 file is not completely recorded, the player determines the actual file length, determines the offset position of the current data block, and repairs the MP4 file based on the media basic information, the recorded data blocks, and the extension information before the recorded data blocks. The present application solves the problem that an MP4 file cannot be played due to incomplete recording.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of audio and video technologies, and in particular, to an MP4 file processing method, apparatus, electronic device, and storage medium. Background Art

[0002] MP4, also known as MPEG-4 Part 14, is a multimedia container format with the extension.mp4. An MP4 file consists of many boxes, each box containing different information, and these boxes are organized in a tree structure. Figure 1 Brief description of the main boxes of mp4. It can be seen that under the root node, there are mainly three nodes: ftyp: file type, describing the version of the compliance specification; moov box: media metadata information; mdat: storing the actual media data. The moov box includes stsz and stco, where stsz contains the size of the audio and video data blocks, and stco contains the offset of the audio and video data in the file. The player reads the audio and video data according to the information in stsz and stco for decoding and playing.

[0003] When recording an mp4 file, the moov box containing media metadata information is written to the end of the mp4 file only when the audio and video data recording ends. When the storage program crashes unexpectedly due to a bug or the server powers off unexpectedly, etc., it will cause the mp4 file to only record the media data of the mdat box, and the content in the moov box has not had time to be stored in the mp4 file, so such an incomplete file cannot be played.

[0004] Therefore, in view of the situation that the mp4 file cannot be played normally due to incomplete recording of the mp4 file in the prior art, there is currently no good solution. Summary of the Invention

[0005] The purpose of the embodiments of the present application is to provide an MP4 file processing method, apparatus, electronic device, and storage medium to solve the problem that the mp4 file cannot be played normally due to incomplete recording of the mp4 file. The specific technical solutions are as follows:

[0006] In a first aspect, an MP4 file processing method is provided, which is applied to a recorder, and the method includes:

[0007] When recording an MP4 file, insert the media basic information into the starting position of the recording data storage space;

[0008] After each data block is recorded, insert extension information before the data block, where the extension information indicates the data block length.

[0009] So that when the MP4 file recording is incomplete, the player determines the actual file length according to the media basic information, the recorded data blocks, and the extended information before the recorded data blocks, determines the offset position of the current data block, and repairs the MP4 file through the media basic information, the actual file length, the data block length, and the data block offset position.

[0010] Optionally, inserting extended information before the data block includes:

[0011] Inserting the extended information before the data block according to the type of the data block, where the extended information can indicate the type of the data block.

[0012] Optionally, inserting the extended information before the data block according to the type of the data block includes:

[0013] If it is determined according to the extended information that the type of the data block is an audio data block, determine the audio length of the audio data block;

[0014] Deposit audio extended information in front of the audio data block according to a preset audio identifier and the audio length, where the length of the audio extended information is the sum value of the audio identifier and the audio length.

[0015] Optionally, inserting the extended information before the data block according to the type of the data block includes:

[0016] If it is determined according to the extended information that the type of the data block is a video data block, deposit video extended information in front of the video data block according to a preset video identifier, where the length of the video extended information is the length of the video identifier.

[0017] In a second aspect, an MP4 file processing method is provided, which is applied to a player, and the method includes:

[0018] In the case where the MP4 file recording is incomplete, extract media basic information from the starting position of the recording data storage space;

[0019] Determine the data block length of the data block by reading the extended information inserted before each data block, and determine the offset position of the current data block;

[0020] After all the recorded data blocks are read, determine the actual file length according to the sum value of the length of the media basic information, the length of each data block, and the length of each extended information;

[0021] Parse the MP4 file according to the media basic information, the actual file length, the length of each data block, and the offset position of each data block to repair the MP4 file.

[0022] Optionally, determining the data block length of the data block by reading the extended information inserted before each data block includes:

[0023] Read the data identifier in the extended information;

[0024] If it is identified that the data block is an audio data block according to the data identifier, use the n bytes after the data identifier as the audio length of the audio data block, where the n bytes exist in the extended information.

[0025] Optionally, determining the data block length of the data block by reading the extended information inserted before each data block includes:

[0026] Read the data identifier in the extended information;

[0027] If it is identified that the data block is a video data block according to the data identifier, use the m bytes after the data identifier as the video length of the video data block, where the m bytes exist in the data block.

[0028] In a third aspect, there is provided an MP4 file processing apparatus, which is applied to a recorder, and the apparatus includes:

[0029] A first insertion module, configured to insert media basic information into the starting position of the recording data storage space when recording an MP4 file;

[0030] A second insertion module, configured to insert extended information before each data block after each data block is recorded, where the extended information indicates the data block length,

[0031] So that when the MP4 file is incompletely recorded, the player determines the actual file length, determines the offset position of the current data block, and repairs the MP4 file according to the media basic information, the recorded data blocks, and the extended information before the recorded data blocks.

[0032] In a fourth aspect, there is provided an MP4 file processing apparatus, which is applied to a player, and the apparatus includes:

[0033] An extraction module, configured to extract media basic information from the starting position of the recording data storage space when the MP4 file is incompletely recorded;

[0034] A reading module, configured to determine the data block length of the data block by reading the extended information inserted before each data block, and determine the offset position of the current data block;

[0035] A determining module, configured to determine the actual file length according to the sum of the length of the media basic information, the length of each data block, and the length of each extended information after all the recorded data blocks are read;

[0036] An analysis module, configured to analyze the MP4 file according to the media basic information, the actual file length, the length of each data block, and the offset position of each data block, so as to repair the MP4 file.

[0037] In a fifth aspect, an electronic device is provided, including a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus;

[0038] The memory is used to store a computer program;

[0039] The processor is configured to implement the steps of any of the MP4 file processing methods when executing the program stored on the memory.

[0040] In a sixth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the MP4 file processing methods are implemented.

[0041] Advantageous effects of the embodiments of the present application:

[0042] The embodiments of the present application provide an MP4 file processing method. During the recording process, the recorder stores media metadata information and inserts extended information in front of the data block. When the MP4 file cannot be played normally, the player first reads the media metadata information, then obtains the data block length by reading the extended information, determines the data block offset position according to the data block after inserting the extended information, then calculates mdat_length according to the length of the media metadata information, the data block length, and the extended information length, and finally repairs the MP4 file through the media basic information, mdat_length, the data block length, and the data block offset position.

[0043] Of course, it is not necessary for any product or method implementing the present application to achieve all the above advantages at the same time. Description of the Drawings

[0044] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0045] Figure 1 Brief description of the main boxes of mp4 in the prior art;

[0046] Figure 2 Flowchart of a method for processing MP4 files provided by an embodiment of the present application;

[0047] Figure 3 Structural schematic diagram of an MP4 file processing device provided by an embodiment of the present application;

[0048] Figure 4 Structural schematic diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts belong to the scope of protection of the present application.

[0050] In subsequent descriptions, the suffixes such as "module", "component", or "unit" used to represent elements are only for the convenience of description of the present application, and they have no specific meaning in themselves. Therefore, "module" and "component" can be used interchangeably.

[0051] To solve the problems mentioned in the background art, according to one aspect of the embodiments of the present application, an embodiment of a method for processing MP4 files is provided.

[0052] A method for processing MP4 files in the embodiments of the present application can be executed by a recorder or a player, and is used to repair an MP4 file when the MP4 file recording is not completed.

[0053] The following will, in combination with the detailed implementation manners, provide a detailed description of a method for processing MP4 files provided by the embodiments of the present application. As Figure 2 shown, the specific steps are as follows:

[0054] Step 201: When recording an MP4 file, insert the media basic information into the starting position of the recording data storage space.

[0055] When recording an MP4 file, the recorder obtains media metadata information (basic media information) through the DESCRIBE instruction of RSTP (Real Time Streaming Protocol). The media metadata information indicates the data block parameters in mdat, such as audio and video coding formats, video resolution, audio sampling rate, and other parameters. The recorder stores the media metadata information at the starting position of mdat.

[0056] Step 202: After each data block is recorded, insert extension information before the data block. The extension information indicates the data block length, so that when the MP4 file recording is incomplete, the player can determine the actual file length, determine the offset position of the current data block, and repair the MP4 file based on the basic media information, the recorded data blocks, and the extension information before the recorded data blocks.

[0057] If there is no failure during the recording process, under normal circumstances, after each data block is recorded by the recorder, the data block is recorded into the mdat box, and then extension information is inserted before the data block. The extension information indicates the data block length. After the extension information is inserted, the offset position of the data block will change. The recorder determines the offset position of the current data block, records the offset position into the stco box of moov, records the data block length into the stsz box of moov, and obtains mdat_length after all data blocks are recorded and stores it in the mdat header. In this way, the player can directly read the mdat header to obtain the media metadata information and mdat_length, read stco to obtain the offset position, and read stsz to obtain the data block length, so as to decode and play the audio and video data in mdat.

[0058] If an unexpected power outage or recorder damage occurs during the recording process of the recorder, it will cause stsz, stco, the basic media information, and mdat_length not to be stored in the mp4 file in time. At this time, the mp4 file cannot be played normally on the player.

[0059] At this time, the player reads the extension information inserted before each data block, determines the data block length of the data block, records the data block length into the stsz box of moov. After the extension information is inserted, the offset position of the data block will change. The player determines the offset position of the current data block and records the offset position into the stco box of moov.

[0060] After the reading of each recorded data block is completed, the lengths of the media basic information, each data block, and each extended information can be obtained. The player takes the sum of the above lengths as the actual file length mdat_length and stores mdat_length in the header of mdat. At this time, mdat_length only includes the recorded data blocks and the extended information inserted in front of them, and does not include the information of unrecorded data blocks.

[0061] Exemplarily, the media metadata information is 556 bytes in total. Converted to hexadecimal, it is 0x022C. Write the data length 0x022C to the very beginning position of mdat, and write the above 556 bytes of data after 0x022C. Then, a total of 558 bytes of data are written, denoted as the variable mdat_length.

[0062] The audio length is 340 bytes, and the audio extended information is 3 bytes. At this time, the length of the mdat data actually increases by 340 + 3, which is 343 bytes. Update the value of the mdat_length variable to get mdat_length = mdat_length + 343.

[0063] The video length is 17046 bytes, and the video extended information is 1 byte. At this time, the length of the mdat data actually increases by 17046 + 1, which is 17047 bytes. Update the value of the mdat_length variable to get mdat_length = mdat_length + 17047.

[0064] In this way, the player can read the media metadata information and mdat_length from the header of the mdat box, read the stco to obtain the offset position, and read the stsz to obtain the data block length, so as to decode and play the audio and video data in the mdat. Since the original lengths of the audio and video data blocks are stored in stsz and the offset positions are stored in stco, without recording the extended information, the mp4 files recorded in this way can be played using common players.

[0065] The player parses the mdat according to the media basic information, the actual file length, each data block length, and each data block offset position to repair the MP4 file.

[0066] In this application, during the recording process, the recorder stores media metadata information and inserts extension information in front of the data block. When the MP4 file cannot be played normally, the player first reads the media metadata information, then obtains the data block length by reading the extension information, determines the data block offset position according to the data block after inserting the extension information, then calculates mdat_length based on the length of the media metadata information, the data block length, and the length of the extension information, and finally repairs the MP4 file through the media basic information, mdat_length, the data block length, and the data block offset position.

[0067] As an alternative implementation, inserting extension information in front of the data block includes: inserting extension information in front of the data block according to the type of the data block, where the extension information can indicate the type of the data block.

[0068] The player determines whether the data block is an audio data block or a video data block, and thus inserts extension information in front of the data block. The extension information can indicate the type of the data block. However, the extension information includes not only the type of the data block, but also the data block length.

[0069] As an alternative implementation, inserting extension information in front of the data block according to the type of the data block includes two methods:

[0070] The first method: If the player determines that the type of the data block is an audio data block according to the extension information, then determine the audio length of the audio data block, and then store audio extension information in front of the audio data block according to the preset audio identifier and the audio length, where the length of the audio extension information is the sum value of the audio identifier and the audio length.

[0071] For the audio data block, the recorder determines the audio length of the audio data block after receiving the audio data, obtains the preset audio identifier from the server, combines the audio identifier and the audio length together to obtain the audio extension information, and then stores the audio extension information in front of the audio data block. The recorder stores the audio length in stsz and determines the offset position of the audio data block after storing the audio extension information in the current MP4 file and stores it in stco.

[0072] Exemplarily, assume the audio length is 340 bytes, which is converted to hexadecimal as 0x0154. Combine the audio identifier 0x41 and the audio length to get 0x410154, and write these three bytes in sequence to the front of the audio data block. Among them, the first byte is 0x41, indicating the audio data block, and the following two bytes are used to represent the size of the audio data block. Since the audio data occupies less memory, two bytes are sufficient to record the size of the audio data block. Record the position of the audio data block in the current file and record it in stco, and record the audio length 0x0154 in the stsz data.

[0073] The second way: If the player determines that the type of the data block is a video data block according to the extended information, then according to the preset video identifier, deposit the video extended information in front of the video data block, where the length of the video extended information is the length of the video identifier.

[0074] For the video data block, the recorder determines the video length of the video data block after receiving the video data, obtains the preset video identifier from the server, uses the video identifier as the video extended information, and then deposits the video extended information in front of the video data block. The recorder deposits the video length in stsz and determines the offset position of the video data block after depositing the video extended information in the current MP4 file and deposits it in stco.

[0075] Exemplarily, assume the video data block length is 17046 bytes, which is converted to hexadecimal 0x4269. Then the video identifier is the video extended information, and write the video extended information 0x56 in front of the video data block. Record the position of the video data block in the current file and record it in stco, and record the video length 0x4269 in the stsz data.

[0076] This application can be applied to any audio and video recording and playing scenarios. Then the number of bytes occupied by the extended information is also determined according to the actual scenario. The extended information occupies less memory and does not affect the playback of audio and video data.

[0077] Exemplarily, in some scenarios, an mp4 file is usually 30 minutes long. Generally, the set video stream size to be recorded is 3Mbps, which means 3×1024×1024 bits of data are generated per second. To convert it to bytes, divide by 8, that is, 3×1024×1024÷8 = 393216 bytes. 30 minutes is 1800 seconds, so the size of an mp4 file is: 393216×1800 = 707788800 bytes, approximately 700MB.

[0078] The audio data blocks generated in this scenario are usually 40 frames per second. Three bytes are added in front of each audio data block. An MP4 file is 1800 seconds long, so the total increase is 40×3×1800 = 216000 bytes. The video data blocks generated in this scenario are usually 25 frames per second. One byte is added in front of each video data block. An MP4 file is 1800 seconds long, so the total increase is 25×1800 = 45000 bytes. The total number of bytes added for audio and video is 261000 bytes, which is negligible for a 700MB file.

[0079] In addition, the content of audio and video data is stored in mdat, but the data block length and the offset position of the data block in the file are stored in stsz and stco respectively. As long as the information contained in stsz and scto is the data block length and the offset position respectively, the player can accurately read mdat according to the data block length and the offset position and correctly decode and play the MP4 file. Therefore, inserting extended information into the MP4 file has no impact on the player.

[0080] The specific method for determining the audio length and the audio offset position is as follows: For audio data blocks, since the audio extended information is composed of a preset audio identifier and the audio length. Therefore, if the player identifies the data block as an audio data block based on the first n bytes of the extended information, then the remaining bytes of the extended information indicate the audio length of the audio data block. The player determines the position offset of the audio data block by reading the position of the audio data block in the MP4 file.

[0081] Exemplarily, the player determines the data identifier of the first bit of the extended information. If it is the 0x41 identifier, it means it is an audio data block. The player reads the data length of the last two bytes of the extended information, records it in stsz, and obtains the position of the audio data block in the current file and records it in stco.

[0082] The specific method for determining the video length and the video offset position is as follows: For video data blocks, since the video extended information is composed of a preset video identifier. Therefore, if the player identifies the data block as a video data block based on the first n bytes of the extended information, then it reads the first four bytes of the video data block as the video length of the video data block. The player determines the position offset of the video data block by reading the position of the video data block in the MP4 file.

[0083] Exemplarily, the player determines the data identifier of the first bit of the extended information. If it is the 0x56 identifier, it means it is a video data block. The player reads the length of the video data block of the last 4 bytes of the extended information, records it in stsz, and obtains the position of the video data block in the current file and records it in stco.

[0084] This application can further solve the problem of distinguishing audio and video data blocks. By separately processing the extended data of audio and video, different data identifiers are used to distinguish audio and video, and the different bytes after the data identifier respectively represent the lengths of audio and video, distinguishing audio and video from both the data identifier and the data length.

[0085] Based on the same technical concept, an embodiment of this application also provides an MP4 file processing MP4 file processing process, which includes:

[0086] Step 1: When recording an MP4 file, store the length of the media metadata information behind the head of mdat in the MP4 file.

[0087] Step 2: Determine the extended information according to the category of the data block.

[0088] Step 3: Insert the extended information in front of the data block, and the extended length indicates the type and length of the data block.

[0089] Step 4: Determine the offset position of the data block after inserting the extended information;

[0090] Step 5: Determine mdat_length according to the length of the media metadata information, the length of the data block, and the length of the extended information.

[0091] Step 6: Store the data block length and offset position in stsz and stco of moov, and store mdat_length in the head (the first 8 bytes) of mdat.

[0092] Step 7: If the MP4 file recording is not completed, the head of mdat and the content of moov are empty. When opening the MP4 file in binary mode, read the length of the media metadata information (the 9th and 10th bytes of the MP4 file).

[0093] Step 8: Through the length of the media metadata information, read and store the media metadata information in moov.

[0094] Step 9: Read the first few bytes of the extended information to determine the type of the data block.

[0095] Step 10: If it is an audio data block, the remaining bytes of the extended information indicate the audio length of the audio data block. Read the position of the audio data block in the MP4 file to determine the position offset of the audio data block.

[0096] If it is a video data block, determine the video length of the video data block through the first four bytes of the video data block; read the position of the video data block in the MP4 file to determine the position offset of the video data block.

[0097] Step 11: Record the data block length into stsz and record the offset position into stco.

[0098] During the process of reading the extended information and data blocks in Step 12, determine mdat_length and store mdat_length into the header of mdat.

[0099] In Step 13, parse and repair the MP4 file according to mdat_length, the media metadata information in moov, the data block length, and the offset position.

[0100] Based on the same inventive concept, an embodiment of the present application further provides an MP4 file processing apparatus, which is applied to a recorder, as Figure 3 shown. The apparatus includes:

[0101] A first insertion module 301, configured to insert media basic information into the starting position of the mdat box when recording an MP4 file;

[0102] A second insertion module 302, configured to insert extended information before each data block is recorded, where the extended information indicates the data block length,

[0103] so that when the MP4 file recording is incomplete, the player determines the actual file length, determines the offset position of the current data block, and repairs the MP4 file through the media basic information, the actual file length, the data block length, and the data block offset position according to the media basic information, the recorded data blocks, and the extended information before the recorded data blocks.

[0104] Optionally, the second insertion module 302 is configured to:

[0105] Insert extended information before the data block according to the type of the data block, where the extended information can indicate the type of the data block.

[0106] Optionally, the second insertion module 302 is configured to:

[0107] If it is determined according to the extended information that the type of the data block is an audio data block, determine the audio length of the audio data block;

[0108] Store audio extended information in front of the audio data block according to a preset audio identifier and the audio length, where the length of the audio extended information is the sum value of the audio identifier and the audio length.

[0109] Optionally, the second insertion module 302 is configured to:

[0110] If it is determined according to the extended information that the type of the data block is a video data block, video extended information is stored in front of the video data block according to a preset video identifier, where the length of the video extended information is the length of the video identifier.

[0111] Based on the same technical concept, an embodiment of the present application further provides an MP4 file processing apparatus for processing MP4 files, which is applied to a player. The apparatus includes:

[0112] An extraction module, configured to extract media basic information from the starting position of the mdat box in the MP4 file when the MP4 file is incompletely recorded;

[0113] A reading module, configured to determine the data block length of the data block and determine the offset position of the current data block by reading the extended information inserted before each data block;

[0114] A determination module, configured to determine the actual file length according to the sum of the length of the media basic information, the length of each data block, and the length of each extended information after all the recorded data blocks are read;

[0115] An analysis module, configured to analyze mdat according to the media basic information, the actual file length, the length of each data block, and the offset position of each data block to repair the MP4 file.

[0116] Optionally, the reading module is configured to:

[0117] Read the data identifier in the extended information;

[0118] If it is recognized according to the data identifier that the data block is an audio data block, the n bytes after the data identifier are used as the audio length of the audio data block, where the n bytes are in the extended information.

[0119] Optionally, the reading module is configured to: Read the data identifier in the extended information;

[0120] If it is recognized according to the data identifier that the data block is a video data block, the m bytes after the data identifier are used as the video length of the video data block, where the m bytes are in the data block.

[0121] According to another aspect of the embodiment of the present application, the present application provides an electronic device, as Figure 4 shown, including a memory 403, a processor 401, a communication interface 402, and a communication bus 404. A computer program that can run on the processor 401 is stored in the memory 403. The memory 403 and the processor 401 communicate through the communication interface 402 and the communication bus 404. When the processor 401 executes the computer program, the steps of the above method are implemented.

[0122] In the above-mentioned electronic device, the memory and the processor communicate through a communication bus and a communication interface. The communication bus can be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. This communication bus can be divided into an address bus, a data bus, a control bus, and the like.

[0123] The memory can include a Random Access Memory (RAM), or can also include a non-volatile memory, such as at least one disk memory. Optionally, the memory can also be at least one storage device located far from the aforementioned processor.

[0124] The above-mentioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0125] According to another aspect of the embodiments of the present application, there is also provided a computer-readable medium having non-volatile program code executable by a processor.

[0126] Optionally, in the embodiments of the present application, the computer-readable medium is set to store program code for the processor to execute the above method.

[0127] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments, and will not be elaborated herein.

[0128] When the embodiments of the present application are specifically implemented, reference can be made to the above various embodiments, and corresponding technical effects are achieved.

[0129] It can be understood that the embodiments described herein can be implemented by hardware, software, firmware, middleware, microcode, or any combination thereof. For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in this application, or any combination thereof.

[0130] For software implementation, the technologies described herein can be implemented by units that execute the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented within the processor or externally to the processor.

[0131] Those of ordinary skill in the art will appreciate that the units and algorithm steps of the examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, or in a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0132] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.

[0133] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.

[0134] The unit described as a separation component may or may not be physically separated. The component shown as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0135] In addition, in each embodiment of the present application, each functional unit may be integrated into a processing unit, may exist separately as individual physical units, or two or more units may be integrated into one unit.

[0136] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiments of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical discs that can store program codes. It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.

[0137] The above description is only the specific implementation manners of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for processing MP4 files, characterized in that, Applied to a recorder, the method includes: When recording an MP4 file, inserting media basic information at the starting position of the recording data storage space; After each data block is recorded, inserting extended information before the data block, where the extended information indicates the data block length; So that when the MP4 file is incompletely recorded, the player reads the media basic information, obtains the data block length by reading the extended information, determines the data block offset position according to the data block after inserting the extended information, calculates mdat_length based on the length of the media basic information, the data block length, and the length of the extended information, and repairs the MP4 file through the media basic information, the mdat_length, the data block length, and the data block offset position; Among them, inserting extended information before the data block includes: According to the type of the data block, inserting the extended information before the data block, where the extended information can indicate the type of the data block; Among them, according to the type of the data block, inserting the extended information before the data block includes: If it is determined that the type of the data block is an audio data block according to the extended information, determining the audio length of the audio data block; According to a preset audio identifier and the audio length, storing audio extended information in front of the audio data block, where the length of the audio extended information is the sum value of the audio identifier and the audio length; Among them, according to the type of the data block, inserting the extended information before the data block includes: If it is determined that the type of the data block is a video data block according to the extended information, storing video extended information in front of the video data block according to a preset video identifier, where the length of the video extended information is the length of the video identifier.

2. A method for processing MP4 files, characterized in that, Applied to a player, the method includes: In the case where the MP4 file is incompletely recorded, extracting media basic information from the starting position of the recording data storage space; By reading the extended information inserted before each data block, determining the data block length of the data block and determining the offset position of the current data block; After all the recorded data blocks are completely read, determining the actual file length according to the sum value of the length of the media basic information, the length of each data block, and the length of each extended information; Parsing the MP4 file according to the media basic information, the actual file length, each data block length, and each data block offset position to repair the MP4 file; Among them, by reading the extended information inserted before each data block, determining the data block length of the data block includes: Reading the data identifier in the extended information; If it is determined that the data block is an audio data block according to the data identifier, taking the n bytes after the data identifier as the audio length of the audio data block, where the n bytes exist in the extended information; Among them, by reading the extended information inserted before each data block, determining the data block length of the data block includes: Reading the data identifier in the extended information; If it is identified that the data block is a video data block according to the data identifier, then the m bytes after the data identifier are used as the video length of the video data block, where the m bytes exist in the data block.

3. An MP4 file processing device, characterized in that, Applied to a recorder, the device includes: A first insertion module, configured to insert media basic information at the starting position of the recording data storage space when recording an MP4 file; A second insertion module, configured to insert extended information before the data block every time a data block is recorded, where the extended information indicates the data block length, so that when the MP4 file is incompletely recorded, the player reads the media basic information, obtains the data block length by reading the extended information, determines the data block offset position according to the data block after inserting the extended information, calculates mdat_length according to the length of the media basic information, the data block length, and the length of the extended information, and repairs the MP4 file through the media basic information, the mdat_length, the data block length, and the data block offset position; Wherein, the second insertion module is configured to: Insert the extended information before the data block according to the type of the data block, where the extended information can indicate the type of the data block; Wherein, the second insertion module is specifically configured to: If it is determined that the type of the data block is an audio data block according to the extended information, determine the audio length of the audio data block; Deposit audio extended information in front of the audio data block according to a preset audio identifier and the audio length, where the length of the audio extended information is the sum value of the audio identifier and the audio length; Wherein, the second insertion module is specifically configured to: If it is determined that the type of the data block is a video data block according to the extended information, deposit video extended information in front of the video data block according to a preset video identifier, where the length of the video extended information is the length of the video identifier.

4. An MP4 file processing device, characterized in that, Applied to a player, the device includes: An extraction module, configured to extract media basic information from the starting position of the recording data storage space when the MP4 file is incompletely recorded; A reading module, configured to determine the data block length of the data block and determine the offset position of the current data block by reading the extended information inserted before each data block; A determination module, configured to determine the actual file length according to the sum value of the length of the media basic information, the length of each data block, and the length of each extended information after all the recorded data blocks are read; An analysis module, configured to analyze the MP4 file according to the media basic information, the actual file length, each data block length, and each data block offset position to repair the MP4 file; Wherein, the reading module is configured to: Read the data identifier in the extended information; If it is identified that the data block is an audio data block according to the data identifier, then the n bytes after the data identifier are used as the audio length of the audio data block, where the n bytes exist in the extended information; Wherein, the reading module is configured to: Read the data identifier in the extended information; If it is recognized according to the data identifier that the data block is a video data block, then use the m bytes after the data identifier as the video length of the video data block, where the m bytes exist in the data block.

5. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete mutual communication through the communication bus; The memory is used to store computer programs; The processor is configured to implement the method steps described in any one of claims 1 or 2 when executing the program stored on the memory.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the method steps described in any one of claims 1 or 2 are implemented.

Citation Information

Patent Citations

  • An MP4 file processing method and related equipment thereof

    CN109936715A