MP4 file recording and repairing method and electronic equipment

By generating temporary moov files in the video recording device and using these files to repair MP4 files damaged due to abnormal termination, the problem that MP4 files cannot be played normally due to abnormal termination of recording is solved, and the repair effect and efficiency are improved.

CN120050379AActive Publication Date: 2025-05-27AXERA SEMICON (SHANGHAI) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510115264.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-05-27
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

When the recording process is abnormally terminated due to abnormal situations such as system stuck, power outage, power exhaustion or equipment damage, the MP4 file information is incompletely saved and cannot be played normally. The existing repair software has poor repair effect and low efficiency.

Method used

Generate temporary moov files during recording, and use these temporary moov files to repair MP4 files that cannot be played normally due to the abnormal end of recording, and ensure the integrity of the file by generating and writing to the moov box.

Benefits of technology

It improves the repair effect and efficiency of MP4 files, ensures that the repaired files can be played normally, and avoids problems such as out-of-synchronization of audio and video and stuttering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120050379A_ABST
    Figure CN120050379A_ABST
Patent Text Reader

Abstract

The invention provides an MP4 file recording and repairing method and electronic equipment, and the MP4 file recording method comprises the steps: generating an MP4 file and a data index file based on audio and video coding data, generating a first number of sample frames, sequentially writing the sample frames into a data block, and when the memory of the data block reaches a preset memory threshold value, recording the MP4 file according to the first number of sample frames; adding the data block to the end of the media data area; metadata parameters in the data index file are updated, and a temporary moov file is generated based on the media data area; writing the remaining sample frames into a new data block until the first number of sample frames are all written into the data block, and generating a plurality of temporary moov files; obtaining a normal recording ending identifier, generating a moov box, and writing the moov box into the MP4 file; and setting the file state identifier as a complete state, and updating the length of the media data. According to the method, the temporary moov file can be generated in the recording process, so that the MP4 file generated due to accidental interruption of recording is repaired by using the temporary moov file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of video repair technology, and particularly to a method for recording and repairing MP4 files and an electronic device. Background Art

[0002] Recording videos is the main function of video recording devices such as cameras, action cameras, and dash cams. Video recording devices encapsulate videos into media files according to multimedia encapsulation formats. Among them, the MP4 format is a commonly used video encapsulation format. MP4 files generated in the MP4 format can store the data streams and metadata of audio and video, and can be used and played across multiple platforms.

[0003] During the real-time recording process of video recording devices, the devices may encounter abnormal situations such as system freezes, power outages, battery depletion, or device damage, resulting in abnormal termination of the recording process. As a result, the MP4 file information is not saved completely, making the MP4 file unable to play normally due to lack of data information.

[0004] Using repair software to repair damaged MP4 files can recover some simple damage situations, but the repaired MP4 files will have problems such as audio-video out-of-sync and video stuttering during playback, resulting in poor repair effect and low efficiency of MP4 files. Summary of the Invention

[0005] This application provides a method for recording and repairing MP4 files and an electronic device. By generating a temporary moov file during the recording process and using the temporary moov file to repair the MP4 file generated due to accidental interruption of the recording, the repair effect and efficiency of the MP4 file are improved.

[0006] In a first aspect, this application provides a method for recording an MP4 file, including:

[0007] Generating an MP4 file and a data index file based on audio-video coding data. The MP4 file includes a file header and a media data area. The file header includes a file status flag and a media data length. The initial state of the file status flag is an incomplete state. The data index file is used to save metadata parameters.

[0008] Generating a first number of sample frames based on the audio-video coding data, and sequentially writing the sample frames into data blocks. When the memory of the data block reaches a preset memory threshold, adding the data block to the end of the media data area.

[0009] Updating the metadata parameters in the data index file, and generating a temporary moov file based on the media data area.

[0010] Write the remaining sample frames into a new data block until all the sample frames of the first quantity are written into the data block, and generate multiple temporary moov files;

[0011] Obtain the recording normal end flag, generate a moov box by combining the media data area and the metadata parameters, and write the moov box into the MP4 file;

[0012] Set the file status flag in the MP4 file to the complete status, and update the media data length based on the number of bytes in the media data area.

[0013] In some embodiments, generating an MP4 file and a data index file based on audio-visual coding data includes:

[0014] Obtain the parameter information of the audio-visual coding data, where the parameter information includes: encoder type, resolution, frame rate, audio sampling rate, and number of channels;

[0015] Generate the file header and the metadata parameters according to the parameter information, where the metadata parameters include: number of samples in the data block, sample size, data block offset, sample sampling duration, and key frame index.

[0016] In some embodiments, the method for recording an MP4 file further includes:

[0017] Obtain the generation time of the temporary moov file;

[0018] Obtain the number of files of the temporary moov file;

[0019] When the number of files reaches a preset file number threshold, delete the temporary moov file with the earliest generation time.

[0020] In some embodiments, after updating the media data length based on the number of bytes in the media data area, it further includes:

[0021] Close the MP4 file;

[0022] Delete the temporary moov file.

[0023] In a second aspect, an embodiment of the present application provides a method for repairing an MP4 file, which is used to repair the MP4 file generated in any one of the methods for recording an MP4 file in the first aspect. Wherein, the file status flag in the MP4 file is in an incomplete status, and the method for repairing the MP4 file includes:

[0024] Obtain an MP4 file and obtain a temporary moov file, where the temporary moov file includes data blocks, and the data blocks include sample frames;

[0025] Mark a reference temporary file according to the number of sample frames in the temporary moov file, where the reference temporary file is the temporary moov file with the largest number of sample frames;

[0026] Obtain the reference offset of the reference temporary file and the actual offset of the MP4 file, where the reference offset is the end offset position of the last sample frame in the reference temporary file, and the actual offset is the offset position of the last byte in the MP4 file;

[0027] In the case where the reference offset is less than or equal to the actual offset, mark the reference byte corresponding to the reference offset in the MP4 file and delete the bytes after the reference byte in the MP4 file to generate a calibrated MP4 file;

[0028] Generate a new moov box according to the reference temporary file and add the new moov box to the end of the calibrated MP4 file to generate a complete MP4 file;

[0029] Set the file status flag of the complete MP4 file to the complete status and update the media data length of the complete MP4 file.

[0030] In some embodiments, the method for repairing an MP4 file further includes: in the case where the reference offset is greater than the actual offset, delete the last data block in the reference temporary file to update the reference offset, where the last data block is the last written data block in the reference temporary file.

[0031] In some embodiments, obtaining an MP4 file includes: in the case where the MP4 file contains a moov box, delete the moov box in the MP4 file.

[0032] In some embodiments, after obtaining the MP4 file, it further includes: query the file status flag in the MP4 file, and in the case where the file status flag is the complete status, exit the repair.

[0033] In some embodiments, after updating the media data length of the complete MP4 file, it further includes:

[0034] Close the complete MP4 file;

[0035] Delete the temporary moov file and the reference temporary file.

[0036] In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a memory, and a bus; the processor and the memory are communicatively connected through the bus;

[0037] The memory stores computer program instructions executable by the processor, and the processor is configured to implement the methods described in the first aspect and the second aspect.

[0038] As can be seen from the above technical solutions, the present application provides a method for recording and repairing an MP4 file, an electronic device. The method for recording an MP4 file can generate an MP4 file and a data index file based on audio-visual coding data, generate a first number of sample frames based on the audio-visual coding data, and sequentially write the sample frames into data blocks. When the memory of the data block reaches a preset memory threshold, add the data block to the end of the media data area; update the metadata parameters in the data index file, and generate a temporary moov file based on the media data area; then write the remaining sample frames into new data blocks until all the first number of sample frames are written into the data blocks, and generate multiple temporary moov files; then obtain a recording normal end flag, generate a moov box in combination with the media data area and the metadata parameters, and write the moov box into the MP4 file; finally, set the file status flag in the MP4 file to the complete status, and update the media data length based on the number of bytes in the media data area. Among them, the MP4 file includes a file header and a media data area, the file header includes a file status flag and a media data length, and the initial status of the file status flag is the incomplete status; the data index file is used to save the metadata parameters. The above method can generate a temporary moov file during the video recording process. When the MP4 file cannot be played normally due to abnormal recording end, use the temporary moov file to repair the MP4 file, improving the repair effect and repair efficiency of the MP4 file. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions of the present application, the accompanying drawings required for the embodiments will be briefly introduced below. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0040] Figure 1 It is a schematic diagram of the steps of the method for recording an MP4 file according to an embodiment of the present application;

[0041] Figure 2 It is a schematic diagram of the data structure example of the MP4 file according to an embodiment of the present application;

[0042] Figure 3 It is a schematic diagram of the process of recording data blocks according to an embodiment of the present application;

[0043] Figure 4 Schematic diagram of the steps of the MP4 file repair method according to the embodiment of the present application;

[0044] Figure 5 Schematic diagram of the process of generating a complete MP4 file according to the embodiment of the present application;

[0045] Figure 6 Schematic diagram of the structure of the electronic device according to the embodiment of the present application. Detailed implementation manners

[0046] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0047] It should be understood that the "plurality" mentioned herein refers to two or more. In the description of the embodiments of the present application, unless otherwise specified, " / " means "or", for example, A / B may mean A or B; the "and / or" herein is only a description of the association relationship of the associated objects, indicating that there can be three relationships, for example, A and / or B may mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in order to clearly describe the technical solutions in the embodiments of the present application, in the embodiments of the present application, terms such as "first" and "second" are used to distinguish the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the terms "first" and "second" do not limit the quantity and execution order, and the terms "first" and "second" do not necessarily mean different.

[0048] In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0049] Video recording is the main function of video recording devices such as cameras, action cameras, and dash cams. Video recording devices encapsulate videos into media files according to multimedia encapsulation formats. Among them, the MP4 format is a commonly used video encapsulation format. The MP4 format is a set of compression and encoding standards for audio and video information, developed by the "Moving Picture Experts Group" (MPEG) under the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC). The MP4 format is widely used to package video and audio data streams, posters, subtitles, and metadata, etc., and can be used and played across multiple different platforms.

[0050] The MP4 format can generate MP4 files from media files. The data in the MP4 file exists in the movie container. Among them, a movie container can be composed of multiple audio / video sequences (tracks). A track is a media sequence that changes over time. Each track has independent time and space information and can be played or processed independently.

[0051] A track contains multiple video frames or audio samples. Among them, a sample frame is the basic unit for storing media data. For a video track, a sample frame represents one frame of video; for an audio track, a sample frame represents a continuous segment of compressed audio. A chunk is a unit composed of multiple consecutive sample frames in a track. A chunk combines multiple sample frames together, and a chunk is one of the basic units for storing and transmitting media data.

[0052] Since video recording devices may encounter abnormal situations such as system freezing, power outage, battery depletion, or device damage during real-time recording, resulting in abnormal termination of the recording process, and further causing incomplete preservation of MP4 file information, making the MP4 file unable to be played and used normally due to lack of data information.

[0053] Using repair software to repair damaged MP4 files can restore some simple damage situations, but the repaired MP4 files will have problems such as out-of-sync sound and video, and video stuttering during playback, resulting in poor repair effect and low efficiency of MP4 files.

[0054] In order to improve the repair effect and efficiency of MP4 files, the first aspect of this application provides a method for recording MP4 files. Figure 1 It is a schematic diagram of the steps of the method for recording MP4 files in the embodiments of this application. The following is based on Figure 1 The method for recording MP4 files in this embodiment will be described in detail.

[0055] Step S110: Generate an MP4 file and a data index file based on the audio - video encoded data.

[0056] In some embodiments, the video recording device starts recording audio - video, generates audio - video encoded data using an audio - video encoder, and generates an MP4 file and a data index file based on the audio - video encoded data. Among them, the MP4 file includes a file header and a media data area. The file header includes key boxes at the beginning of the file, and these boxes contain important information such as file type, version, etc. The file header also includes a file status flag and the length of the media data. The file status flag includes a complete status and an incomplete status, and the initial status of the file status flag is the incomplete status. The media data length is used to represent the byte length of the media data in the MP4 file, and the initial value of the media data length is 0.

[0057] Exemplarily, Figure 2 is a data structure example diagram of the MP4 file in the embodiments of the present application. As Figure 2 shown, the MP4 file includes a file header (Header) and a media data area (Data). The file header includes multiple box files (Box), such as: a file type box (File Type Box, ftyp box) and a free space box (Free Space Box, free box). The ftyp box is used to describe the specifications, file type, and version information followed in the current MP4 file. The free box includes placeholders and a buffering mechanism for storing and accessing other key data. The free box also contains a complete field in the file status flag, and the complete field is used to represent whether the MP4 file is complete. For example, when the complete field is 1, it represents that the MP4 file is a complete file; when the complete field is 0, it represents that the MP4 file is an incomplete file. The initial value of the complete field is 0.

[0058] In some embodiments, a file header and metadata parameters are generated according to the parameter information of the audio - video encoded data. The parameter information of the audio - video encoded data includes: encoder type, resolution, frame rate, audio sampling rate, and number of channels. The data index file is used to record the position information of each key frame or data block in the media data and save the metadata parameters. The metadata parameters can be used to locate the data block at a specific time in the MP4 file, and the metadata parameters include: the number of samples in the data block, the sample size, the data block offset, the sample sampling duration, and the key frame index.

[0059] Step S120: Generate a first number of sample frames based on the audio - video encoded data and write the sample frames into data blocks in sequence.

[0060] In some embodiments, a decoder is used to parse audio-visual coding data to generate audio-visual frames, and the audio-visual frames are processed, including adjusting parameters such as frame rate, resolution, and audio sampling rate, so as to generate a first number of sample frames. Then, the memory of the data block is obtained, and when the memory of the data block is less than or equal to a preset memory threshold, the sample frames are written into the data block.

[0061] Step S130: When the memory of the data block reaches the preset memory threshold, add the data block to the end of the media data area.

[0062] In some embodiments, refer to Figure 3 , obtain the memory of the data block in real time. When the memory of the data block reaches the preset memory threshold, stop writing sample frames into the data block. And write the data stored in the data block at the end of the media data area to update the media data area.

[0063] Step S140: Update the metadata parameters in the data index file and generate a temporary moov file based on the media data area.

[0064] In some embodiments, when the data in the media data area is updated, it is necessary to synchronously update the metadata parameters in the data index file, including the number of samples in the data block, the sample size, the data block offset, the sample sampling duration, and the key frame index.

[0065] The data index file is used to represent the position information of the sample frames. According to the data index file, the MP4 file can be parsed, and then the playback and use of the MP4 file can be realized. Specifically, the number of samples in the data block is used to represent the number of samples contained in a data block, and the efficiency of data reading and processing can be optimized through the number of samples in the data block. The sample size is used to represent the byte size of each sample, and the storage space size occupied by each sample can be determined through the sample size, so as to read and parse the data of each sample.

[0066] The data block offset is used to represent the offset of the data block in the file, that is, the number of bytes from the beginning of the file to the start position of the data block. Through the data block offset, the data block can be quickly located, and then the sample frames of the data block can be efficiently read. The sample sampling duration is used to represent the time length of the sample frame. Through the sample sampling duration, the position of each sample frame on the playback timeline can be determined, thereby ensuring the correct playback of the media data. The key frame index is used to represent the position information of the key frame. Through the key frame index, the position of the key frame can be quickly located during the playback of the media data. An audio-visual box is generated by combining the media data region and the data index file, and a temporary moov file is generated based on the audio-visual box. The moov file is a specific MP4 file or a key component of the MP4 file, which contains the metadata required for media playback. The temporary moov file contains the media file structure, encoding method, and metadata parameters. Through the information in the temporary moov file, the position of the sample frame can be located, thereby realizing the playback of the MP4 file.

[0067] Step S150: Write the remaining sample frames into a new data block until all the sample frames of the first quantity are written into the data block, and generate multiple temporary moov files.

[0068] See Figure 3 , when the current data block is full of sample frames, continue to write the sample frames into the next data block until all the sample frames of the first quantity are written. After each data block is full, it will be added to the end of the media data region, and a temporary moov file will be generated based on the media data region. Therefore, when all the sample frames of the first quantity are written into the data block, multiple temporary moov files will be generated.

[0069] Exemplarily, the sample frames of the first quantity are sequentially stored in data block 1, data block 2, and data block 3, and temporary moov file 1, temporary moov file 2, and temporary moov file 3 are generated. Among them, the temporary moov file 3 includes the data contents in data block 1, data block 2, and data block 3.

[0070] In some embodiments, the file names of the temporary moov files are set according to the chronological order of generation of the temporary moov files. For example, the file names of the temporary moov files can be: moov_file_inc_1, moov_file_inc_2, moov_file_inc_3. Among them, the generation time of moov_file_inc_1 is earlier than that of moov_file_inc_2, and the generation time of moov_file_inc_2 is earlier than that of moov_file_inc_3.

[0071] In some embodiments, in order to save system memory and avoid insufficient memory caused by an excessive number of temporary moov files, it is necessary to delete temporary moov files according to their generation time. First, obtain the generation time of the temporary moov files, and then obtain the number of temporary moov files. When the number of files reaches the preset file number threshold, delete the temporary moov file with the earliest generation time.

[0072] Exemplarily, the preset file number threshold is 5. The temporary moov files in the current system are moov_file_inc_1, moov_file_inc_2, moov_file_inc_3, moov_file_inc_4, and moov_file_inc_5 respectively. That is, when the number of files reaches the preset file number threshold, delete moov_file_inc_1 to free up the system's memory space.

[0073] Step S160: Obtain the recording normal end flag, generate a moov box in combination with the media data area and metadata parameters, and write the moov box into the MP4 file.

[0074] In some embodiments, the recording normal end flag is used to indicate that the video recording device has normally ended recording. Obtain the recording normal end flag, generate a moov box in combination with the media data area and metadata parameters, and write the moov box into the MP4 file to generate a complete MP4 file. The moov box is used to store the metadata required for media playback in the MP4 file and contains the parameters required for decoding, playing, and editing the MP4 file. Exemplarily, the moov box contains the basic information of the MP4 file, such as the creation time, modification time, number of frames, etc.; the moov box also includes the metadata of the media track, for example, track ID, type, duration, and encoding information, etc.

[0075] Step S170: Set the file status flag in the MP4 file to the complete status and update the media data length based on the number of bytes in the media data area.

[0076] In some embodiments, the file status flag is used to indicate the integrity of the MP4 file. The initial status of the file status flag is the incomplete status. After the recording ends normally and a complete MP4 file is generated, set the file status flag in the MP4 file to the complete status and obtain the number of bytes in the media data area to update the media data length.

[0077] In some embodiments, after updating the media data length based on the number of bytes in the media data region, the MP4 file is closed. Since the MP4 file is a complete file at this time and there is no need to perform subsequent repair on it through a temporary moov file, the temporary moov file is deleted to reduce the memory consumption of the system.

[0078] As can be seen from the above technical solutions, the first aspect of the present application provides a method for recording an MP4 file. The method can generate an MP4 file and a data index file based on audio-visual coding data, generate a first number of sample frames based on the audio-visual coding data, and sequentially write the sample frames into data blocks. When the memory of the data block reaches a preset memory threshold, the data block is added to the end of the media data region; update the metadata parameters in the data index file, and generate a temporary moov file based on the media data region; then write the remaining sample frames into a new data block until all the first number of sample frames are written into the data blocks, and generate multiple temporary moov files; then obtain a normal recording end flag, generate a moov box by combining the media data region and the metadata parameters, and write the moov box into the MP4 file; finally, set the file status flag in the MP4 file to the complete status, and update the media data length based on the number of bytes in the media data region. Among them, the MP4 file includes a file header and a media data region, the file header includes a file status flag and a media data length, and the initial state of the file status flag is the incomplete state; the data index file is used to store the metadata parameters. The above method can generate a temporary moov file during the video recording process, providing a reference basis for the repair of MP4 files that cannot be played normally due to abnormal recording termination.

[0079] The second aspect of the present application provides a method for repairing an MP4 file. Figure 4 FIG. is a schematic diagram of the steps of the method for repairing an MP4 file according to an embodiment of the present application. The following will be based on Figure 4 The method for repairing an MP4 file in this embodiment will be described in detail.

[0080] Step S210, obtain an MP4 file and obtain a temporary moov file.

[0081] In some embodiments, the video recording device may encounter abnormal situations such as system freeze, power-off, power exhaustion, or device damage, resulting in abnormal termination of the recording process. At this time, the moov box in the MP4 file fails to be correctly generated, so the MP4 file cannot be played and used normally due to lack of data information. When the video recording device is powered on and file automatic repair is triggered, the temporary moov file is used to repair the MP4 file so that the MP4 file can be played and used normally.

[0082] When the file status flag in the MP4 file is in an incomplete state, it indicates that the MP4 file is a file to be repaired. Obtain a temporary moov file and repair the MP4 file according to the temporary moov file. In some embodiments, the temporary moov file includes data blocks, and the data blocks include sample frames.

[0083] In some embodiments, due to an abnormal end of the recording process, there is an abnormal moov box in the MP4 file, and the abnormal moov box will cause the MP4 file to fail to play. Therefore, when the MP4 file contains a moov box, delete the moov box in the MP4 file to delete the abnormal moov box. Then generate a new moov box according to the temporary moov file and repair the MP4 file according to the new moov box.

[0084] In some embodiments, after obtaining the MP4 file, query the file status flag in the MP4 file. If the file status flag of the MP4 file is in a complete state, it indicates that the MP4 file is an audio-visual file generated by a normal recording end, and the MP4 file can be played and used normally without repair. Therefore, when the file status flag is in a complete state, exit the repair.

[0085] Step S220: Mark the reference temporary file according to the number of sample frames in the temporary moov file.

[0086] In some embodiments, there are multiple temporary moov files stored in the system. The temporary moov files include different numbers of sample frames. Take the temporary moov file with the largest number of sample frames as the reference temporary file and repair the MP4 file according to the reference temporary file to improve the recovery effect of the MP4 file and retain more data information.

[0087] Step S230: Obtain the reference offset of the reference temporary file and the actual offset of the MP4 file.

[0088] In some embodiments, the reference offset is the end offset position of the last frame sample frame in the reference temporary file, and the actual offset is the offset position of the last byte in the MP4 file. Based on the reference offset and the actual offset, repair the missing data in the MP4 file.

[0089] Step S240: When the reference offset is less than or equal to the actual offset, mark the reference byte corresponding to the reference offset in the MP4 file and delete the bytes after the reference byte in the MP4 file to generate a calibrated MP4 file.

[0090] In some embodiments, when an unexpected interruption occurs during recording, the MP4 file lacks data information, while the sample frames in the reference temporary file are complete data information. Therefore, as Figure 5 shown, when the reference offset is less than or equal to the actual offset, the bytes in the MP4 file that exceed the reference offset are deleted to generate a calibrated MP4 file.

[0091] Exemplarily, the reference offset is 2300 and the actual offset is 2500. The byte corresponding to the offset of 2300 in the MP4 file is marked as the reference byte, and the bytes after the actual offset of 2300 in the MP4 file are deleted, thereby obtaining a calibrated MP4 file.

[0092] In some embodiments, referring again to Figure 5 , in the case where the reference offset is greater than the actual offset, the last data block in the reference temporary file is deleted to update the reference offset. After deleting the last data block in the reference temporary file, the reference offset of the reference temporary file decreases. If the updated reference offset is less than or equal to the actual offset, the reference byte corresponding to the reference offset in the MP4 file is marked, and the bytes after the reference byte in the MP4 file are deleted to generate a calibrated MP4 file. If the updated reference offset is still greater than the actual offset, the last data block in the current reference temporary file continues to be deleted to update the reference offset until the reference offset is less than or equal to the actual offset. Herein, the last data block is the last written data block in the reference temporary file.

[0093] Step S250: Generate a new moov box according to the reference temporary file, and add the new moov box to the end of the calibrated MP4 file to generate a complete MP4 file.

[0094] In some embodiments, the reference temporary file is encapsulated as a new moov box, and the new moov box is added to the end of the calibrated MP4 file to make the data of the MP4 file complete and generate a complete MP4 file.

[0095] Step S260: Set the file status flag of the complete MP4 file to the complete status, and update the media data length of the complete MP4 file.

[0096] In some embodiments, the initial file status flag of the MP4 file to be repaired is the incomplete status. The complete MP4 file generated after repair is an audio-visual file that can be played and used. Set the file status flag of the complete MP4 file to the complete status, and update the media data length of the complete MP4 file.

[0097] In some embodiments, after updating the media data length of the complete MP4 file, the complete MP4 file is closed, and the temporary moov file and the reference temporary file are deleted to reduce the memory consumption of the system.

[0098] As can be seen from the above technical solutions, the second aspect of the present application provides a method for repairing an MP4 file, which is used to repair the MP4 file generated in the first aspect. Among them, the status flag of the MP4 file is in an incomplete state. The method for repairing the MP4 file includes: obtaining the MP4 file and obtaining the temporary moov file, marking the reference temporary file according to the number of sample frames in the temporary moov file; then obtaining the reference offset of the reference temporary file and the actual offset of the MP4 file. When the reference offset is less than or equal to the actual offset, mark the reference byte corresponding to the reference offset in the MP4 file, and delete the bytes after the reference byte in the MP4 file to generate a calibrated MP4 file; then generate a new moov box according to the reference temporary file, and add the new moov box to the end of the calibrated MP4 file to generate a complete MP4 file; finally, set the file status flag of the complete MP4 file to the complete state and update the media data length of the complete MP4 file. Among them, the temporary moov file includes data blocks, and the data blocks include sample frames; the reference temporary file is the temporary moov file with the largest number of sample frames; the reference offset is the last offset position of the last sample frame in the reference temporary file, and the actual offset is the offset position of the last byte in the MP4 file. The above method can repair the media data of the MP4 file to be repaired according to the reference offset of the reference temporary file and the actual offset of the MP4 file to generate a complete MP4 file, thereby improving the repair effect and repair efficiency of the MP4 file.

[0099] The third aspect of the present application further provides an electronic device, including: a processor, a memory and a bus;

[0100] The processor and the memory are communicatively connected through the bus; the memory stores computer program instructions executable by the processor, and the processor is configured to implement the method described in any one of the first aspect and the second aspect.

[0101] For example, as Figure 6 shown, the electronic device includes a processor 610, at least one communication bus 620, a user interface 630, at least one external communication interface 640 and a memory 650. Among them, the communication bus 620 is configured to implement connection communication between these components. Among them, the user interface 630 may include a display screen, and the external communication interface 640 may include a standard wired interface and a wireless interface. Among them, a computer program is stored in the memory 650. Among them, the processor 610 is used to execute the computer program stored in the memory 650.

[0102] The descriptions of the above computer program products, computer-readable storage media, and electronic devices are similar to those of the above method embodiments and have beneficial effects similar to those of the method embodiments. For technical details not disclosed in the computer program products, computer-readable storage media, and electronic devices of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0103] The serial numbers or the order of introduction of the embodiments of this application are only for description and do not represent the superiority or inferiority of the embodiments.

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

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

[0106] In addition, the functional units in each embodiment of this application can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0107] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer, or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital versatile disc (DVD)), or a semiconductor medium (e.g., solid state disk (SSD)), etc. It should be noted that the computer-readable storage medium mentioned in the embodiments of the present application can be a non-volatile storage medium, in other words, a non-transitory storage medium.

[0108] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.), and signals involved in the embodiments of the present application are all authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions. For example, the scene data of the current frame in the three-dimensional virtual scene, the device information of the client, and the scene interaction information involved in the embodiments of the present application are all obtained under full authorization.

[0109] For the similar parts between the embodiments provided in the present application, reference can be made to each other. The specific embodiments provided above are only several examples under the general concept of the present application and do not constitute a limitation on the protection scope of the present application. For those skilled in the art, any other embodiments extended based on the solution of the present application without creative efforts belong to the protection scope of the present application.

Claims

1. A method for recording an MP4 file, characterized in that: include: Generate an MP4 file and a data index file based on the audio and video encoding data, the MP4 file includes a file header and a media data area, the file header includes a file status identifier and a media data length, and the initial state of the file status identifier is an incomplete state; the data index file is used to store metadata parameters; Generate a first number of sample frames based on the audio and video encoding data, and write the sample frames into a data block in sequence, and add the data block to the end of the media data area when the memory of the data block reaches a preset memory threshold; Updating metadata parameters in the data index file and generating a temporary moov file based on the media data area; Writing the remaining sample frames into the new data block until all the first number of sample frames are written into the data block, and generating multiple temporary moov files; Obtaining a normal recording end mark, generating a moov box in combination with the media data area and the metadata parameters, and writing the moov box into the MP4 file; The file status flag in the MP4 file is set to a complete status, and the media data length is updated based on the number of bytes in the media data area.

2. The method for recording an MP4 file according to claim 1, characterized in that: The method of generating an MP4 file and a data index file based on the audio and video encoding data includes: Obtain parameter information of audio and video encoding data, the parameter information including: encoder type, resolution, frame rate, audio sampling rate and number of channels; The file header and the metadata parameters are generated according to the parameter information, and the metadata parameters include: the number of samples in the data block, the sample size, the data block offset, the sample sampling duration and the key frame index.

3. The MP4 file recording method according to claim 1, characterized in that: Also includes: Get the generation time of the temporary moov file; Get the number of temporary moov files. When the number of files reaches a preset file number threshold, the temporary moov file with the earliest generation time is deleted.

4. The method for recording an MP4 file according to claim 1, characterized in that: After updating the media data length based on the number of bytes in the media data area, the method further includes: Close the MP4 file; Delete the temporary moov file.

5. A method for repairing an MP4 file, characterized in that: Used to repair an MP4 file generated by the method according to any one of claims 1 to 4, wherein the file status in the MP4 file is marked as an incomplete state, the method comprising: Obtain an MP4 file and a temporary moov file, wherein the temporary moov file includes a data block, and the data block includes a sample frame; According to the number of sample frames in the temporary moov file, mark the reference temporary file, where the reference temporary file is the temporary moov file with the largest number of sample frames; Obtain a reference offset of the reference temporary file and an actual offset of the MP4 file, wherein the reference offset is the last offset position of the last sample frame in the reference temporary file, and the actual offset is the offset position of the last byte in the MP4 file; In the case where the reference offset is less than or equal to the actual offset, marking the reference byte corresponding to the reference offset in the MP4 file, and deleting the byte after the reference byte in the MP4 file to generate a calibration MP4 file; Generate a new moov box according to the reference temporary file, and add the new moov box to the end of the marked MP4 file to generate a complete MP4 file; The file status flag of the complete MP4 file is set to a complete status, and the media data length of the complete MP4 file is updated.

6. The method for repairing an MP4 file according to claim 5, characterized in that: Also includes: In the case where the reference offset is greater than the actual offset, the end data block in the reference temporary file is deleted to update the reference offset, and the end data block is the data block last written in the reference temporary file.

7. The method for repairing an MP4 file according to claim 5, characterized in that: The obtaining of MP4 files comprises: In the case where the MP4 file contains a moov box, the moov box in the MP4 file is deleted.

8. The method for repairing an MP4 file according to claim 5, characterized in that: After obtaining the MP4 file, the method further includes: The file status identifier in the MP4 file is queried, and when the file status identifier is a complete state, the repair is exited.

9. The method for repairing an MP4 file according to claim 5, characterized in that: After the media data length of the complete MP4 file is updated, the method further includes: Close the complete MP4 file; The temporary moov file and the reference temporary file are deleted.

10. An electronic device, characterized in that: Includes processor, memory and bus; The processor and the memory are communicatively connected via the bus; The memory stores computer program instructions executable by the processor, and the processor is configured to implement the method of any one of claims 1-9.

Citation Information

Patent Citations

  • Method for repairing MP4 corrupted file

    CN110740391A

  • MP4 video restoration method and system based on moov

    CN115589480A

  • MP4 file recording power-off recovery method and device, equipment and storage medium

    CN116881042A

  • MP4 file processing method and device, electronic equipment and storage medium

    CN117539683A

  • Multimedia data processing method and device, equipment, storage medium and program product

    CN119071596A