CN108093299B - Method for repairing damaged MP4 file and storage medium - Google Patents

Method for repairing damaged MP4 file and storage medium Download PDF

Info

Publication number
CN108093299B
CN108093299B CN201711404796.7A CN201711404796A CN108093299B CN 108093299 B CN108093299 B CN 108093299B CN 201711404796 A CN201711404796 A CN 201711404796A CN 108093299 B CN108093299 B CN 108093299B
Authority
CN
China
Prior art keywords
video
frame
box
audio
frames
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711404796.7A
Other languages
Chinese (zh)
Other versions
CN108093299A (en
Inventor
唐淮灿
范玮
吴少华
沈长达
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xiamen Meiya Pico Information Co Ltd
Original Assignee
Xiamen Meiya Pico Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiamen Meiya Pico Information Co Ltd filed Critical Xiamen Meiya Pico Information Co Ltd
Priority to CN201711404796.7A priority Critical patent/CN108093299B/en
Publication of CN108093299A publication Critical patent/CN108093299A/en
Application granted granted Critical
Publication of CN108093299B publication Critical patent/CN108093299B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/85Assembly of content; Generation of multimedia applications
    • H04N21/854Content authoring
    • H04N21/85406Content authoring involving a specific file format, e.g. MP4 format
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/439Processing of audio elementary streams
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/44Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream, rendering scenes according to MPEG-4 scene graphs
    • H04N21/4402Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream, rendering scenes according to MPEG-4 scene graphs involving reformatting operations of video signals for household redistribution, storage or real-time display
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/81Monomedia components thereof
    • H04N21/8106Monomedia components thereof involving special audio data, e.g. different tracks for different languages

Abstract

The invention discloses a method for repairing a damaged MP4 file and a storage medium, wherein the method comprises the following steps: acquiring a reference video; acquiring a sequence parameter set of the reference video; decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame; if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame; obtaining legal video frames in the damaged file to obtain a video frame set; acquiring frames between every two video frames in the damaged file to obtain an audio frame set; sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set; and obtaining a repair file according to the reference video and the video and audio frame set. The invention can improve the repairing effect and repairing support rate of the damaged MP4 file as a whole.

Description

Method for repairing damaged MP4 file and storage medium
Technical Field
The invention relates to the technical field of repair, in particular to a repair method and a storage medium for an MP4 damaged file.
Background
With the popularization of smart phones and recorder devices, video data is visible everywhere. Video data such as mobile phones, automobile recorders, law enforcement recorders and the like are manufactured in large quantities every day, and most of the video data are packaged in an MP4 format.
MP4 is called MPEG-4Part 14 entirely, is a common multimedia container format, and most video recording devices such as smart phones, unmanned aerial vehicles, automobile data recorders and the like use MP4 as a video packaging format. MP4 is defined in the "ISO/IEC 14496-14" standard document, which is part of MPEG-4. The MP4 is in a packaging format, i.e. a packaging format, and packages the existing data according to a certain format. The MP4 data package is in box units, and fig. 1 is a block diagram of MP4 package format.
Unfortunately, these precious video data sometimes suffer from various accidents, some are video recording interruption caused by equipment failure, recorded videos cannot be played, some are files deleted artificially, although there is data recovery software to recover the video data, because the MP4 video packaging format has high requirement for the integrity of the files, recovered data sometimes is not complete data, a small part of the data is already covered, which causes video damage and cannot be played, but the uncovered data may have critical information, and at this time, a video repair technology is needed to repair these incomplete videos, so that the damaged videos can be played again.
There are several pieces of software that are dedicated to repairing damaged MP4 video files, both domestically and internationally. The repair for a corrupted MP4 video file typically takes the following scenario:
providing a reference video (the reference video is required to be a video file which is recorded by the same device and can be normally played), extracting audio and video frames from a magnetic disk by referring to information provided by the video, and packaging the extracted audio and video frames into MP4 according to a standard video packaging format.
However, the existing scheme has the following defects:
1. and part of video and sound repair is not supported, and the audio repair support rate is low.
2. The recovery effect of partial video is not good, although the video can be played, the picture has the condition of screen-blooming.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: a method for repairing damaged MP4 files and a storage medium are provided, which can improve the repairing effect of damaged MP4 files and reduce the supporting rate of audio repairing.
In order to solve the technical problems, the invention adopts the technical scheme that: a method for repairing damaged files of MP4 comprises:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set;
and obtaining a repair file according to the reference video and the video and audio frame set.
The invention also relates to a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set;
and obtaining a repair file according to the reference video and the video and audio frame set.
The invention has the beneficial effects that: by adopting a defect frame identification algorithm, the integrity and the effective performance of the video frame can be judged, and only the legal video frame is obtained, so that the video repair effect is greatly improved, and the condition that the screen is lost after repair is avoided; by the video and audio interleaved differential data extraction method, frames between every two video frames are taken as audio frames to be obtained, sound data in the video can be effectively repaired, and the audio repair effect and repair support rate are greatly improved. The invention can improve the repairing effect and repairing support rate of the damaged MP4 file as a whole.
Drawings
FIG. 1 is a diagram illustrating the package format of MP 4;
FIG. 2 is a flowchart of a method for repairing a damaged MP4 file according to the present invention;
fig. 3 is a flowchart of a method according to a first embodiment of the invention.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: judging the integrity and effectiveness of the video frame by adopting a defect frame identification algorithm; and extracting the audio frame by adopting a video-audio interleaved differential data extraction method.
Referring to fig. 2, a method for repairing a damaged MP4 file includes:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set;
and obtaining a repair file according to the reference video and the video and audio frame set.
From the above description, the beneficial effects of the present invention are: the repairing effect and the repairing support rate of the damaged files of the MP4 can be improved integrally.
Further, the "acquiring the sequence parameter set of the reference video" specifically includes:
and decoding the network abstraction layer unit with the type value of 7 in the reference video to obtain a sequence parameter set.
From the above description, the NA L unit with NA L TYPE of 7 is the sequence parameter set.
Further, the "decoding the slice header in the damaged file according to the sequence parameter set to obtain the slice type and the frame number of the video frame" specifically includes:
taking the first byte in the damaged file as the current byte;
acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
decoding the byte data according to the sequence parameter set;
if the decoding fails, taking the next byte of the current byte as the current byte, and continuing to execute the step of obtaining the byte data with the length of eight bytes by taking the current byte as the starting point;
and if the decoding is successful, taking the byte data as a slice header, acquiring a video frame corresponding to the slice header according to the first four bytes of the slice header, and acquiring a slice type and a frame number of the video frame according to a decoding result.
Further, after the "if the value of the slice type is within the preset range and the frame numbers are consecutive, determining that the video frame corresponding to the slice header is a legal video frame", the method further includes:
and taking the next byte of the current byte as the current byte, and continuing to execute the step of acquiring the byte data with the length of eight bytes by taking the current byte as the starting point.
As can be seen from the above description, the Slice header SliceHeader including the frame header of the video frame is obtained in a traversal manner in the damaged file, so that the video frame can be obtained according to the frame header information of the video frame, and the Slice type and the frame number frame _ num of the video frame can be obtained by analyzing the Slice header for determining whether the video frame is legal.
Further, the "obtaining a repair file according to the reference video and the video and audio frame set" specifically includes:
creating a repair file;
if the repair file has an ftyp box, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file;
calculating the total length of the video and audio frames in the video and audio frame set, and obtaining the head information of the mdat box according to the total length;
writing the header information of the mdat box and the video and audio frames in the video and audio frame set into the mdat box of a repair file;
acquiring a time scale from an mvhd box in a reference video;
acquiring the duration of a single frame of a video frame from an stts box in a reference video;
obtaining the duration according to the single-frame duration of the video frame and the total frame number of the video frames in the video and audio frame set;
writing the time scale and the duration into an mvhd box of a repair file;
writing the length of each video frame in the video and audio frame set into an stsz box of a corresponding video frame in a repair file;
writing the length of each audio frame in the video and audio frame set into an stsz box of a corresponding audio frame in a repair file;
calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdat box;
grouping the video frames and the audio frames respectively according to the offset addresses;
writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file;
writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file;
writing the grouping information into an stsc box of the repair file;
writing the frame sequence number of the video frame with the type of the random readable frame in the video and audio frame set into the stss box of the repair file;
and writing the data in the tkhd box, stsd box and stts box of the reference video into the tkhdbox, stsd box and stts box of the repair file respectively.
As can be seen from the above description, a repair file is created based on the format information and the codec information of the video and audio frames of the reference video and the extracted video and audio frames from the damaged file.
The invention also proposes a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set;
and obtaining a repair file according to the reference video and the video and audio frame set.
Further, the "acquiring the sequence parameter set of the reference video" specifically includes:
and decoding the network abstraction layer unit with the type value of 7 in the reference video to obtain a sequence parameter set.
Further, the "decoding the slice header in the damaged file according to the sequence parameter set to obtain the slice type and the frame number of the video frame" specifically includes:
taking the first byte in the damaged file as the current byte;
acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
decoding the byte data according to the sequence parameter set;
if the decoding fails, taking the next byte of the current byte as the current byte, and continuing to execute the step of obtaining the byte data with the length of eight bytes by taking the current byte as the starting point;
and if the decoding is successful, taking the byte data as a slice header, acquiring a video frame corresponding to the slice header according to the first four bytes of the slice header, and acquiring a slice type and a frame number of the video frame according to a decoding result.
Further, after the "if the value of the slice type is within the preset range and the frame numbers are consecutive, determining that the video frame corresponding to the slice header is a legal video frame", the method further includes:
and taking the next byte of the current byte as the current byte, and continuing to execute the step of acquiring the byte data with the length of eight bytes by taking the current byte as the starting point.
Further, the "obtaining a repair file according to the reference video and the video and audio frame set" specifically includes:
creating a repair file;
if the repair file has an ftyp box, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file;
calculating the total length of the video and audio frames in the video and audio frame set, and obtaining the head information of the mdat box according to the total length;
writing the header information of the mdat box and the video and audio frames in the video and audio frame set into the mdat box of a repair file;
acquiring a time scale from an mvhd box in a reference video;
acquiring the duration of a single frame of a video frame from an stts box in a reference video;
obtaining the duration according to the single-frame duration of the video frame and the total frame number of the video frames in the video and audio frame set;
writing the time scale and the duration into an mvhd box of a repair file;
writing the length of each video frame in the video and audio frame set into an stsz box of a corresponding video frame in a repair file;
writing the length of each audio frame in the video and audio frame set into an stsz box of a corresponding audio frame in a repair file;
calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdat box;
grouping the video frames and the audio frames respectively according to the offset addresses;
writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file;
writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file;
writing the grouping information into an stsc box of the repair file;
writing the frame sequence number of the video frame with the type of the random readable frame in the video and audio frame set into the stss box of the repair file;
and writing the data in the tkhd box, stsd box and stts box of the reference video into the tkhdbox, stsd box and stts box of the repair file respectively.
Example one
Referring to fig. 3, a first embodiment of the present invention is: a method for repairing damaged MP4 files comprises the following steps:
s1: acquiring a reference video; namely, the video file which is recorded by the same equipment and can be played normally is obtained.
And S2, acquiring a sequence parameter set of the reference video, specifically, decoding a network abstraction layer unit with a TYPE value of 7 in the reference video to obtain the sequence parameter set, namely acquiring an NA L unit with an NA L TYPE of 7.
S3: taking the nth byte in the damaged file as the current byte; the initial value of n is 1.
S4: and judging whether the n +8 is larger than the total byte number of the damaged file, if so, indicating that the damaged file has traversed and the video frame has been extracted, executing the step S11, and if not, executing the step S5.
S5: acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
s6: decoding the byte data according to the sequence parameter set, that is, decoding the byte data according to the information provided by the sequence parameter set, and determining whether the decoding is successful, if so, executing step S8, otherwise, executing step S7.
S7: let n be n +1, go to step S3;
s8: and judging the byte data to be a Slice Header (Slice Header), acquiring a video frame corresponding to the Slice Header according to the first four bytes of the Slice Header, and acquiring a Slice type and a frame number (frame _ num) of the video frame according to a decoding result.
Since a frame of video image can be encoded into one or several slices (Slice), the above steps are to traverse and find a Slice containing a frame header of the video frame in the damaged file, and since four bytes of the frame header represent the length of the video frame, a corresponding video frame can be obtained according to the first four bytes of the Slice, and then Slice _ type and frame _ num of the video frame are obtained from the Slice.
S9: and judging whether the video frame is a legal video frame, if so, executing the step S10, otherwise, discarding the video frame, and then continuing searching for the damaged file, namely, executing the step S7. Specifically, if the value of the slice _ type is within 0 to 9 and the frame numbers are consecutive, it is determined that the video frame corresponding to the slice header is a legal video frame.
The consecutive frame numbers in this step mean that the frame numbers of the video frames in the same period are consecutive and complete until the current video frame.
Frame _ num of a video frame is periodically cycled, for example, a video frame with a frame rate of 30 has 30 video frames per second, and frame _ num is periodically cycled within 0-29, i.e., frame _ num represents the video frame as the frame _ num +1 video frame of the second (period).
Therefore, the consecutive frame numbers in this step specifically means that the frame numbers of the video frames which are in the same second as the video frame and have frame numbers smaller than that of the video frame are consecutive and complete and the frame numbers of the video frames are consecutive with that of the previous video frame, that is, if the frame numbers before the frame number are consecutive and complete in the current frame number period and the frame numbers are consecutive with that of the previous frame, the frame numbers are considered to be consecutive. If the frame number is not continuous, a fault is indicated.
For example, assuming that frame _ num of a frame acquired for a certain second is 0, 1, 2, 3, 5, 6, 7 … 28, 29 in this order, frames with frame _ num of 5-29 are all discarded. The data within the range of only 1 second is discarded, and the continuity of the next second frame is judged again.
S10: adding the legal video frame to a video frame set; the search for the damaged file then continues, i.e., step S7 is performed. Further, in step S7, the step S3 may be executed to let n be n + the total number of bytes of the legal video frame, that is, the first byte after the video frame is taken as the current byte, so as to increase the traversal speed and improve the repair efficiency.
S11: acquiring audio frames in the damaged file to obtain an audio frame set; according to the storage rule of video and audio frames, an audio frame is usually stored behind a key frame, and the audio frame and the video frame are stored in a staggered mode, so that frames between every two video frames in a damaged file are used as audio frames to be acquired, namely, after all the video frames are extracted, the residual data are audio data. And further, decoding the audio frame after the audio frame is acquired, adding the audio frame into the audio frame set if the decoding is successful, and discarding the audio frame set if the decoding is failed.
S12: sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set; for each element A in the set of video frames VS and the set of audio frames ASiAnd ViThe entries include an entry offset entry and an entry size entry, wherein the entry offset entry is an offset from the start address of the corrupted file.
S13: and obtaining a repair file according to the reference video and the video and audio frame set.
Specifically, a repair file is created first; for the ftyp box, if the ftyp box exists in the repair file, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file.
For the mdat box, storing video and audio frames; the header information of the mdat box comprises the length of mdat and four characters of 'mdatbox', therefore, the total length of the video and audio frames in the video and audio frame set is calculated to be the length of mdat, and then the four characters of 'mdat box' are added to obtain the header information of the mdat box; and then writing the header information of the mdat box and the video and audio frames in the video and audio frame set into the mdat box of the repair file.
For the mvhd box in the moov box, storing a time scale (timescale) and a duration (duration), wherein a value obtained by dividing the duration by the time scale is the total duration of the video, and the unit is second; the time scale can be extracted from the mvhd box in the reference video; for the duration, firstly, acquiring the duration of a single frame of a video frame from an stts box in a reference video, and then multiplying the total number of frames of the video frame in the video and audio frame set by the duration of the single frame to obtain the duration of the video frame, in this embodiment, the duration of the video frame is taken as the duration of a video file; and finally writing the time scale and the duration into an mvhd box of the repair file.
For a tkhd box in a moov box, video resolution information is mainly updated, and a screen is played due to an error in resolution setting. If the resolution of the reference video is directly used, resolution information is acquired from the tkhd box of the reference video and written into the tkhd box of the repair file. If the resolution is to be reset, it is preferably set to 1080P or 720P.
For the stsd box in the moov box, the box contains necessary decoding information, and if an error causes decoding failure, the decoding can be copied and written from the reference video.
For stts box in moov box, it is only necessary to copy and write from reference video for storing video and audio frame duration.
For the stsz box in the moov box, the length for storing the video and audio frames is used; in the moov box, there are two stsz boxes, one for storing the length of a video frame and the other for storing the length of an audio frame; therefore, writing the length of each video frame in the video and audio frame set into the stsz box of the corresponding video frame in the repair file; and writing the length of each audio frame in the video and audio frame set into the stsz box of the corresponding audio frame in the repair file.
For the stco box in the moov box, there are two stco boxes, one for storing the offset address of the video frame and the other for storing the offset address of the audio frame.
Calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdat box; the specific calculation process is as follows:
suppose HS ═ H1,H2,H3,....,HnDenotes a set of audio and video frames, i.e. HS AS ∪ US, where HnSorting according to the size of ENTRYOFFSET; let CS be { C ═ C1,C2,C3,....,CnDenotes the set of audio and video frames in the repair file, each element CiThe method comprises the steps of including entry offset ENTRYOFFSET and entry size ENTRYSIZE; hypothesis C1o……CnoRepresentation collectionENTRYOFFSET, C of elements in CS1s……CnsRepresentative of the elements in the set CS, i.e. subscript o denotes ENTRYOFFSET and subscript s denotes ENTRYSIZE; assuming that the size of the ftyp box is F, and the size of the head of the mdat box is M; combining the above assumptions, the calculation formula for obtaining the video/audio frame offset address is as follows:
Figure BDA0001520083730000111
further, the length of the video/audio frame is calculated as follows:
Cns=Hns
after the offset addresses of the video frames and the audio frames are obtained through calculation, grouping is carried out according to the offset addresses, namely the video frames with continuous offset addresses are divided into a group, and the audio frames with continuous offset addresses are divided into a group; and then writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file, and writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file.
For the stsc box in the moov box, writing the grouping information into the stsc box of the repair file;
for the stss box in the moov box, the TYPE (NA L TYPE) of the video frame in the video and audio frame set is obtained, and if the video frame is a randomly readable frame, the frame number of the video frame in the video frame set is written into the stssbox of the repair file.
In the embodiment, the integrity and the effective performance of the video frame can be judged by adopting a defect frame identification algorithm, and only a legal video frame is obtained, so that the video repairing effect is greatly improved, and the condition that a screen is lost after repairing is avoided; by the video and audio interleaved differential data extraction method, frames between every two video frames are taken as audio frames to be obtained, sound data in the video can be effectively repaired, and the audio repair effect and repair support rate are greatly improved.
Example two
The present embodiment is a computer-readable storage medium corresponding to the above-mentioned embodiments, on which a computer program is stored, which when executed by a processor, performs the steps of:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to the offset to obtain a video and audio frame set;
and obtaining a repair file according to the reference video and the video and audio frame set.
Further, the "acquiring the sequence parameter set of the reference video" specifically includes:
and decoding the network abstraction layer unit with the type value of 7 in the reference video to obtain a sequence parameter set.
Further, the "decoding the slice header in the damaged file according to the sequence parameter set to obtain the slice type and the frame number of the video frame" specifically includes:
taking the first byte in the damaged file as the current byte;
acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
decoding the byte data according to the sequence parameter set;
if the decoding fails, taking the next byte of the current byte as the current byte, and continuing to execute the step of obtaining the byte data with the length of eight bytes by taking the current byte as the starting point;
and if the decoding is successful, taking the byte data as a slice header, acquiring a video frame corresponding to the slice header according to the first four bytes of the slice header, and acquiring a slice type and a frame number of the video frame according to a decoding result.
Further, after the "if the value of the slice type is within the preset range and the frame numbers are consecutive, determining that the video frame corresponding to the slice header is a legal video frame", the method further includes:
and taking the next byte of the current byte as the current byte, and continuing to execute the step of acquiring the byte data with the length of eight bytes by taking the current byte as the starting point.
Further, the "obtaining a repair file according to the reference video and the video and audio frame set" specifically includes:
creating a repair file;
if the repair file has an ftyp box, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file;
calculating the total length of the video and audio frames in the video and audio frame set, and obtaining the head information of the mdat box according to the total length;
writing the header information of the mdat box and the video and audio frames in the video and audio frame set into the mdat box of a repair file;
acquiring a time scale from an mvhd box in a reference video;
acquiring the duration of a single frame of a video frame from an stts box in a reference video;
obtaining the duration according to the single-frame duration of the video frame and the total frame number of the video frames in the video and audio frame set;
writing the time scale and the duration into an mvhd box of a repair file;
writing the length of each video frame in the video and audio frame set into an stsz box of a corresponding video frame in a repair file;
writing the length of each audio frame in the video and audio frame set into an stsz box of a corresponding audio frame in a repair file;
calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdat box;
grouping the video frames and the audio frames respectively according to the offset addresses;
writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file;
writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file;
writing the grouping information into an stsc box of the repair file;
writing the frame sequence number of the video frame with the type of the random readable frame in the video and audio frame set into the stss box of the repair file;
and writing the data in the tkhd box, stsd box and stts box of the reference video into the tkhdbox, stsd box and stts box of the repair file respectively.
In summary, according to the method for repairing the damaged MP4 file and the storage medium provided by the present invention, the integrity and the effective performance of the video frame can be determined by using the defect frame identification algorithm, and only the legal video frame is obtained, so that the video repairing effect is greatly improved, and the condition of screen splash after repairing is avoided; by the video and audio interleaved differential data extraction method, frames between every two video frames are taken as audio frames to be obtained, sound data in the video can be effectively repaired, and the audio repair effect and repair support rate are greatly improved. The invention can improve the repairing effect and repairing support rate of the damaged MP4 file as a whole.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (8)

1. A method for repairing damaged MP4 files, wherein data object blocks in MP4 package format include ftyp, ftyp box, mdat box, stts box, mvhd box, stsz box, stco box, stsc box, stss box, tkhd box and stsdbox, and the method comprises the following steps:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to an offset to obtain a video and audio frame set, wherein the offset is an offset relative to a starting address of a damaged file;
obtaining a repair file according to the reference video and the video and audio frame set;
the "obtaining the repair file according to the reference video and the video and audio frame set" specifically includes:
creating a repair file;
if the repair file has an ftyp box, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file;
calculating the total length of the video and audio frames in the video and audio frame set, and obtaining the head information of the mdat box according to the total length;
writing the header information of the mdat box and the video and audio frames in the video and audio frame set into an mdatbox of a repair file;
acquiring a time scale from an mvhd box in a reference video;
acquiring the duration of a single frame of a video frame from an stts box in a reference video;
obtaining the duration according to the single-frame duration of the video frame and the total frame number of the video frames in the video and audio frame set;
writing the time scale and the duration into an mvhd box of a repair file;
writing the length of each video frame in the video and audio frame set into an stsz box of a corresponding video frame in a repair file;
writing the length of each audio frame in the video and audio frame set into an stsz box of a corresponding audio frame in a repair file;
calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdatbox;
grouping the video frames and the audio frames respectively according to the offset addresses;
writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file;
writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file;
writing the grouping information into an stsc box of the repair file;
writing the frame sequence number of the video frame with the type of the random readable frame in the video and audio frame set into the stss box of the repair file;
and writing the data in the tkhd box, stsd box and stts box of the reference video into the tkhd box, stsd box and stts box of the repair file respectively.
2. The method of claim 1, wherein the step of obtaining the sequence parameter set of the reference video comprises:
and decoding the network abstraction layer unit with the type value of 7 in the reference video to obtain a sequence parameter set.
3. The method of claim 1, wherein the "decoding slice headers in the corrupted file according to the sequence parameter set to obtain slice types and frame numbers of video frames" is specifically:
taking the first byte in the damaged file as the current byte;
acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
decoding the byte data according to the sequence parameter set;
if the decoding fails, taking the next byte of the current byte as the current byte, and continuing to execute the step of obtaining the byte data with the length of eight bytes by taking the current byte as the starting point;
and if the decoding is successful, taking the byte data as a slice header, acquiring a video frame corresponding to the slice header according to the first four bytes of the slice header, and acquiring a slice type and a frame number of the video frame according to a decoding result.
4. The method for repairing an MP4 damaged file as claimed in claim 3, wherein after said determining that the video frame corresponding to the slice header is a legal video frame if the value of the slice type is within a preset range and the frame numbers are consecutive, further comprising:
and taking the next byte of the current byte as the current byte, and continuing to execute the step of acquiring the byte data with the length of eight bytes by taking the current byte as the starting point.
5. A computer-readable storage medium on which a computer program is stored, a data object block in MP4 package format comprising ftyp, ftyp box, mdat box, stts box, mvhd box, stsz box, stco box, stsc box, stssbox, tkhd box, and stsd box, wherein the program when executed by a processor implements the steps of:
acquiring a reference video;
acquiring a sequence parameter set of the reference video;
decoding the strip header in the damaged file according to the sequence parameter set to obtain the strip type and the frame number of the video frame;
if the value of the stripe type is within a preset range and the frame numbers are continuous, judging that the video frame corresponding to the stripe head is a legal video frame;
obtaining legal video frames in the damaged file to obtain a video frame set;
acquiring frames between every two video frames in the damaged file to obtain an audio frame set;
sequencing the video frames in the video frame set and the audio frames in the audio frame set according to an offset to obtain a video and audio frame set, wherein the offset is an offset relative to a starting address of a damaged file;
obtaining a repair file according to the reference video and the video and audio frame set;
the "obtaining the repair file according to the reference video and the video and audio frame set" specifically includes:
creating a repair file;
if the repair file has an ftyp box, acquiring ftyp data from the reference video, and writing the ftyp data into the ftyp box of the repair file;
calculating the total length of the video and audio frames in the video and audio frame set, and obtaining the head information of the mdat box according to the total length;
writing the header information of the mdat box and the video and audio frames in the video and audio frame set into an mdatbox of a repair file;
acquiring a time scale from an mvhd box in a reference video;
acquiring the duration of a single frame of a video frame from an stts box in a reference video;
obtaining the duration according to the single-frame duration of the video frame and the total frame number of the video frames in the video and audio frame set;
writing the time scale and the duration into an mvhd box of a repair file;
writing the length of each video frame in the video and audio frame set into an stsz box of a corresponding video frame in a repair file;
writing the length of each audio frame in the video and audio frame set into an stsz box of a corresponding audio frame in a repair file;
calculating offset addresses of the video frames and the audio frames in the video and audio frame set in the repair file according to the offset of the video frames and the audio frames in the video and audio frame set, the size of an ftyp box and the size of a head of an mdatbox;
grouping the video frames and the audio frames respectively according to the offset addresses;
writing the offset address of each video frame group into the stco box of the corresponding video frame in the repair file;
writing the offset address of each audio frame group into the stco box of the corresponding audio frame in the repair file;
writing the grouping information into an stsc box of the repair file;
writing the frame sequence number of the video frame with the type of the random readable frame in the video and audio frame set into the stss box of the repair file;
and writing the data in the tkhd box, stsd box and stts box of the reference video into the tkhd box, stsd box and stts box of the repair file respectively.
6. The computer-readable storage medium according to claim 5, wherein said "acquiring the sequence parameter set of the reference video" is specifically:
and decoding the network abstraction layer unit with the type value of 7 in the reference video to obtain a sequence parameter set.
7. The computer-readable storage medium according to claim 5, wherein said "decoding the slice header in the corrupted file according to the sequence parameter set to obtain the slice type and the frame number of the video frame" specifically comprises:
taking the first byte in the damaged file as the current byte;
acquiring byte data with the length of eight bytes by taking a current byte as a starting point;
decoding the byte data according to the sequence parameter set;
if the decoding fails, taking the next byte of the current byte as the current byte, and continuing to execute the step of obtaining the byte data with the length of eight bytes by taking the current byte as the starting point;
and if the decoding is successful, taking the byte data as a slice header, acquiring a video frame corresponding to the slice header according to the first four bytes of the slice header, and acquiring a slice type and a frame number of the video frame according to a decoding result.
8. The computer-readable storage medium according to claim 5, wherein after determining that the video frame corresponding to the slice header is a legal video frame if the value of the slice type is within a preset range and the frame numbers are consecutive, the method further comprises:
and taking the next byte of the current byte as the current byte, and continuing to execute the step of acquiring the byte data with the length of eight bytes by taking the current byte as the starting point.
CN201711404796.7A 2017-12-22 2017-12-22 Method for repairing damaged MP4 file and storage medium Active CN108093299B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711404796.7A CN108093299B (en) 2017-12-22 2017-12-22 Method for repairing damaged MP4 file and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711404796.7A CN108093299B (en) 2017-12-22 2017-12-22 Method for repairing damaged MP4 file and storage medium

Publications (2)

Publication Number Publication Date
CN108093299A CN108093299A (en) 2018-05-29
CN108093299B true CN108093299B (en) 2020-08-04

Family

ID=62178602

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711404796.7A Active CN108093299B (en) 2017-12-22 2017-12-22 Method for repairing damaged MP4 file and storage medium

Country Status (1)

Country Link
CN (1) CN108093299B (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108961193B (en) * 2018-08-10 2021-04-02 厦门市美亚柏科信息股份有限公司 Image restoration method, device and storage medium
CN109960731B (en) * 2019-03-28 2022-11-18 腾讯音乐娱乐科技(深圳)有限公司 Data processing method, device and storage medium
CN110662084B (en) * 2019-10-15 2021-07-09 北京齐尔布莱特科技有限公司 MP4 file stream live broadcasting method, mobile terminal and storage medium
CN110740391B (en) * 2019-10-31 2021-10-26 四川效率源信息安全技术股份有限公司 Method for repairing MP4 damaged file
CN111063380A (en) * 2020-01-02 2020-04-24 南京美乐威电子科技有限公司 MP4 file generation method, processing device, equipment and storage medium
CN110781037B (en) * 2020-01-02 2020-04-17 成都易我科技开发有限责任公司 Method and system for recovering video file in storage medium and readable storage medium
CN113362233B (en) * 2020-03-03 2023-08-29 浙江宇视科技有限公司 Picture processing method, device, equipment, system and storage medium
CN112732180B (en) * 2020-12-29 2023-04-14 哈尔滨海能达科技有限公司 Information processing method, processing device, electronic equipment and storage medium
CN113382189A (en) * 2021-05-24 2021-09-10 深圳市爱为物联科技有限公司 Electronic equipment damaged file repairing method
CN113507625B (en) * 2021-06-22 2022-08-19 西安理工大学 Self-adaptive video restoration method
CN113660442B (en) * 2021-08-31 2024-03-19 广州盈可视电子科技有限公司 Video restoration method and device, electronic equipment and readable medium
CN114257840B (en) * 2021-11-26 2024-03-19 厦门市美亚柏科信息股份有限公司 Repairing method and system for Matroska format video
CN114007112B (en) * 2021-11-30 2023-06-02 四川效率源信息安全技术股份有限公司 Method for repairing mdat box data errors in MP4 video file
CN114446330B (en) * 2021-12-30 2024-04-16 厦门市美亚柏科信息股份有限公司 Method, device and storage medium for repairing MP4 file

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103327362A (en) * 2013-05-24 2013-09-25 武汉东信同邦信息技术有限公司 High reliability streaming medium memory system and method thereof
CN104598328A (en) * 2015-02-04 2015-05-06 南车株洲电力机车研究所有限公司 File system repair method, device and system
CN104768025A (en) * 2015-04-02 2015-07-08 无锡天脉聚源传媒科技有限公司 Method and device for repairing bad frames in video
CN105426262A (en) * 2014-09-11 2016-03-23 哈曼国际工业有限公司 Methods And Systems For Avb Networks
CN107273244A (en) * 2017-06-08 2017-10-20 深圳市普天宜通技术股份有限公司 The fault tolerant control method and system of a kind of media file storage

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2002212664A1 (en) * 2000-10-27 2002-05-06 Polycom Israel Ltd. Apparatus and method for improving the quality of video communication over a packet-based network
US20050089102A1 (en) * 2002-02-21 2005-04-28 Roberto Alvarez Arevalo Video processing

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103327362A (en) * 2013-05-24 2013-09-25 武汉东信同邦信息技术有限公司 High reliability streaming medium memory system and method thereof
CN105426262A (en) * 2014-09-11 2016-03-23 哈曼国际工业有限公司 Methods And Systems For Avb Networks
CN104598328A (en) * 2015-02-04 2015-05-06 南车株洲电力机车研究所有限公司 File system repair method, device and system
CN104768025A (en) * 2015-04-02 2015-07-08 无锡天脉聚源传媒科技有限公司 Method and device for repairing bad frames in video
CN107273244A (en) * 2017-06-08 2017-10-20 深圳市普天宜通技术股份有限公司 The fault tolerant control method and system of a kind of media file storage

Also Published As

Publication number Publication date
CN108093299A (en) 2018-05-29

Similar Documents

Publication Publication Date Title
CN108093299B (en) Method for repairing damaged MP4 file and storage medium
CN111063376B (en) Method, terminal equipment and storage medium for audio and video synchronization in MP4 repairing
CN108322808B (en) Video recording processing method and device, computer device and storage medium
CN105872484B (en) A kind of abnormal guard method of monitoring video
CN105847724B (en) A kind of video record power-off protection method and device
US9262419B2 (en) Syntax-aware manipulation of media files in a container format
CN104702914A (en) Monitored video data processing method and system
US20180316977A1 (en) Apparatus and method for delivering and receiving multimedia data in hybrid network
CN107566768A (en) Video recording method and device
DE60218535T2 (en) ERROR CORRECTION IN A DATA CURRENT
CN110896497A (en) Image processing method, video playing method and device
US20170054964A1 (en) Method and electronic device for playing subtitles of a 3d video, and storage medium
KR20200041650A (en) Method and apparatus for recovering damaged mp4 video file based on meta information of reference video
Park et al. Data fragment forensics for embedded DVR systems
CN113660442B (en) Video restoration method and device, electronic equipment and readable medium
CN109040827B (en) Video file playing method, storage medium and intelligent terminal
CN105653385B (en) A kind of vehicle-mounted kinescope method
Lee et al. Integrity verification scheme of video contents in surveillance cameras for digital forensic investigations
CN110851301A (en) Recovery method and system for MP4 file
CN114446330B (en) Method, device and storage medium for repairing MP4 file
CN107977551B (en) Method and device for protecting file and electronic equipment
KR102165087B1 (en) Video Data Control of Vehicle Black Box using for SAT
CN114143486A (en) Video stream synchronization method and device, computer equipment and storage medium
CN113555040B (en) Write method of moov container in multimedia file and computer readable storage medium
JP2012049956A (en) Semiconductor integrated circuit loadable to drive recorder and method of operating the same

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant