method for repairing MP4 damaged files

文档序号:1580011 发布日期:2020-01-31 浏览:21次 中文

阅读说明:本技术 一种修复mp4损坏文件的方法 (method for repairing MP4 damaged files ) 是由 许超明 梁效宁 韩勇 于 2019-10-31 设计创作,主要内容包括:本发明公开了一种修复MP4损坏文件的方法,其特征在于包括以下步骤:S100:获取任一MP4正常文件,解析所述MP4正常文件以获取数据流的编码方式、sample数据的封装模式及时间流的交错模式;S200:根据所述编码方式及所述交错模式,扫描所述MP4损坏文件的媒体数据区域并获取所述媒体数据区域中的sample大小及sample的偏移量并记录在音/视频序列容器中;S300:根据所述音/视频序列容器中sample大小及sample的偏移位置,修改所述MP4正常文件中moov的区块偏移表的偏移量,用以重新构建所述MP4正常文件的moov;S400:采用所述MP4损坏文件的媒体数据区域替换步骤S300中所重新构建的所述MP4正常文件的媒体数据区域,生成正常播放的MP4文件,完成所述MP4损坏文件的修复。(The invention discloses a method for repairing MP4 damaged files, which is characterized by comprising the following steps of S100, obtaining any MP4 normal files, analyzing the MP4 normal files to obtain a coding mode of a data stream, an encapsulation mode of sample data and an interleaving mode of a time stream, S200, scanning a media data area of the MP4 damaged files according to the coding mode and the interleaving mode, obtaining a sample size and an offset of the sample in the media data area, recording the sample size and the offset in an audio/video sequence container, S300, modifying an offset of a block offset table of moov in the MP4 normal files according to the sample size and the offset position of the sample in the audio/video sequence container, reconstructing the moov of the MP4 normal files, S400, replacing the media data area of the MP4 normal files reconstructed in the step S300 by the media data area of the MP4 damaged files, generating normally played MP4 files, and repairing the MP4 damaged files.)

1, method for repairing MP4 damaged file, which comprises the following steps:

s100, acquiring any MP4 normal file, and analyzing the MP4 normal file to acquire a coding mode of a data stream, a package mode of sample data and an interleaving mode of a time stream, wherein the MP4 normal file and the MP4 damaged file are generated by the same MP4 manufacturing device and/or manufacturing software and have the same coding mode and interleaving mode;

s200: according to the coding mode and the interleaving mode, scanning a media data area of the MP4 damaged file, acquiring the size of a sample and the offset of the sample in the media data area, and recording the size and the offset in an audio/video sequence container;

s300: modifying the offset of the block offset table of moov in the MP4 normal file according to the size of the sample and the offset position of the sample in the audio/video sequence container, so as to reconstruct the moov of the MP4 normal file;

s400: and replacing the media data area of the MP4 normal file reconstructed in the step S300 with the media data area of the MP4 damaged file to generate a MP4 file played normally, thereby completing the repair of the MP4 damaged file.

2. The method for repairing MP4 damaged files according to claim 1, wherein the step S100 includes the steps of:

s101: the method for acquiring the coding mode of the data stream comprises the following steps:

s1011: acquiring sample description information, wherein the sample description information comprises atom size, type, version, mark, item number and a sample description table, and the type is stsd;

s1012: reading the data format in the sample description table as the encoding mode, wherein the encoding mode comprises avc1, mp4a, mp4v, alac, samr, Twos, apcn, in24, sobt and sawb;

s102: obtaining an interleaved pattern of time streams, comprising the steps of:

s1021: acquiring a block offset table of each audio/video sequence in the MP4 normal file and acquiring an offset of each audio/video sequence, wherein the offset is a relative offset address relative to a starting address of a media data area;

s1022, merging the offsets of the audio/video sequences into the same set and arranging the offsets in ascending order;

s1023: searching the rule of the audio/video sequence to which each offset belongs in the set to determine the interleaving mode of each audio/video sequence;

s1024: removing audio/video sequences in the set which are repeatedly circulated so as to obtain an interleaving mode of the time stream;

s103: the method for acquiring the encapsulation mode of the sample data comprises the following steps:

s1031, obtaining a sample-block corresponding relation table in the MP4 normal file and reading the sequence number of the th block, the sample number of each block and the description identification number of the sample;

s1032: and acquiring a package mode of sample data according to the acquired interleaving mode of the audio/video sequence and the sample-block corresponding relation table in the MP4 normal file.

3. The method for repairing MP4 damaged files according to claim 1, wherein the step S200 comprises the steps of:

s201: reading data of a media data container of the MP4 damaged file, and searching for an identifier of the media data, wherein the identifier of the media data is a starting address of the media data;

s202: selecting an audio/video sequence to be matched according to the interleaving mode of the MP4 normal file;

s203: acquiring the number of samples to be matched according to the number of samples of each block of the MP4 normal file;

s204: scanning samples in the media data according to the coding mode of the audio/video sequence to match the read samples;

s205: judging whether the read sample is matched with the coding mode of the audio/video sequence, if so, executing step S207, otherwise, executing step S206;

s206, addressing the sample required to be read by , and executing the step S204;

s207: the byte length and offset of the current sample are recorded and the offset of the current sample is recorded in the audio/video sequence container.

4. The method of repairing MP4 damaged files as claimed in claim 3, wherein the method of obtaining byte length of sample for different audio/video sequence coding modes is as follows:

the encoding mode is avc 1: taking the initial address of the current sample as a first address, shifting 0x5 bytes backwards, reading the content of the bytes, and performing logical AND operation with 0x1f, wherein the obtained result represents the type of the sample and is less than 21 decimal numbers, and the content of the first 4 bytes of the current sample represents the byte length of the sample;

the encoding mode is mp4 a: with the start address of the current sample as the first address, shift backward by 0x5 bytes, 0x06 bytes and read the content of the bytes and the read content is 0xee, 0x1b, respectively, or,

taking the initial address of the current sample as a first address, shifting backwards by 0x5 bytes and 0x06 bytes, and respectively reading the content of the bytes, wherein the read content is 0x3e and 0x64 respectively, and the content of the first byte of the current sample is not zero;

obtaining the byte length of sample by using an untr _ decode _ audio4 function of ffpeg;

the encoding mode is mp4 v: taking the initial address of the current sample as the initial address, the content of the first two bytes is 0x1b3 or 0x1b6, and obtaining the byte length of the sample by adopting the avcodec _ decode _ video2 function of ffpeg;

the coding mode is alcc: the starting address of the current sample is used as the initial address, the address is shifted backward by 0x5 bytes and the integer t of the content of the consecutive 4 bytes is read, when the content of the first 4 bytes of the current sample is 0x00, the value of t is 0x00130000, or,

when the content of the first 4 bytes of the current sample is 0x1000, the value of t is 0x001a0000, and the byte length of the sample is obtained by adopting an untr _ decode _ audio4 function of ffpeg;

the coding mode is samr: the content of the first byte of the current sample is 0x3c, and the byte length of the sample is 32 bytes.

Technical Field

The invention belongs to the field of electronic data recovery and evidence collection, and relates to a repair method for audio/video files, in particular to a method for repairing MP4 damaged files.

Background

MP4 is a compression coding standard applied for audio and video information, and is established by the "Moving Picture Experts Group" (MPEG) under the international organization for standardization (ISO) and the International Electrotechnical Commission (IEC), with version being passed by 10 months in 1998 and version two being passed by 12 months in 1999, the main use of the MPEG-4 format is for streaming over the internet, compact discs, voice transmission (video telephony), and television broadcasts.

MPEG-4 contains most of the functions of MPEG-1 and MPEG-2 and other format advantages, and adds and expands the support of Virtual Reality Modeling Language (VRML), object oriented synthetic files (including sound, video and VRML objects), and Digital Rights Management (DRM) and other interactive functions, and of the features of MPEG-4, which are more advanced than MPEG-2, are no longer using macro blocks for image analysis, but using individual on image as change record, so that no square picture appears even though the image has fast change speed and insufficient code rate.

MPEG-4 is characterized as follows:

(1) different encoding algorithms can be used for different objects, thereby further improving compression efficiency;

(2) the objects are relatively independent, so that the reusability of multimedia data is improved;

(3) allowing a user to operate on a single object, providing unprecedented interactivity;

(4) code rates are allowed to be flexibly distributed among different objects, more bytes can be distributed to important objects, and less bytes can be distributed to secondary objects, so that a good effect can be obtained under a low code rate;

(5) natural audio and video objects and synthetic audio and video objects can be conveniently integrated.

Due to the advantages and features of MP4, MP4 has achieved -wide application and has a large number of users.

In the MP4 file format, all data is stored in containers called movies. movies may be composed of multiple audio/video sequences (tracks). Each audio/video sequence (track) is time-varying media sequences, e.g., a sequence of video frames.Each time unit in an audio/video sequence (track) is samples, which may be frames of video or audio.

The movie container holds media description metadata (metadata) that directs a player how to index and play media data, and is named moov.

However, MP4 may be damaged for various reasons, which may cause MP4 not to play normally, especially in the video surveillance file used in the field of public inspection, the damage of MP4 video surveillance file may cause great difficulty in monitoring and evidence collection.

Disclosure of Invention

Aiming at the defects of the prior art, the invention provides methods for repairing MP4 damaged files, which are characterized in that moov data index information is reconstructed by scanning samples in media data mdat, so that a player can normally play files, and the aim of repairing MP4 damaged files is fulfilled.

For ease of description, the present invention may include the following terms:

metadata media description metadata

mdat: media data area

chunk

track: audio/video sequence

interleave: interleaved pattern

sample-to-chunk table: sample-block correspondence table

chunk offset table: block offset table

sample description atom: sample description information

accurate Tracking with maximized Overlap

The invention comprises the following steps:

s100, acquiring any MP4 normal file, and analyzing the MP4 normal file to acquire a coding mode of a data stream, a package mode of sample data and an interleaving mode of a time stream, wherein the MP4 normal file and the MP4 damaged file are generated by the same MP4 manufacturing device and/or manufacturing software and have the same coding mode and interleaving mode;

s200: according to the coding mode and the interleaving mode, scanning a media data area of the MP4 damaged file, acquiring the size of a sample and the offset of the sample in the media data area, and recording the size and the offset in an audio/video sequence container;

s300: modifying the offset of the block offset table of moov in the MP4 normal file according to the size of the sample and the offset position of the sample in the audio/video sequence container, so as to reconstruct the moov of the MP4 normal file;

s400: replacing the media data area of the MP4 normal file reconstructed in the step S300 with the media data area of the MP4 damaged file, generating an MP4 file that can be played normally, and completing the repair of the MP4 damaged file.

Preferably, the step S100 includes the steps of:

s101: the method for acquiring the coding mode of the data stream comprises the following steps:

s1011: acquiring sample description information, wherein the sample description information comprises atom size, type, version, mark, item number and a sample description table, and the type is stsd;

s1012: reading the data format in the sample description table as the encoding mode, wherein the encoding mode comprises avc1, mp4a, mp4v, alac, samr, Twos, apcn, in24, sobt and sawb;

s102: obtaining an interleaved pattern of time streams, comprising the steps of:

s1021: acquiring a block offset table of each audio/video sequence in the MP4 normal file and acquiring an offset of each audio/video sequence, wherein the offset is a relative offset address relative to a starting address of a media data area;

s1022, merging the offsets of the audio/video sequences into the same set and arranging the offsets in ascending order;

s1023: searching the rule of the audio/video sequence to which each offset belongs in the set to determine the interleaving mode of each audio/video sequence;

s1024: removing audio/video sequences in the set which are repeatedly circulated so as to obtain an interleaving mode of the time stream;

s103: the method for acquiring the encapsulation mode of the sample data comprises the following steps:

s1031, obtaining a sample-block corresponding relation table in the MP4 normal file and reading the sequence number of the th block, the sample number of each block and the description identification number of the sample;

s1032: and acquiring a package mode of sample data according to the acquired interleaving mode of the audio/video sequence and the sample-block corresponding relation table in the MP4 normal file.

Preferably, the step S200 includes the steps of:

s201: reading data of a media data container of the MP4 damaged file, and searching for an identifier of the media data, wherein the identifier of the media data is a starting address of the media data;

s202: selecting an audio/video sequence to be matched according to the interleaving mode of the MP4 normal file;

s203: acquiring the number of samples to be matched according to the number of samples of each block of the MP4 normal file;

s204: scanning samples in the media data according to the coding mode of the audio/video sequence to match the read samples;

s205: judging whether the read sample is matched with the coding mode of the audio/video sequence, if so, executing step S207, otherwise, executing step S206;

s206, addressing the sample required to be read by , and executing the step S204;

s207: the byte length and offset of the current sample are recorded and the offset of the current sample is recorded in the audio/video sequence container.

Preferably, for different audio/video sequence coding modes, the method for obtaining the byte length of sample is as follows:

the encoding mode is avc 1: taking the initial address of the current sample as a first address, shifting 0x5 bytes backwards, reading the content of the bytes, and performing logical AND operation with 0x1f, wherein the obtained result represents the type of the sample and is less than 21 decimal numbers, and the content of the first 4 bytes of the current sample represents the byte length of the sample;

the encoding mode is mp4 a: with the start address of the current sample as the first address, shift backward by 0x5 bytes, 0x06 bytes and read the content of the bytes and the read content is 0xee, 0x1b, respectively, or,

taking the initial address of the current sample as a first address, shifting backwards by 0x5 bytes and 0x06 bytes, and respectively reading the content of the bytes, wherein the read content is 0x3e and 0x64 respectively, and the content of the first byte of the current sample is not zero;

obtaining the byte length of sample by using an untr _ decode _ audio4 function of ffpeg;

the encoding mode is mp4 v: taking the initial address of the current sample as the initial address, the content of the first two bytes is 0x1b3 or 0x1b6, and obtaining the byte length of the sample by adopting the avcodec _ decode _ video2 function of ffpeg;

the coding mode is alcc: the starting address of the current sample is used as the initial address, the address is shifted backward by 0x5 bytes and the integer t of the content of the consecutive 4 bytes is read, when the content of the first 4 bytes of the current sample is 0x00, the value of t is 0x00130000, or,

when the content of the first 4 bytes of the current sample is 0x1000, the value of t is 0x001a0000, and the byte length of the sample is obtained by adopting an untr _ decode _ audio4 function of ffpeg;

the coding mode is samr: the content of the first byte of the current sample is 0x3c, and the byte length of the sample is 32 bytes.

The invention has the following beneficial effects: the technical problem that damage caused by the fact that the MP4 file is lost moov cannot be repaired in the prior art is solved.

Drawings

FIG. 1 is a general flow diagram of a method provided by the present invention;

FIG. 2 is a flowchart illustrating the steps of obtaining sample size and offset according to embodiments of the present invention.

Detailed Description

In the MP4 file format, all data is stored in containers called movies. movies may be composed of multiple audio/video sequences (tracks). Each audio/video sequence (track) is time-varying media sequences, e.g., a sequence of video frames.Each time unit in an audio/video sequence (track) is samples, which may be frames of video or audio.

The movie container holds media description metadata (metadata) that directs a player how to index and play media data, and is named moov.

Each sample within an audio/video sequence (track) is associated by reference to sample descriptions.

The video frames need not be arranged in chronological order in the file, meaning that if such frames are actually present in the file, then file structures exist to describe the arrangement of the media and the corresponding time information.

All data in the MP4 file is packaged in boxes, previously called atom (accurate tracking by overlay maximum), i.e. accurate tracking with Overlap maximization, all media description metadata (metadata), including data defining the arrangement and time information of the media, is contained in such structural boxes the MP4 file format defines the format of these boxes, where metadata refers to the description of the media data (e.g. video frames).

The box defines how to find the arrangement of the media data in the sample table. This includes data references, sample size table (stsz for short), sample-to-chunk table (stsc for short), and chunk offset table (STCO for short), which can find the location and size of each sample in the audio/video sequence (track) in the file.

In addition, instead of combining samples from samples, the interleaving (interleave) combines several samples of a single audio/video sequence (track) into , and then the other samples are combined anew. units of consecutive samples of an audio/video sequence (track) are called chunks (chunk). each chunk (chunk) has offsets in the file, relative to the start address of the file, within which chunks are stored contiguously.

Thus, if chunks (chunk) contain two samples, the position of the second sample is the offset of the chunk (chunk) plus the size of th sample.

Additionally, if multiple audio/video sequences (tracks) of media data are contained in the same files, this media data may be interleaved generally to facilitate reading audio/video sequences (tracks) of media data while ensuring that each table is compact, interleaves at suitable time intervals (e.g., 1 second) rather than samples followed by samples

The overall layout of the MP4 file is as follows:

Figure BDA0002255185100000091

the method mainly comprises the steps of analyzing an MP4 normal file, obtaining a moov of the file, obtaining an interleaving mode and a coding mode of an audio/video sequence (track) from the moov, scanning a media data area (mdat) of an MP4 damaged file according to the interleaving mode, obtaining the size and the offset of each samples, rewriting a sample-block correspondence table (chunk offset table, short for STCO) in the moov according to the size and the offset of the obtained samples, and finally writing the rewritten moov and the media data area (mdat) into files to obtain MP4 files capable of being played normally.

The invention is further illustrated in the following description with reference to the figures and examples.

Fig. 1 shows a general flow chart of the method provided by the present invention.

As shown in fig. 1, the method of the present invention comprises the steps of:

s100, acquiring any MP4 normal file, and analyzing the MP4 normal file to acquire the coding mode of a data stream, the packaging mode of sample data and the interleaving mode of a time stream, wherein the MP4 normal file and the MP4 damaged file are generated by the same MP4 manufacturing device and/or manufacturing software and have the same coding mode and interleaving mode;

specifically, MP4 normal files from the same equipment as the MP4 damaged files are analyzed, the same MP4 making device refers to the same hardware equipment, such as the same camera and the same mobile phone, and the same MP4 making software refers to the same recording software, such as storm video, because the encoding mode of generating data streams of MP4 files, the packaging mode of sample data and the interleaving mode of time streams by the same MP4 making device and/or making software are the same, and the MP4 damaged files only have media data areas (mdat) and no moov information, the encoding mode of data streams cannot be obtained, and therefore the damaged files can only be obtained from the files generated by analyzing the same MP4 making device and/or making software.

Step S100 includes the steps of:

s101: the method for acquiring the coding mode of the data stream comprises the following steps:

s1011: acquiring sample description information, wherein the sample description information comprises atom size, type, version, mark, item number and a sample description table, and the type is stsd;

the encoding mode of the data stream is stored in a sample description atom (STSD), and the path position of the file is moov/track/stbl/STSD. The data structure of the sample description atom is as follows:

Figure BDA0002255185100000101

note that, at this time, the type of the sample description table is 'stsd', which includes sample description tables, and there may be to multiple sample description for each media data through the index table according to different encoding modes and the number of files storing the data.

S1012: reading a data format in the sample description table as an encoding mode, wherein the encoding mode comprises avc1, mp4a, mp4v, alac, samr, Twos, apcn, in24, sobt and sawb;

the following table is a sample description table in the examples of the present invention:

Figure BDA0002255185100000111

the encoding mode is obtained by reading the "data format" of 4 bytes in the table.

S102: obtaining an interleaved pattern of time streams, comprising the steps of:

s1021: obtaining a block offset table of each audio/video sequence in the normal file of the MP4 and obtaining an offset of each audio/video sequence, wherein the offset is a relative offset address relative to a starting address of a media data area;

s1022, merging the offsets of the audio/video sequences into the same set and arranging the offsets in ascending order;

s1023: searching the rule of the audio/video sequence to which each offset belongs in the set to determine the interleaving mode of each audio/video sequence;

s1024: removing the audio/video sequence in the set which is repeatedly circulated so as to obtain an interleaving mode of the time stream;

specifically, data of a plurality of audio/video sequences (tracks) in the mp4 file are distributed in an interleaving manner in time of the media data area (mdat), that is, what we call an interleaving (interleave) pattern, and the interleaving (interleave) pattern of the mp4 file generated by the same device is the same, and the interleaving (interleave) pattern of the audio/video sequences (tracks) can be determined according to the chunkoffset distribution in the chunkoffset table (STCO) of each audio/video sequence (track) of the mp4 normal file, for example, there are three tracks which are track0, track1 and track2 respectively, and the offset distributions in the blocks (chunks) are:

the offset of track0 in a chunk (chunk) is 1,10,20,30 bytes, and is denoted as set:

track0 chunk offsets('stco'):[1,10,20,30]

the offset of track1 in a chunk (chunk) is 2,4,12,15,21,24,32,33 bytes, which is denoted as set:

track1 chunk offsets('stco'):[2,4,12,15,21,24,32,33]

the offset of track2 in a chunk (chunk) is 6,7,18,19,25,28,38,39 bytes, denoted as set:

track2 chunk offsets('stco'):[6,7,18,19,25,28,38,39]

the respective offsets are merged into the same set and arranged in ascending order as 0,1,1,2,2,0,1,1,2,2,0,1,1,2,2,0, wherein 0 represents the position of the offset of track0 in the same set after being merged into the same set, similarly, 1 represents the position of the offset of track1 in the same set after being merged into the same set, and 2 represents the position of the offset of track2 in the same set after being merged into the same set, which is denoted as the following staggered set:

interleaveMask:[0,1,1,2,2,0,1,1,2,2,0,1,1,2,2,0]

finding out the rule in the appearance order and removing the repeated circulation part in the set, and obtaining the interleaving set as follows:

interleaveMask:[0,1,1,2,2,0]

that is, the interleave pattern is track0, track1, track1, track2, track2, and track0 occurring in this order and circulating in this order.

S103: the method for acquiring the encapsulation mode of the sample data comprises the following steps:

s1031, obtaining a sample-block corresponding relation table in the MP4 normal file and reading the sequence number of the th block, the sample number of each block and the description identification number of the sample;

s1032: and acquiring the encapsulation mode of the sample data according to the acquired interleaving mode of the audio/video sequence and the sample-block corresponding relation table in the MP4 normal file.

Specifically, the samples are organized in chunks (chunk) in the media data area (mdat), chunks (chunk) include or more samples, the byte length of the chunks (chunk) may be different, and the byte length of the chunks (chunk) may also be different.

The sample description information sample description atom (stsc) records the corresponding relationship between the sample and the block (chunk), and the path position of the file is moov/track/stbl/stsc:

the data structure of the sample description atom is as follows:

Figure BDA0002255185100000131

note that, at this time, the type of the sample description atom is 'stsc'.

The following table is a sample-to-chunk mapping table (sample-to-chunk) in another embodiment of the present invention:

field(s) Length (byte) Description of the invention
Size of 4 Number of bytes of atom
Type (B) 4 stsc
Version(s) 1 Versions of atom
Sign (sign) 3 Here is 0
Number of items 4 Number of sample-to-chunk
sample-to-chunk Structure of sample-to-chunk table
First chunk 4 The chunk sequence number used by this table
Samples per chunk 4 Number of samples in current trunk
Sample description ID 4 Sample desc associated with these samplesNumber of reptation

Reading the First chunk, Samples Perchunk and the Sample description ID in the Sample-block corresponding relation table of each Sample, and generating the following table:

First chunk Samples per chunk Sample description ID
1 4 1
4 3 1
5 4 1
8 3 1
9 4 1
12 3 1
13 4 1
16 3 1
17 4 1
20 3 1
21 4 1
277 4 1
280 3 1

the sequence number of the second First chunk minus the sequence number of the th First chunk is how many chunks including the same number of samples are in , so that has 280 chunks and how many samples each chunk includes and the description ID. corresponding to each chunk passes through the stsc table from the mp4 normal file, combines the interleaving pattern of the audio/video sequence (track), that is, the packing pattern of all samples in the media data area (mdat) is obtained, for example, in the present invention embodiment, it is assumed that there are two tracks, track0 is video, track1 is audio, the stsc of track0 has only entries (i.e., entries), all the chunks include only 1 sample with description ID 1, and the sequence ID is represented as:

track0'stsc'(one entry):[1,1,1]

wherein, the st 1 represents the number of chunk, the second 1 represents the number of samples contained in each chunk of the track0, and the third 1 represents the description ID of the samples;

the stsc of track1 has three entries (i.e., three entries), the th chunk with sequence number 1 in the th entry [1,2,1], the th chunk with sequence number 4,4-1 being 3 in the second entry [4,1,1], indicating that there are 3 chunks between the th entry and the second entry and each chunk contains 2 samples with description ID 1, the th chunk with sequence number 5,5-4 being 1 in the third entry [5,2,1], indicating that there are 1 chunks between the second entry and the third entry and each chunk contains 1 sample with description ID 1, no immediately after the third entry [5,2,1], indicating that each chunk after the 5 th chunk contains 2 samples with description ID 1, and that:

track1'stsc'(three entries):[1,2,1,4,1,1,5,2,1]

wherein each value in [1,2,1,4,1,1,5,2,1] has the same meaning as that of track 0. With this staggered correspondence relationship, we can directly obtain the sequence stream with sample number from the above-mentioned track sequence stream, and thus obtain the corresponding sample number (i.e. the encapsulation mode of sample data) through the track on the sequence stream, which is noted as:

Figure BDA0002255185100000151

wherein 0 in the interleave message represents track0,1 represents track1, in other words, the interleave pattern is track0 and track1 alternately, the obtaining method of the interleave pattern is obtained by step S102, the digit in the parentheses in the samppersChunkMask represents the number of samples, the second digit represents description ID

The above-mentioned track0 Chunk # and track1 Chunk # indicate the number of chunks in the track sequence

S200: according to the coding mode and the interleaving mode, scanning a media data area of the MP4 damaged file, acquiring the size of a sample and the offset of the sample in the media data area, and recording the sample size and the offset in an audio/video sequence container;

fig. 2 shows a specific flowchart of acquiring the size of the sample and the offset of the sample in embodiments of the present invention, as shown in fig. 2, step S200 includes the following steps:

s201: reading data of a media data container of the MP4 damaged file, and searching for an identifier of the media data, wherein the identifier of the media data is a starting address of the media data;

s202: selecting an audio/video sequence to be matched according to the interleaving mode of the MP4 normal file;

s203: acquiring the number of samples to be matched according to the number of samples of each block of the MP4 normal file;

s204: scanning samples in the media data according to the coding mode of the audio/video sequence to match the read samples;

s205: judging whether the read sample is matched with the coding mode of the audio/video sequence, if so, executing step S207, otherwise, executing step S206;

s206, addressing the sample required to be read by , and executing the step S204;

s207: the byte length and offset of the current sample are recorded and the offset of the current sample is recorded in the audio/video sequence container.

It should be noted that, for different audio/video sequence coding modes, the method for obtaining the byte length of sample is as follows:

the encoding mode is avc 1: taking the initial address of the current sample as a first address, shifting 0x5 bytes backwards, reading the content of the bytes, and performing logical AND operation with 0x1f, wherein the obtained result represents the type of the sample and is less than 21 decimal numbers, and the content of the first 4 bytes of the current sample represents the byte length of the sample;

the encoding mode is mp4 a: with the start address of the current sample as the first address, shift backward by 0x5 bytes, 0x06 bytes and read the content of the bytes and the read content is 0xee, 0x1b, respectively, or,

taking the initial address of the current sample as a first address, shifting backwards by 0x5 bytes and 0x06 bytes, and respectively reading the content of the bytes, wherein the read content is 0x3e and 0x64 respectively, and the content of the first byte of the current sample is not zero;

obtaining the byte length of sample by using an untr _ decode _ audio4 function of ffpeg;

the encoding mode is mp4 v: taking the initial address of the current sample as the initial address, the content of the first two bytes is 0x1b3 or 0x1b6, and obtaining the byte length of the sample by adopting the avcodec _ decode _ video2 function of ffpeg;

the coding mode is alcc: the starting address of the current sample is used as the initial address, the address is shifted backward by 0x5 bytes and the integer t of the content of the consecutive 4 bytes is read, when the content of the first 4 bytes of the current sample is 0x00, the value of t is 0x00130000, or,

when the content of the first 4 bytes of the current sample is 0x1000, the value of t is 0x001a0000, and the byte length of the sample is obtained by adopting an untr _ decode _ audio4 function of ffpeg;

the coding mode is samr: the content of the first byte of the current sample is 0x3c, and the byte length of the sample is 32 bytes.

S300: according to the size of the sample in the audio/video sequence container and the offset position of the sample, the offset of the block offset table of moov in the MP4 normal file is modified to reconstruct moov of the MP4 normal file.

S400: the media data area of the MP4 normal file reconstructed in step S300 is replaced with the media data area of the MP4 damaged file, an MP4 file that can be played normally is generated, and the repair of the MP4 damaged file is completed.

The method provided by the invention solves the technical problem that methods for repairing MP4 damaged files are not available in the prior art.

It is to be understood that the invention is not limited to the examples described above, but that modifications and variations are possible to those skilled in the art in light of the above teachings, and that all such modifications and variations are intended to be included within the scope of the invention as defined in the appended claims.

15页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种使用寿命长的便于维护的5G无线CPE设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类