Video file repairing method and device, terminal equipment and storage medium
By extracting the video stream number and audio stream number from the reference file, parsing and saving the video and audio data, the problem of incomplete video file structure caused by the power outage of the recording equipment is solved, and the repair and playback of the video file are realized.
Patent Information
- Application Number
- CN202410757167.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-24
AI Technical Summary
During the process of shooting or editing videos, due to uncontrollable factors such as power outages of the recording equipment, the video file structure is incomplete, difficult to repair, and cannot be played normally.
By obtaining the file to be repaired and the reference file, parsing the video stream number and audio stream number of the reference file, extracting the video data and audio data from the file to be repaired, and saving them as pure video and pure audio files based on the reference file parameter information, Finally merged into repair file.
It has realized the repair of damaged video files and generated a complete repaired file, which can be played normally by the player.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data repair technology, and in particular, relates to a video file repair method, device, terminal equipment and storage medium. Background Art
[0002] In the process of shooting or editing a video, if there is an uncontrollable factor such as a power failure of the recording device, the recorded video file does not stop normally, which may cause the structure of the video file to be incomplete and unable to be played normally by the player. In the related art, when a video file is damaged, it is often difficult to repair it because its structural features are destroyed or incomplete. Summary of the invention
[0003] The embodiments of the present application provide a method, apparatus, terminal device and storage medium for repairing a video file, which can solve the problem in the related art that damaged video files are difficult to repair.
[0004] In a first aspect, an embodiment of the present application provides a method for repairing a video file, comprising:
[0005] Acquire a file to be repaired and a reference file, wherein the file to be repaired and the reference file are acquired by the same photographing device;
[0006] Parsing the reference file to obtain reference file parameter information of the reference file, wherein the reference file parameter information includes a reference file video stream number and a reference file audio stream number;
[0007] Extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number;
[0008] According to the reference file parameter information, the video data is saved as a pure video file;
[0009] According to the reference file parameter information, the audio data is saved as a pure audio file;
[0010] The pure video file and the pure audio file are merged into a repaired file.
[0011] In a second aspect, an embodiment of the present application provides a video file repair device, comprising:
[0012] An acquisition module, used to acquire a file to be repaired and a reference file, wherein the file to be repaired and the reference file are acquired by the same photographing device;
[0013] A parsing module, used for parsing the reference file to obtain reference file parameter information of the reference file, wherein the reference file parameter information includes a reference file video stream number and a reference file audio stream number;
[0014] An extraction module, used for extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number;
[0015] A first saving module, used for saving the video data as a pure video file according to the reference file parameter information;
[0016] A second saving module, used for saving the audio data as a pure audio file according to the reference file parameter information;
[0017] A merging module is used to merge the pure video file and the pure audio file into a repair file.
[0018] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned video file repair method when executing the computer program.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned video file repair method are implemented.
[0020] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the above-mentioned video file repair method.
[0021] The beneficial effect of the embodiment of the present application compared with the prior art is as follows: the embodiment of the present application obtains the file to be repaired and the reference file, and parses the reference file to obtain the reference file parameter information of the reference file, and then extracts the video data and the audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number, and saves the video data as a pure video file according to the reference file parameter information, and saves the audio data as a pure audio file according to the reference file parameter information, and finally merges the pure video file and the pure audio file into a repair file. The embodiment of the present application realizes the repair of the damaged video file by parsing the reference file parameter information from the reference file, extracting the video data and the audio data from the file to be repaired according to the reference file parameter information, and then generating the repair file according to the reference file parameter information and the video data and the audio data. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0023] Figure 1 It is a schematic diagram of the implementation process of a method for repairing a video file provided in an embodiment of the present application;
[0024] Figure 2 It is a structural schematic diagram of a video file repair device provided in an embodiment of the present application;
[0025] Figure 3 It is a schematic diagram of the structure of the terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work are protected by the present application.
[0027] It should be noted that the terms "include", "comprises" and "have" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, terminal, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices. In the claims, specification and drawings of the present application, relational terms such as "first" and "second" are merely used to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such real-time relationship or order between these entities / operations / objects.
[0028] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0029] In the process of shooting or editing a video, if there is an uncontrollable factor such as a power failure of the recording device, the recorded video file does not stop normally, which may cause the structure of the video file to be incomplete and unable to be played normally by the player. In the related art, when a video file is damaged, it is often difficult to repair it because its structural features are destroyed or incomplete.
[0030] In view of this, the embodiment of the present application achieves the repair of the damaged video file by parsing reference file parameter information from the reference file, extracting video data and audio data from the file to be repaired based on the reference file parameter information, and then generating a repair file based on the reference file parameter information as well as the video data and audio data.
[0031] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.
[0032] Figure 1 The present invention provides a schematic diagram of the implementation process of a video file repair method provided in an embodiment of the present invention, which can be applied to a terminal device, which can be a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, etc.
[0033] Specifically, the above video file repair method may include the following steps S101 to S106.
[0034] Step S101, obtaining a file to be repaired and a reference file.
[0035] The file to be repaired and the reference file can be acquired by the same shooting device. Specifically, the file to be repaired refers to a damaged or incomplete video file. The reference file is a complete and undamaged video file, which is acquired by the same shooting device as the file to be repaired.
[0036] In the implementation manner of the present application, the terminal device can receive the file to be repaired and the reference file uploaded by the user. It is understandable that the terminal device can also obtain the file to be repaired and the reference file through the network or other means, which will not be repeated here.
[0037] Step S102: parsing the reference file to obtain reference file parameter information of the reference file.
[0038] The reference file parameter information is detailed information about the video and audio streams extracted from the reference file, which defines the organization of the video and audio data. The reference file parameter information may include a reference file video stream number and a reference file audio stream number. The video stream number is a unique number or code used to identify a video data stream. In a multimedia file, the video stream number can be used to distinguish different video tracks or data streams. The audio stream number can be used to identify an audio data stream. It should be understood that in a video file, the audio stream and the video stream are usually stored separately, and a specific audio track can be identified and processed by the audio stream number.
[0039] In an implementation manner of the present application, the terminal device may parse the reference file and extract the reference file parameter information from the reference file. Specifically, the terminal device may parse the audio stream object structure of the reference file and extract the reference file audio stream number therefrom. The terminal device may also parse the video stream object structure of the reference file and extract the reference file video stream number therefrom.
[0040] Step S103: extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number.
[0041] In an implementation manner of the present application, after obtaining the reference file video stream number and the reference file audio stream number, the terminal device can find and extract the corresponding video data from the file to be repaired based on the reference file video stream number, and can also find and extract the corresponding audio data from the file to be repaired based on the reference file audio stream number.
[0042] Step S104, saving the video data as a pure video file according to the reference file parameter information.
[0043] Among them, a pure video file is a file that contains only video data and no audio data. It is understandable that during the repair process, extracting and saving the video data in the file to be repaired as a pure video file is helpful to separate and process the video data separately.
[0044] In an implementation manner of the present application, after obtaining the video data, the terminal device may use video encoding technology to encode the extracted video data according to the format and parameters of the reference file based on the reference file parameter information and save it as an independent pure video file.
[0045] Step S105: saving the audio data as a pure audio file according to the reference file parameter information.
[0046] Wherein, pure audio file is the file which only contains audio data, does not contain video data.It is understandable that, in the repair process, extracting and saving the audio data in the file to be repaired as pure audio file is helpful to process the audio data separately.
[0047] In an implementation manner of the present application, the terminal device may utilize audio encoding technology to encode the extracted audio data according to the audio format and parameters of the reference file based on the reference file parameter information, and save it as an independent pure audio file.
[0048] Step S106, merging the pure video file and the pure audio file into a repaired file.
[0049] Among them, the repaired file is a complete video file after repair processing, which contains video and audio data extracted and reassembled from the file to be repaired.
[0050] In an implementation manner of the present application, the terminal device may use a multimedia editing tool or a programming method to merge the pure video file and the pure audio file into a complete video file in the correct timing and format.
[0051] The beneficial effect of the embodiment of the present application compared with the prior art is as follows: the embodiment of the present application obtains the file to be repaired and the reference file, and parses the reference file to obtain the reference file parameter information of the reference file, and then extracts the video data and the audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number, and saves the video data as a pure video file according to the reference file parameter information, and saves the audio data as a pure audio file according to the reference file parameter information, and finally merges the pure video file and the pure audio file into a repair file. The embodiment of the present application realizes the repair of the damaged video file by parsing the reference file parameter information from the reference file, extracting the video data and the audio data from the file to be repaired according to the reference file parameter information, and then generating the repair file according to the reference file parameter information and the video data and the audio data.
[0052] In some specific implementations of the present application, the above-mentioned extraction of video data and audio data from the file to be repaired based on the reference file video stream number and the reference file audio stream number may specifically include steps S401 to S403.
[0053] Step S401, parsing the file to be repaired, obtaining the data packet offset, data packet size and data packet stream number of the data packet in the file to be repaired.
[0054] Among them, the packet offset refers to the starting position of the packet in the file. Each data packet contains certain video or audio data, and the packet offset can be used to locate the specific position of these packets in the file. The packet size refers to the amount of data contained in each packet, usually in bytes. The packet stream number can be used to identify the packets of different data streams (such as video streams, audio streams, etc.) in the multimedia file. It can be understood that each data stream has a unique stream number, and the packet stream number is used to distinguish between packets in different data streams.
[0055] In an embodiment of the present application, the terminal device can use a special multimedia file parsing tool or algorithm to parse the file to be repaired, thereby identifying the starting position of each data packet in the file (i.e., the data packet offset), the size of the data packet, and the stream to which the data packet belongs (data packet stream number).
[0056] Specifically, the terminal device can continuously scan the 3-byte data frame start feature in the entire file. Once the 3 bytes are scanned, it means that the asf data packet structure in the wmv file (i.e., the file to be repaired) is found. Next, the asf data packet structure can be parsed according to the protocol structure to obtain the payLoad length carried in the data packet, which is recorded as payLoadLen. The payLoad structure is parsed from this position, where the first byte is the length type flag (the 0th bit is used to indicate the subsequent payLoad type, the 1st-2nd bits indicate the number of bytes occupied by the sequence in the payload, the 3rd-4th bits indicate the number of bytes occupied by the padding, and the 5th-6th bits indicate the number of bytes occupied by the packet length). For example, the first byte is 0, indicating that it is a single data packet payLoad, and 1 indicates that it contains multiple data packets of payLoad. The second byte represents the attribute mark, which can also be used to indicate the number of bytes occupied by each field of the relevant attributes in the subsequent data packets. If it is a single data packet payLoad, it can be parsed according to the single data packet payLoad in the wmv file protocol structure. According to the parsing result of the flag in 2, the bytes of each field in the payLoad header (sequence, padding, packet length, etc.) can be known. The offset obtained by skipping these bytes in the header is the offset of the actual media frame. Subtract these bytes in the header and the padding bytes at the end from payLoadLen to get the size of the media frame. The offset and size position are recorded as a data packet, and the data packet offset, data packet size, and data packet stream number are combined and stored in the data packet list datapacketList. Similarly, the multi-data packet structure can be parsed according to the multi-data packet protocol structure definition, and the obtained data packets can also be stored in datapacketList.
[0057] The implementation method of the present application can ensure that the required data packet is accurately extracted from the file to be repaired by parsing the offset, size and stream number of the data packet.
[0058] Step S402: extract all data packets from the file to be repaired according to the data packet offset and the data packet size.
[0059] In an implementation manner of the present application, after obtaining the data packet offset and the data packet size, the terminal device can use a file read operation to extract each data packet one by one from the file to be repaired according to the data packet offset and size information.
[0060] Step S403, according to the reference file video stream number, the reference file audio stream number and the data packet stream number, classify the data packet whose data packet stream number matches the reference file video stream number as video data, and classify the data packet whose data packet stream number matches the reference file audio stream number as audio data.
[0061] In an embodiment of the present application, after extracting all data packets, the terminal device can classify the data packets whose data packet stream numbers in the file to be repaired match the video stream number of the reference file as video data, and classify the data packets whose data packet stream numbers match the audio stream number of the reference file as audio data, based on the video stream number and audio stream number of the reference file.
[0062] Specifically, the terminal device can divide the data packet according to the stream number. If the stream number in the data packet is equal to the audio stream number of the reference file, the data packet is divided into audio data. If the stream number in the data packet is equal to the video stream number of the reference file, the data packet is divided into video data.
[0063] The implementation method of the present application classifies the data packet stream numbers according to the reference file video stream number and the reference file audio stream number, which can ensure that the extracted video data and audio data are accurate, providing a guarantee for subsequent video file repair.
[0064] In some specific embodiments of the present application, the above-mentioned reference file parameter information may also include the number of audio channels, audio sampling rate, audio bit rate, video width, video height, video bit rate, video encoding information, and video frame rate. The above-mentioned parsing of the reference file to obtain the reference file parameter information of the reference file may specifically include steps S501 to S505.
[0065] It is important to understand that the number of audio channels refers to the number of channels in the audio data, such as mono, stereo, etc. It determines the dimension and complexity of the audio signal. The audio sampling rate indicates the number of times the audio signal is sampled per second, usually in Hertz (Hz). The higher the sampling rate, the better the audio quality, but the file size will also increase accordingly. The audio bit rate indicates the number of bits used to encode the audio data per second. The higher the bit rate, the better the audio quality, but the file size will also increase accordingly. The video width and video height refer to the number of pixels in the horizontal and vertical directions of the video screen, usually in pixels (px). The video bit rate indicates the number of bits used to encode the video data per second. The higher the bit rate, the better the video quality, but the file size will also increase accordingly. Video encoding information can be the algorithms and parameters used to compress and encode video data. Different video encoding standards (such as H.264, H.265, etc.) and parameter settings will affect the size and quality of the video file. The video frame rate indicates the number of video frames displayed per second, usually in frames per second (fps). The higher the frame rate, the smoother the video playback.
[0066] Step S501, parse the file information object of the reference file to obtain the reference file duration and the number of data packets, and divide the number of data packets by the reference file duration to obtain the video frame rate.
[0067] The file information object refers to an object containing file metadata and attribute information. In a video file, the file information object may include information such as the duration and size of the file.
[0068] In an embodiment of the present application, the terminal device can read the file information object of the reference file, extract the total duration (in seconds) of the file and the total number of data packets contained therein, and then estimate the video frame rate (i.e., the number of frames per second) by calculating the ratio of the number of data packets to the file duration.
[0069] Specifically, the terminal device can first search the 16-byte header obcjetID of the file to verify the legality of the reference file. If the reference file is legal, the 16-byte file information object ID in the reference file can be searched to obtain the file information location and size, and then the file information object structure can be parsed to parse out the file duration, data packet and other information of the reference file. Among them, at the offset of 56 bytes of the file information object, reading 8 bytes can get the number of data packets dataPacketsCount, at the offset of 64 bytes, the play duration playDuration can be obtained, and at the offset of 80 bytes, the reserved duration preRoll can be obtained. The reference file duration can be calculated based on the play duration and the reserved duration. Dividing the number of data packets by the reference file duration can get the video frame rate.
[0070] Specifically, in some more specific implementations of the present application, the above-mentioned parsing of the file information object of the reference file to obtain the reference file duration may specifically include steps S601 to S603.
[0071] Step S601, parsing the file information object of the reference file to obtain the playback duration and the reserved duration.
[0072] In the implementation manner of the present application, the terminal device can parse the file information object of the reference file to obtain the playback duration and the reserved duration. The specific parsing process can refer to the above step S501, which will not be repeated here.
[0073] Step S602, unifying the units of the play duration and the reserved duration to obtain a unified play duration and a unified reserved duration.
[0074] In the implementation of the present application, it is necessary to understand that after obtaining the playback duration and the reserved duration, the units of the playback duration and the reserved duration are not unified. In fact, the unit of the parsed playback duration is 100 nanoseconds, while the unit of the parsed reserved duration is nanoseconds, so it is necessary to unify the units of the playback duration and the reserved duration. Specifically, the units of the playback duration and the reserved duration can be quasi-converted to seconds, that is, the parsed playback duration is divided by 10 million to obtain a unified playback duration in seconds. The parsed reserved duration is divided by one thousand to obtain a unified reserved duration in seconds.
[0075] Step S603, subtracting the unified playback duration from the unified reserved duration to obtain the reference file duration.
[0076] In an implementation manner of the present application, after the units of the playback duration and the reserved duration are unified, the terminal device can subtract the unified playback duration from the unified reserved duration to obtain the reference file duration.
[0077] Step S502, parsing the audio stream object structure of the reference file to obtain the number of audio channels, audio sampling rate, audio bit rate and the audio stream number of the reference file.
[0078] The audio stream object structure refers to the organization and structure of the audio data stream in the video file.
[0079] In an implementation manner of the present application, the terminal device can read the audio stream object structure of the reference file, and extract parameter information such as the number of audio channels, sampling rate, bit rate, and audio stream number.
[0080] Specifically, the terminal device can search for the 16-byte stream object ID in the reference file to obtain the position and size of the stream, parse the stream object structure to obtain the stream information, and determine whether the stream object is an audio stream object or a video stream object by the stream type ID in the stream information. If it is an audio stream, the data carried in the stream information is audio stream information. At this time, the data can be parsed according to the audio stream object structure to obtain parameters such as the number of audio channels, audio sampling rate, audio bit rate, and reference file audio stream number and audio-specific data content.
[0081] Step S503, parsing the video stream object structure of the reference file to obtain the video width, video height, video bit rate, video encoding information and the reference file video stream number.
[0082] The video stream object structure refers to the organization and structure of the video data stream in the video file.
[0083] In an implementation manner of the present application, the terminal device can read the video stream object structure of the reference file, and extract parameter information such as the width, height, bit rate, encoding format, and video stream number of the video.
[0084] Specifically, the terminal device searches for the 16-byte stream object ID in the file, obtains the position and size of the stream, parses the stream object structure to obtain the stream information, and determines whether the stream object is an audio stream object or a video stream object by the stream type ID in the stream information. If it is a video stream, the data carried in the stream information is video stream information. At this time, the data can be parsed according to the video stream object structure to obtain the video width, video height, video bit rate, video encoding information, reference file video stream number, and video specific data content.
[0085] In some more specific implementations of the present application, the above-mentioned saving of video data as a pure video file based on the reference file parameter information may specifically include steps S701 to S704.
[0086] Step S701, compile fixed header information of the video file.
[0087] The fixed header information of a video file refers to some fixed bytes at the beginning of a video file, which are used to identify the type and version of the file and provide some basic information required by the decoder.
[0088] In the implementation manner of the present application, the terminal device can write the corresponding file fixed header information according to the selected video file format (such as MP4, AVI, etc.). It can be understood that for a specific file format, the video file fixed header information is fixed.
[0089] Step S702, determining the number of video data packets corresponding to the video data.
[0090] The number of video data packets refers to the total number of data packets contained in the video stream. These data packets contain the encoded data of the video frames.
[0091] In an implementation manner of the present application, in the process of extracting video data from the file to be repaired, the data packet stream number will be matched with the reference file video stream number, and ultimately the number of data packets in all data packets that match the reference file video stream number is the number of video data packets corresponding to the video data.
[0092] Step S703, compile video file media header information according to the number of video data packets, video width, video height, video bit rate and video encoding information.
[0093] The media header information of the video file contains detailed information about the video data itself, such as the width, height, bit rate, encoding information, etc.
[0094] In the implementation mode of the present application, after obtaining the number of video data packets, video width, video height, video bit rate and video encoding information, the terminal device can write the video file media header information according to the number of video data packets and other given parameter information (video width, height, bit rate, encoding information, etc.). This information will be included in the header of the video file for the decoder to read and use.
[0095] Step S704, generating a pure video file according to the video file fixed header information, the video file media header information and the video data.
[0096] In an implementation manner of the present application, the terminal device may organize the video file fixed header information, the video file media header information, and the actual video data according to a specific file structure to generate a complete pure video file.
[0097] Specifically, in some more specific implementations of the present application, the above-mentioned saving of audio data as a pure audio file based on the reference file parameter information may specifically include steps S801 to S804.
[0098] Step S801, writing audio file header information.
[0099] Step S802, compose audio information according to the number of audio channels, audio sampling rate and audio bit rate.
[0100] Step S803: Generate a pure audio file according to the audio file header information, audio information and audio data.
[0101] In the implementation mode of the present application, the terminal device can write the file header information according to the format and characteristics of the audio data. And according to the specific parameters of the audio, such as the number of audio channels, the audio sampling rate and the audio bit rate, write the audio information, etc., and write the corresponding description information before the audio data. Finally, the audio file header information, the audio information and the audio data are combined in the corresponding format and order to generate a complete pure audio file.
[0102] In some specific implementations of the present application, the above-mentioned pure video file is a pure video avi file, the pure audio file is a pure audio wav file, and the repair file is a wmv file. The above-mentioned merging of the pure video file and the pure audio file into a repair file may specifically include steps S901 to S904.
[0103] Step S901, determining the number of video data frames corresponding to the video data.
[0104] Step S902, calculating the video duration according to the video frame rate and the number of video data frames.
[0105] Step S903, merging the pure video avi file and the pure audio wav file into a mixed avi file according to the video duration.
[0106] Step S904, converting the mixed avi file into a repaired file.
[0107] In the embodiment of the present application, in the process of extracting video data from the file to be repaired, the data packet stream number is matched with the reference file video stream number, and the number of data packets that match the reference file video stream number in all the final data packets is the number of video data packets corresponding to the video data, and the video data packet number video data is the number of video data frames. The terminal device can divide the number of video data frames by the video frame rate to obtain the total duration of the video. Then video editing software or programming method can be used to synchronize and merge pure video files and pure audio files according to the time axis to generate a mixed avi file. Finally, a video conversion tool or programming method is used to convert the mixed avi file into the required repair file format (wmv).
[0108] The implementation method of the present application first merges the pure video avi file and the pure audio wav file into a mixed avi file according to the video length, which can shorten the merging time, and then converts the mixed avi file into a repair file in wmv format, thereby ensuring that the final generated video file meets the user's needs or the compatibility of the player.
[0109] Figure 2 A schematic diagram of the structure of a video file repair device provided in an embodiment of the present application is shown. The video file repair device 2 may be configured on a terminal device. Specifically, the video file repair device 2 may include:
[0110] An acquisition module 201 is used to acquire a file to be repaired and a reference file, wherein the file to be repaired and the reference file are acquired by the same photographing device;
[0111] A parsing module 202, configured to parse the reference file to obtain reference file parameter information of the reference file, wherein the reference file parameter information includes a reference file video stream number and a reference file audio stream number;
[0112] An extraction module 203, configured to extract video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number;
[0113] A first saving module 204, configured to save the video data as a pure video file according to the reference file parameter information;
[0114] A second saving module 205 is used to save the audio data as a pure audio file according to the reference file parameter information;
[0115] The merging module 206 is used to merge the pure video file and the pure audio file into a repaired file.
[0116] The beneficial effect of the embodiment of the present application compared with the prior art is as follows: the embodiment of the present application obtains the file to be repaired and the reference file, and parses the reference file to obtain the reference file parameter information of the reference file, and then extracts the video data and the audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number, and saves the video data as a pure video file according to the reference file parameter information, and saves the audio data as a pure audio file according to the reference file parameter information, and finally merges the pure video file and the pure audio file into a repair file. The embodiment of the present application realizes the repair of the damaged video file by parsing the reference file parameter information from the reference file, extracting the video data and the audio data from the file to be repaired according to the reference file parameter information, and then generating the repair file according to the reference file parameter information and the video data and the audio data.
[0117] In some embodiments of the present application, the above-mentioned extraction module 203 can also be used to: parse the file to be repaired to obtain the data packet offset, data packet size and data packet stream number of the data packet in the file to be repaired; extract all the data packets from the file to be repaired according to the data packet offset and the data packet size; according to the reference file video stream number, the reference file audio stream number and the data packet stream number, divide the data packet whose data packet stream number matches the reference file video stream number into the video data, and divide the data packet whose data packet stream number matches the reference file audio stream number into the audio data.
[0118] In some embodiments of the present application, the reference file parameter information also includes the number of audio channels, audio sampling rate, audio bit rate, video width, video height, video bit rate, video encoding information, and video frame rate. The above-mentioned parsing module 202 can also be used to: parse the file information object of the reference file to obtain the reference file duration and the number of data packets, and divide the number of data packets by the reference file duration to obtain the video frame rate; parse the audio stream object structure of the reference file to obtain the number of audio channels, the audio sampling rate, the audio bit rate, and the audio stream number of the reference file; parse the video stream object structure of the reference file to obtain the video width, the video height, the video bit rate, the video encoding information, and the video stream number of the reference file.
[0119] In some embodiments of the present application, the above-mentioned first saving module 204 can also be used to: write fixed header information of the video file; determine the number of video data packets corresponding to the video data; write video file media header information according to the number of video data packets, the video width, the video height, the video bit rate and the video encoding information; generate the pure video file according to the video file fixed header information, the video file media header information and the video data.
[0120] In some embodiments of the present application, the above-mentioned second saving module 205 can also be used to: write audio file header information; write audio information according to the number of audio channels, the audio sampling rate and the audio bit rate; generate the pure audio file according to the audio file header information, the audio information and the audio data.
[0121] In some embodiments of the present application, the pure video file is a pure video avi file, the pure audio file is a pure audio wav file, and the repair file is a wmv file. The above-mentioned merging module 206 can also be used to: determine the number of video data frames corresponding to the video data; calculate the video duration according to the video frame rate and the number of video data frames; merge the pure video avi file and the pure audio wav file into a mixed avi file according to the video duration; and convert the mixed avi file into the repair file.
[0122] In some embodiments of the present application, the above-mentioned parsing module 202 can also be used to: parse the file information object of the reference file to obtain the playback time and the reserved time; unify the units of the playback time and the reserved time to obtain the unified playback time and the unified reserved time; subtract the unified playback time from the unified reserved time to obtain the reference file time.
[0123] like Figure 3 FIG. 3 is a schematic diagram of a terminal device provided in an embodiment of the present application. The terminal device 3 may include: a processor 301, a memory 302, and a computer program 303 stored in the memory 302 and executable on the processor 301, such as a video file repair program. When the processor 301 executes the computer program 303, the steps in the above-mentioned video file repair method embodiments are implemented, such as Figure 1 Alternatively, when the processor 301 executes the computer program 303, the functions of each module / unit in the above-mentioned device embodiments are realized, for example Figure 2 The obtained module 201, the parsing module 202, the extraction module 203, the first saving module 204, the second saving module 205, and the merging module 206 are shown.
[0124] The computer program may be divided into one or more modules / units, which are stored in the memory 302 and executed by the processor 301 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the terminal device.
[0125] The terminal device may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3 It is only an example of a terminal device and does not constitute a limitation of the terminal device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access equipment, buses, etc.
[0126] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0127] The memory 302 may be an internal storage unit of the terminal device, such as a hard disk or memory of the terminal device. The memory 302 may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device. Further, the memory 302 may also include both an internal storage unit of the terminal device and an external storage device. The memory 302 is used to store the computer program and other programs and data required by the terminal device. The memory 302 may also be used to temporarily store data that has been output or is to be output.
[0128] It should be noted that, for the convenience and brevity of description, the structure of the above-mentioned terminal device can also refer to the specific description of the structure in the method embodiment, which will not be repeated here.
[0129] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0130] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned video file repair method can be implemented.
[0131] An embodiment of the present application provides a computer program product. When the computer program product is run on a mobile terminal, the steps in the above-mentioned video file repair method can be implemented when the mobile terminal executes the computer program product.
[0132] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0133] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0134] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0135] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0136] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0137] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0138] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for repairing a video file, characterized in that: include: Acquire a file to be repaired and a reference file, wherein the file to be repaired and the reference file are acquired by the same photographing device; Parsing the reference file to obtain reference file parameter information of the reference file, wherein the reference file parameter information includes a reference file video stream number and a reference file audio stream number; Extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number; According to the reference file parameter information, the video data is saved as a pure video file; According to the reference file parameter information, the audio data is saved as a pure audio file; The pure video file and the pure audio file are merged into a repaired file.
2. The video file repair method according to claim 1, characterized in that: The extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number comprises: Parsing the file to be repaired to obtain a data packet offset, a data packet size, and a data packet stream number of a data packet in the file to be repaired; Extracting all the data packets from the file to be repaired according to the data packet offset and the data packet size; According to the reference file video stream number, the reference file audio stream number and the data packet stream number, the data packets whose data packet stream number matches the reference file video stream number are divided into the video data, and the data packets whose data packet stream number matches the reference file audio stream number are divided into the audio data.
3. The video file repair method according to claim 1, characterized in that: The reference file parameter information also includes the number of audio channels, audio sampling rate, audio bit rate, video width, video height, video bit rate, video encoding information, and video frame rate. The parsing of the reference file to obtain the reference file parameter information of the reference file includes: Parsing the file information object of the reference file to obtain the reference file duration and the number of data packets, and dividing the number of data packets by the reference file duration to obtain the video frame rate; Parsing the audio stream object structure of the reference file to obtain the number of audio channels, the audio sampling rate, the audio bit rate and the audio stream number of the reference file; The video stream object structure of the reference file is parsed to obtain the video width, the video height, the video bit rate, the video encoding information and the reference file video stream number.
4. The video file repair method according to claim 3, characterized in that: The step of saving the video data as a pure video file according to the reference file parameter information includes: Write fixed header information of video file; Determining the number of video data packets corresponding to the video data; Compile video file media header information according to the number of video data packets, the video width, the video height, the video bit rate and the video encoding information; The pure video file is generated according to the fixed header information of the video file, the media header information of the video file and the video data.
5. The video file repair method according to claim 3, characterized in that: The step of saving the audio data as a pure audio file according to the reference file parameter information includes: Write audio file header information; Writing audio information according to the number of audio channels, the audio sampling rate, and the audio bit rate; The pure audio file is generated according to the audio file header information, the audio information and the audio data.
6. The video file repair method according to claim 3, characterized in that: The pure video file is a pure video avi file, the pure audio file is a pure audio wav file, the repaired file is a wmv file, and merging the pure video file and the pure audio file into a repaired file includes: Determine the number of video data frames corresponding to the video data; Calculate the video duration according to the video frame rate and the number of video data frames; According to the video duration, the pure video avi file and the pure audio wav file are merged into a mixed avi file; Convert the mixed avi file into the repaired file.
7. The video file repair method according to claim 3, characterized in that: The step of parsing the file information object of the reference file to obtain the duration of the reference file includes: Parsing the file information object of the reference file to obtain the playback duration and the reserved duration; Unifying the units of the playback duration and the reserved duration to obtain a unified playback duration and a unified reserved duration; The unified playback duration is subtracted from the unified reserved duration to obtain the reference file duration.
8. A video file repair device, characterized in that: include: An acquisition module, used to acquire a file to be repaired and a reference file, wherein the file to be repaired and the reference file are acquired by the same photographing device; A parsing module, used for parsing the reference file to obtain reference file parameter information of the reference file, wherein the reference file parameter information includes a reference file video stream number and a reference file audio stream number; An extraction module, used for extracting video data and audio data from the file to be repaired according to the reference file video stream number and the reference file audio stream number; A first saving module, used for saving the video data as a pure video file according to the reference file parameter information; A second saving module, used for saving the audio data as a pure audio file according to the reference file parameter information; A merging module is used to merge the pure video file and the pure audio file into a repair file.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the video file repair method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the video file repair method according to any one of claims 1 to 7 are implemented.
